diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 5aecdc845..c82cd65e7 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -136,7 +136,7 @@ class Xml { foreach ($namespaces as $namespace) { foreach ($xml->attributes($namespace, true) as $key => $value) { - $data[$key] = (string)$value; + $data['@' . $key] = (string)$value; } foreach ($xml->children($namespace, true) as $child) { diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index 3a460154e..1f2553cb5 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -256,6 +256,22 @@ class XmlTest extends CakeTestCase { $xml = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'fixtures' . DS . 'sample.xml'; $obj = Xml::build($xml); $expected = array( + 'tags' => array( + 'tag' => array( + array( + '@id' => '1', + 'name' => 'defect' + ), + array( + '@id' => '2', + 'name' => 'enhancement' + ) + ) + ) + ); + $this->assertEqual(Xml::toArray($obj), $expected); + + $array = array( 'tags' => array( 'tag' => array( array( @@ -269,11 +285,25 @@ class XmlTest extends CakeTestCase { ) ) ); - $this->assertEqual(Xml::toArray($obj), $expected); - $this->assertEqual(Xml::toArray(Xml::fromArray($expected)), $expected); - $this->assertEqual(Xml::toArray(Xml::fromArray($expected, 'tags')), $expected); + $this->assertEqual(Xml::toArray(Xml::fromArray($array, 'tags')), $array); $expected = array( + 'tags' => array( + 'tag' => array( + array( + '@id' => '1', + '@name' => 'defect' + ), + array( + '@id' => '2', + '@name' => 'enhancement' + ) + ) + ) + ); + $this->assertEqual(Xml::toArray(Xml::fromArray($array)), $expected); + + $array = array( 'tags' => array( 'tag' => array( 'id' => '1', @@ -289,7 +319,23 @@ class XmlTest extends CakeTestCase { ) ) ); - $this->assertEqual(Xml::toArray(Xml::fromArray($expected)), $expected); + $expected = array( + 'tags' => array( + 'tag' => array( + '@id' => '1', + 'posts' => array( + array('@id' => '1'), + array('@id' => '2') + ) + ), + 'tagOther' => array( + 'subtag' => array( + '@id' => '1' + ) + ) + ) + ); + $this->assertEqual(Xml::toArray(Xml::fromArray($array)), $expected); $xml = ''; $xml .= 'defect'; @@ -299,7 +345,7 @@ class XmlTest extends CakeTestCase { $expected = array( 'root' => array( 'tag' => array( - 'id' => 1, + '@id' => 1, 'value' => 'defect' ) )