Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 f4d5230
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cake/libs/xml.php
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/xml.test.php
Expand Up @@ -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>';
Expand Down

0 comments on commit f4d5230

Please sign in to comment.