Fixing the read for toArray of content when have child or attribute in xml.

This commit is contained in:
Juan Basso 2010-07-28 18:53:36 -03:00
parent 8f1bdd5378
commit f4d5230dfa
2 changed files with 19 additions and 1 deletions

View file

@ -140,8 +140,11 @@ class Xml {
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();

View file

@ -291,6 +291,21 @@ class XmlTest extends CakeTestCase {
);
$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>';