note 25962 added to function.domxml-xmltree

From: Date: Sun, 13 Oct 2002 02:19:22 +0000
Subject: note 25962 added to function.domxml-xmltree
Groups: php.notes 
Request: Send a blank email to php-notes+get-37991@lists.php.net to get a copy of this message
This function is nice, however it includes all the useless white-space in XML documents. Here is a function that may be more useful: function domxml_xmlarray($branch) { $branch = $branch->first_child(); while ($branch) { if (!($branch->is_blank_node())) { $objptr = &$object[]; switch ($branch->node_type()) { case XML_TEXT_NODE: $objptr['cdata'] = $branch->node_value(); break; case XML_ELEMENT_NODE: $objptr['tagname'] = $branch->node_name(); break; } if ($branch->has_child_nodes()) { $result = domxml_xmlarray($branch); foreach ($result as $values) { array_push($objptr, $values); } } } $branch = $branch->next_sibling(); } return $object; } You would use the function like so: $xmlobj = domxml_open_file('file.xml'); $result = domxml_xmlarray($xmlobj); print_r($result); -- http://www.php.net/manual/en/function.domxml-xmltree.php http://master.php.net/manage/user-notes.php?action=edit+25962 http://master.php.net/manage/user-notes.php?action=delete+25962 http://master.php.net/manage/user-notes.php?action=reject+25962

« previous php.notes (#37991) next »