diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 3c79eb630..1a2048800 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -201,6 +201,7 @@ class XmlNode extends Object { } $tagOpts = $this->__tagOptions($name); + if ($tagOpts === false) { return; } @@ -221,7 +222,6 @@ class XmlNode extends Object { $attributes = array(); $children = array(); $chldObjs = array(); - $document =& $this->document(); if (is_object($object)) { $chldObjs = get_object_vars($object); @@ -239,7 +239,12 @@ class XmlNode extends Object { $node->createTextNode($chldObjs[$tagOpts['value']]); unset($chldObjs[$tagOpts['value']]); } - unset($chldObjs['_name_']); + + $n = $name; + if (!empty($chldObjs['_name_'])) { + $n = null; + unset($chldObjs['_name_']); + } $c = 0; foreach ($chldObjs as $key => $val) { @@ -247,14 +252,11 @@ class XmlNode extends Object { $attributes[$key] = $val; } else { if (!isset($tagOpts['children']) || $tagOpts['children'] === array() || (is_array($tagOpts['children']) && in_array($key, $tagOpts['children']))) { - $n = $key; - - if (is_numeric($n)) { - $n = $name; + if (!is_numeric($key)) { + $n = $key; } if (is_array($val)) { - foreach ($val as $i => $obj2) { - $n2 = $i; + foreach ($val as $n2 => $obj2) { if (is_numeric($n2)) { $n2 = $n; } @@ -262,6 +264,7 @@ class XmlNode extends Object { } } else { if (is_object($val)) { + $node->normalize($val, $n, $options); } elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) { $tmp =& $node->createElement($key); @@ -630,7 +633,6 @@ class XmlNode extends Object { if ($options['whitespace']) { $d .= "\n"; } - $count = count($this->children); $cDepth = $depth + 1; for ($i = 0; $i < $count; $i++) { diff --git a/cake/tests/cases/libs/view/helpers/xml.test.php b/cake/tests/cases/libs/view/helpers/xml.test.php index 514de9495..c7b1bae73 100644 --- a/cake/tests/cases/libs/view/helpers/xml.test.php +++ b/cake/tests/cases/libs/view/helpers/xml.test.php @@ -202,7 +202,7 @@ class XmlHelperTest extends CakeTestCase { $result = $this->Xml->serialize($data, array('format' => 'tags')); $expected = '12'; $this->assertIdentical($result, $expected); - + $data = array( 'Pages' => array('id' => 2, 'url' => 'http://www.url.com/rb/153/?id=bbbb&t=access') ); @@ -210,6 +210,24 @@ class XmlHelperTest extends CakeTestCase { $expected = ''; $this->assertIdentical($result, $expected); } +/** + * testSerializeOnMultiDimensionalArray method + * + * @access public + * @return void + */ + function testSerializeOnMultiDimensionalArray() { + $data = array( + 'Statuses' => array( + array('Status' => array('id' => 1)), + array('Status' => array('id' => 2)) + ) + ); + $result = $this->Xml->serialize($data, array('format' => 'tags')); + $expected = '12'; + $this->assertIdentical($result, $expected); + + } /** * testHeader method * diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index 386a9d94b..e53a452e8 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -98,6 +98,25 @@ class XmlTest extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * testSerializeOnMultiDimensionalArray method + * + * @access public + * @return void + */ + function testSerializeOnMultiDimensionalArray() { + $data = array( + 'Statuses' => array( + array('Status' => array('id' => 1)), + array('Status' => array('id' => 2)) + ) + ); + $result =& new Xml($data, array('format' => 'tags')); + $expected = '12'; + $this->assertIdentical($result->toString(), $expected); + + } + /** * test serialization of boolean and null values. false = 0, true = 1, null = '' * @@ -118,7 +137,7 @@ class XmlTest extends CakeTestCase { $result = $xml->toString(false); $expected = ''; $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); - + $xml =& new Xml(array('data' => array('example' => 0))); $result = $xml->toString(false); $expected = '';