#25264 [NEW]: XML_Unserializer doesn't support element attributes

From: Date: Tue, 26 Aug 2003 21:58:35 +0000
Subject: #25264 [NEW]: XML_Unserializer doesn't support element attributes
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-20584@lists.php.net to get a copy of this message
From: marshall at exclupen dot com Operating system: PHP version: Irrelevant PHP Bug Type: PEAR related Bug description: XML_Unserializer doesn't support element attributes 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 bug report at http://bugs.php.net/?id=25264&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25264&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25264&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25264&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25264&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25264&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25264&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25264&r=support Expected behavior: http://bugs.php.net/fix.php?id=25264&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25264&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25264&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25264&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25264&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25264&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25264&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25264&r=gnused

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