note 19340 added to function.xmldoc

From: Date: Sun, 24 Feb 2002 11:32:45 +0000
Subject: note 19340 added to function.xmldoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-26983@lists.php.net to get a copy of this message
I'm using this function to parse SIMPLE xml docs to a more usable arrays. Be care, it will not work in case of something like: <a><b>hello</b>bye</a> The bye text will not beign recognized. This function is to parse more simple XML like: <a><b>hello</b><c>bye</c></a> It also don't manage attributes :) Hope it helps!... function get_array_from_xml($xml) { // Consultamos si realmente hay hijos por mirar $children = $xml->children(); if(!is_array($children)) return(''); // Creamos el vector de datos $data = array(); // Iteramos y nos volvemos a llamar si es necesario foreach($children as $child) { if($child->type == XML_ELEMENT_NODE) { $tagname = $child->tagname; $data["$tagname"] = get_array_from_xml($child); } elseif($child->type == XML_TEXT_NODE) { return($child->content); } } return($data); } -- http://www.php.net/manual/en/function.xmldoc.php http://master.php.net/manage/user-notes.php?action=edit+19340 http://master.php.net/manage/user-notes.php?action=delete+19340 http://master.php.net/manage/user-notes.php?action=reject+19340

« previous php.notes (#26983) next »