diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
index 9ca8c59091..7fbde8e615 100644
--- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
+++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
@@ -188,14 +188,11 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
$value = (string) $subnode;
}
- if ($key === '*item') {
+ if ($key === 'item') {
if (isset($value['@key'])) {
$data[(string) $value['@key']] = $value['#'];
- } elseif (isset($data['*item'])) {
- $tmp = $data['*item'];
- unset($data['*item']);
- $data[] = $tmp;
- $data[] = $value;
+ } else {
+ $data['item'][] = $value;
}
} elseif (array_key_exists($key, $data)) {
if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) {
diff --git a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php
index 22bff31a62..49d7a86142 100644
--- a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php
+++ b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php
@@ -239,6 +239,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
''.
''.
' '.
+ ' '.
''.
'1'.
''."\n";
@@ -249,7 +250,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
$obj = new Dummy;
$obj->foo = 'foo';
$obj->bar = array('a', 'b');
- $obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', "Barry" => array('FooBar' => array("Baz"=>"Ed", "@id"=>1)));
+ $obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', 'item' => array(array('title' => 'title1'), array('title' => 'title2')), 'Barry' => array('FooBar' => array('Baz' => 'Ed', '@id' => 1)));
$obj->qux = "1";
return $obj;