Skip to content
Permalink
Browse files

Fixing the read for toArray of content when have child or attribute i…

…n xml.
  • Loading branch information...
jrbasso committed Jul 28, 2010
1 parent 8f1bdd5 commit f4d5230dfa33c541de6817778ef793404e1fe7f3
Showing with 19 additions and 1 deletion.
  1. +4 −1 cake/libs/xml.php
  2. +15 −0 cake/tests/cases/libs/xml.test.php
@@ -140,8 +140,11 @@ protected static function _toArray($xml, &$parentData) {
self::_toArray($child, $data);
}
$asString = trim((string)$xml);
if (empty($data)) {
$data = (string)$xml;
$data = $asString;
} elseif (!empty($asString)) {
$data['value'] = $asString;
}
$name = $xml->getName();
@@ -291,6 +291,21 @@ function testToArray() {
);
$this->assertEqual(Xml::toArray(Xml::fromArray($expected)), $expected);
$xml = '<root>';
$xml .= '<tag id="1">defect</tag>';
$xml .= '</root>';
$obj = Xml::build($xml);
$expected = array(
'root' => array(
'tag' => array(
'id' => 1,
'value' => 'defect'
)
)
);
$this->assertEqual(Xml::toArray($obj), $expected);
$xml = '<root>';
$xml .= '<table xmlns="http://www.w3.org/TR/html4/"><tr><td>Apples</td><td>Bananas</td></tr></table>';
$xml .= '<table xmlns="http://www.cakephp.org"><name>CakePHP</name><license>MIT</license></table>';

0 comments on commit f4d5230

Please sign in to comment.
You can’t perform that action at this time.