note 19340 deleted from function.xmldoc by nlopess

From: Date: Mon, 28 Jun 2004 15:05:25 +0000
Subject: note 19340 deleted from function.xmldoc by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72029@lists.php.net to get a copy of this message
Note Submitter: ricardpillosuATdorna.es ---- 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); }

« previous php.notes (#72029) next »