Re: XML_Unserializer - is it right?

From: Date: Fri, 30 Jan 2004 17:06:02 +0000
Subject: Re: XML_Unserializer - is it right?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-10443@lists.php.net to get a copy of this message
As I told, I don't wanted to resolve it using IF. A better solution would be if at the $options exist a parameter like: alwaysArray = array('child') that would make the property child always be an array, even if complexType = 'object' but a change like this at the class would be done only if other people than me agree. At 17:55 30/1/2004 +0100, Bertrand Mansion wrote:
<maka3d@yahoo.com.br> wrote : //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 This will do: if (!is_int(key($data['child']))) {
    $data['child'] = array($data['child']);
} Unless you suggest a better solution... Bertrand Mansion Mamasam -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.pear.general (#10443) next »