XML_Unserializer - is it right?
| From: | Marcos Neves | Date: | Fri, 30 Jan 2004 16:05:06 +0000 |
| Subject: | XML_Unserializer - is it right? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-10441@lists.php.net to get a copy of this message | ||
//The XML_Unserializer does not create the same dataType for
//the follow two xml.
$xml = "<root id='12'>
<child name='john' age='23'/>
<child name='paul' age='24'/>
</root>";
$xml2 = "<root id='12'>
<child name='john' age='23'/>
</root>";
// the only difference between $xml and $xml2 is that the second has only 1 child
require_once 'XML/Unserializer.php';
$options = array('complexType'=>'array', 'parseAttributes'=>true);
$tree = & new XML_Unserializer($options);
$tree->unserialize($xml);
$data = $tree->getUnserializedData();
foreach($data['child'] as $child):
var_dump($child); // the data type is not the same for $xml and $xml2
endforeach;
// It means that I have always two situations:
// 1 - when I have only 1 child
// 2 - when I have 2 or more
// I don't want to resolve it putting IF every time I have to iterate over a child
// is it a bug, or I'm missing something