PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_Serializer » Bug #7913

'fault' in interpreting XML in xml unserializer makes it almost unuseable.

Details

Request #7913'fault' in interpreting XML in xml unserializer makes it almost unuseable.
Submitted2006-06-15 22:14 UTC
Fromjameshfisher at gmail dot com
StatusBogus
PackageXML_Serializer
PHP Version5.1.2
OSWindows XP
Roadmaps(Not assigned)

Comments

[2006-06-15 22:14 UTC] jameshfisher at gmail dot com

Description:
------------
I have attempted to use the XML_Unserializer with XML_Serializer to parse, edit, and resave xml. I currently do this without any DTDs, as for the small scale I am working on, they are inappropriate.
The problem lies in XML_Unserializer. I attempt to unserializer a file such as:

<contact_list>
<contact>
<name>James</name>
<email_address>jameshfisher@gmail.com</email_address>
</contact>
</contact_list>

As is hopefully obvious, <contact_list>, in whatever implementation, would contain an array of <contact> elements. I would expect to be able to this array in the normal way, [0], [1], [2], etc. However, when I unserialize, and when there is only one <contact> element, this array does not appear to exist: instead, it is replaced with the one <contact> element.
I would expect this rather to be an array with one element. The fact that it is not is EXTREMELY irritating from the point of view of editing the data. If I want to add a new <contact>, rather than simply being able to array_push onto the array of contacts, I have to go through the process of checking whether it is an array, and producing separate code for each case.
This is extremely time consuming. The solution seems to be extremely simple: when only one element is encountered it should not be collapsed to just that element, but should continue to be an array.