note 53724 added to ref.dom

From: Date: Fri, 10 Jun 2005 15:04:13 +0000
Subject: note 53724 added to ref.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-90229@lists.php.net to get a copy of this message
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; } } ---- Manual Page -- http://www.php.net/manual/en/ref.dom.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53724 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53724&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53724&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53724&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53724&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53724&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53724&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90229) next »