note 25962 deleted from function.domxml-xmltree by didou

From: Date: Wed, 04 Aug 2004 10:47:39 +0000
Subject: note 25962 deleted from function.domxml-xmltree by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73914@lists.php.net to get a copy of this message
Note Submitter: nutbar@innocent.com ---- 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);

« previous php.notes (#73914) next »