note 26023 modified in function.domxml-xmltree by didou

From: Date: Wed, 04 Aug 2004 10:47:02 +0000
Subject: note 26023 modified in function.domxml-xmltree by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73912@lists.php.net to get a copy of this message
Consider the following revisions for including attributes into the array. function domxml_xmlarray ($branch) { $object = Array (); $objptr =& $object; $branch = $branch->first_child (); while ($branch) { if (!($branch->is_blank_node())) { switch ($branch->node_type()) { case XML_TEXT_NODE: { $objptr['cdata'] = $branch->node_value (); break; } case XML_ELEMENT_NODE: { $objptr =& $object[$branch->node_name ()][]; if ($branch->has_attributes ()) { $attributes = $branch->attributes (); if (!is_array ($attributes)) { break; } foreach ($attributes as $index => $domobj) { $objptr[$index] = $objptr[$domobj->name] = $domobj->value; } } break; } } if ($branch->has_child_nodes ()) { $objptr = array_merge ($objptr, domxml_xmlarray ($branch)); } } $branch = $branch->next_sibling (); } return $object; } --was-- Consider the following revisions for including attributes into the array. function domxml_xmlarray ($branch) { $object = Array (); $objptr =& $obj; $branch = $branch->first_child (); while ($branch) { if (!($branch->is_blank_node())) { switch ($branch->node_type()) { case XML_TEXT_NODE: { $objptr['cdata'] = $branch->node_value (); break; } case XML_ELEMENT_NODE: { $objptr =& $object[$branch->node_name ()][]; if ($branch->has_attributes ()) { $attributes = $branch->attributes (); if (!is_array ($attributes)) { break; } foreach ($attributes as $index => $domobj) { $objptr[$index] = $objptr[$domobj->name] = $domobj->value; } } break; } } if ($branch->has_child_nodes ()) { $objptr = array_merge ($objptr, domxml_xmlarray ($branch)); } } $branch = $branch->next_sibling (); } return $object; } http://php.net/manual/en/function.domxml-xmltree.php

« previous php.notes (#73912) next »