note 53724 deleted from ref.dom by didou
| From: | didou@php.net | Date: | Mon, 13 Mar 2006 00:02:34 +0000 |
| Subject: | note 53724 deleted from ref.dom by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-105398@lists.php.net to get a copy of this message | ||
Note Submitter: mjs15451 at hotmail dot com
----
Disregard the last post from toma at smartsemantics dot com. His function does not parse xml
properly. It does not take into account multiple tags of the same name, multiple of the same
attributes in each tag and even attributes that might occur once and not in the others. So there is
no way to accurately tell where you are in the XML structure. I modified this function and tested
it. If there are any bugs, feel free to modify it and repost but to my knowledge this is an
accurate XML parsing function:
function parseXML($dom, &$arrXML){
$arrPointer = &$arrXML;
$dom = $dom->firstChild;
while (! is_null($dom)){
switch ($dom->nodeType){
case XML_TEXT_NODE:
if (trim($dom->nodeValue) != ''){ //if there are tags inside a tag, generally there
isn't a text value so don't show it
$arrPointer['value'] = $dom->nodeValue;
}
break;
case XML_ELEMENT_NODE:
$arrPointer = &$arrXML[$dom->nodeName][];
if ($dom->hasAttributes()){
$attributes = $dom->attributes;
foreach ($attributes as $index => $oAttr){
$arrPointer['attributes'][$oAttr->name] = $oAttr->value;
}
}
break;
}
if ($dom->hasChildNodes()){
parseXML($dom, $arrPointer);
}
$dom = $dom->nextSibling;
}
}