php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25264 XML_Unserializer doesn't support element attributes
Submitted: 2003-08-26 16:58 UTC Modified: 2003-09-11 11:34 UTC
From: marshall at exclupen dot com Assigned: schst (profile)
Status: Closed Package: PEAR related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2003-08-26 16:58 UTC] 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>";


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-27 02:18 UTC] schst@php.net
I will add a feature to unserialize tags with attributes in the next release, currently working on it.
 [2003-08-27 04:02 UTC] schst@php.net
changed email address back, /me is stupid

BTW: This is not bug, just a feature request.
 [2003-09-11 11:34 UTC] schst@php.net
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.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Aug 05 02:01:23 2021 UTC