mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-12 20:49:50 +00:00
Fixing the read for toArray of content when have child or attribute in xml.
This commit is contained in:
parent
8f1bdd5378
commit
f4d5230dfa
2 changed files with 19 additions and 1 deletions
|
@ -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();
|
||||
|
|
|
@ -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>';
|
||||
|
|
Loading…
Add table
Reference in a new issue