Jump to content

how to convert xml file to dom nodes


seco

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.