#25264 [Opn->Asn]: XML_Unserializer doesn't support element attributes

From: Date: Wed, 27 Aug 2003 07:18:41 +0000
Subject: #25264 [Opn->Asn]: XML_Unserializer doesn't support element attributes
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-20608@lists.php.net to get a copy of this message
ID: 25264 Updated by: schst@php.net -Reported By: marshall at exclupen dot com +Reported By: schst@php.net -Status: Open +Status: Assigned Bug Type: PEAR related PHP Version: Irrelevant -Assigned To: +Assigned To: schst New Comment: I will add a feature to unserialize tags with attributes in the next release, currently working on it. Previous Comments: ------------------------------------------------------------------------ [2003-08-26 16:58:35] schst@php.net Description: ------------ XML_Unserializer works great for turning an XML file into an array, but I can't figure out how to get attributes. Here's a hypothetical example using http://pear.php.net/rss.php as a base: Array ( [channel] => Array ( [language] => en [image] => Array ( [url] => http://pear.php.net/gifs/pearsmall.gif [link] => http://pear.php.net/ ) ... } Now, I know this would be against the RSS spec (I just needed an example XML file), but what if "image" had width and height attributes? [image] => Array ( [url] => http://pear.php.net/gifs/pearsmall.gif [link] => http://pear.php.net/ [attr_width] => 104 [attr_height] => 50 ) All is well and good there. Now imagine that "link" has a "title" attribute: [image] => Array ( [url] => http://pear.php.net/gifs/pearsmall.gif [link] => Array { [0] => http://pear.php.net/ [attr_title] => PEAR } } Suddenly, "link" has changed from a string to an array. If the attributes are optional, you could never be sure which it would be. The 0 is used as a key to avoid naming conflicts that could come up with "content" or "data". One solution would be to make every value an array. Strings would become arrays with only 1 element (key 0). Reproduce code: --------------- require_once 'XML/Unserializer.php'; $options = array('complexType' => 'array'); $unserializer = &new XML_Unserializer($options); $unserializer->unserialize('http://pear.php.net/rss.php', true); $rss = $unserializer->getUnserializedData(); echo "<pre>"; print_r($rss); echo "</pre>"; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25264&edit=1

« previous php.pear.dev (#20608) next »