#25264 [Asn->Csd]: XML_Unserializer doesn't support element attributes
| From: | schst@php.net | Date: | Thu, 11 Sep 2003 15:34:12 +0000 |
| Subject: | #25264 [Asn->Csd]: XML_Unserializer doesn't support element attributes | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-21395@lists.php.net to get a copy of this message | ||
ID: 25264
Updated by: schst@php.net
Reported By: marshall at exclupen dot com
-Status: Assigned
+Status: Closed
Bug Type: PEAR related
PHP Version: Irrelevant
Assigned To: schst
New Comment:
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
This has been added for the current CVS version. There are sveral ways
of reading XML with attributes, as well as writing attributes. Will be
included in the next release.
Previous Comments:
------------------------------------------------------------------------
[2003-08-27 04:02:15] schst@php.net
changed email address back, /me is stupid
BTW: This is not bug, just a feature request.
------------------------------------------------------------------------
[2003-08-27 02:18:40] schst@php.net
I will add a feature to unserialize tags with attributes in the next
release, currently working on it.
------------------------------------------------------------------------
[2003-08-26 16:58:35] marshall at exclupen dot com
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