Re: AW: [PEAR-DEV] Package Proposal XML_Parser_Assoc
| From: | Justin Patrin | Date: | Fri, 30 Jan 2004 22:33:41 +0000 |
| Subject: | Re: AW: [PEAR-DEV] Package Proposal XML_Parser_Assoc | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-25356@lists.php.net to get a copy of this message | ||
Stephan Schmidt wrote:
Hi,With this or XML_Unserializer you get nearly the same data. The major difference is that my package will unserialize any XML and give you a usefull array of all data in the XML. XML_Unserializer is mostly to unserialize XML made with XML_Serializer. Even though it can unserialize any XML, it gives a structure which isn't always the same, whereas mine does. What my package specifically does different is: * segregates attributes and sub-elements into different assoc arrays -This is good because attributes are unique while sub-elements are not * Always puts sub-elements into an array. -This allows for one way to access elements instead of multiple ways. You don't have to do an is_array() to see if an element has multiples before you try to access it. You can still access a specific element easily: $subElem = (is_array($elem['subElem']) ? $elem['subElem'][0] : $elem['subElem']) in XML_Unserializer would be $elem['subElements']['subElem'][0] with the new package OR XML_Parser_Assoc::getElement($elem['subElements'], array('subElem')); * CData in an element with sub-elements is picked up, unlike XML_Unserializer Here's an example: <CRUMB ID="1"> <PARAM TYPE="id">The package is XML_Parser_Assoc. It is similar to XML_Unserialize, but it takes a stricter approach, seperating attributes and sub-elements and only giving them in one format, always an array. The package is finished, but very undocumented (I can add more easily). It also includes a few functions to get certain sub-elements out of the resulting PHP array. (Like very simple XPath selecting.)What can it do that XML_Unserializer can't? Stephan
1</PARAM> <CRUMB ID="2">
<PARAM TYPE="id">
3
</PARAM>
</CRUMB>
<CRUMB ID="3">
</CRUMB>
crumb data
</CRUMB>
become this in XML_Unserilizer:
Array
(
[param] => 1
[crumb] => Array
(
[0] => Array
(
[param] => 3
)
[1] =>
)
)
Note the lack of the "crumb data" cdata.
My package gives you this (it is much larger and more verbose, but it tells you exactly what you have):
Array
(
[CRUMB] => Array
(
[0] => Array
(
[name] => CRUMB
[attributes] => Array
(
[ID] => 1
)
[data] => crumb data
[subElements] => Array
(
[PARAM] => Array
(
[0] => Array
(
[name] => PARAM
[attributes] => Array
(
[TYPE] => id
)
[data] => 1
[subElements] => Array
(
)
)
)
[CRUMB] => Array
(
[0] => Array
(
[name] => CRUMB
[attributes] => Array
(
[ID] => 2
)
[subElements] => Array
(
[PARAM] => Array
(
[0] => Array
(
[name] => PARAM
[attributes] => Array
(
[TYPE] => id
)
[data] => 3
[subElements] => Array
(
)
)
)
)
)
[1] => Array
(
[name] => CRUMB
[attributes] => Array
(
[ID] => 3
)
[subElements] => Array
(
)
)
)
)
)
)) -- paperCrane <Justin Patrin>