seco Posted January 14, 2008 Share Posted January 14, 2008 Hi i have xml file and i want to use the following function to convert xml to array so what is the node that i should pass to this function ? i mean how to convert xml file to nodes to pass it to the function? <?php # public function xmlToArray($domnode, &$array) # { # $array_ptr = &$array; # $domnode = $domnode->firstChild; # while (!is_null($domnode)) # { # if (! (trim($domnode->nodeValue) == "") ) # { # switch ($domnode->nodeType) # { # case XML_TEXT_NODE: # { # $array_ptr['data'] = $domnode->nodeValue; # break; # } # case XML_ELEMENT_NODE: # { # $array_ptr = &$array[$domnode->nodeName][]; # if ($domnode->hasAttributes() ) # { # $attributes = $domnode->attributes; # if (!is_array ($attributes)) # { # break; # } # foreach ($attributes as $index => $domobj) # { # $array_ptr[$index] = $array_ptr[$domobj->name] = $domobj->value; # } # } # break; # } # } # if ( $domnode->hasChildNodes() ) # { # $this->xmlToArray($domnode, $array_ptr); # } # } # $domnode = $domnode->nextSibling; # } # } // xmlToArray ?> thanks in advance. Link to comment https://forums.phpfreaks.com/topic/85935-how-to-convert-xml-file-to-dom-nodes/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.