php - How to Parse Nested XML to nested Array? -


how pass xml array use in soap function.

$res=$client->ota_hoteldestinationsrq($myarray);  <ota_hoteldestinationsrq version="1.0">       <pos>         <source>              <uniqueid id="username:password" />                    </source>       </pos>       <destinationinformation languagecode="en" /> </ota_hoteldestinationsrq> 

you can use code this:

function process( domnode $node){     // special handling character data     if( $node instanceof domcharacterdata){         return $node->data;     }      // has text inside:     if( ($node->childnodes->length == 1) && ($node->childnodes->item(0)->nodename == '#text') && ($node->childnodes->item(0) instanceof domcharacterdata)){         return $node->childnodes->item(0)->data;     }      // attributes     $result = array();     foreach( $node->attributes $item){         $result[ $item->name] = $item->value;     }      // go trough child nodes     foreach($node->childnodes $sub){         $result[$sub->nodename] = process( $sub);     }      return $result; } 

and result:

array (     [version] => 1.0     [pos] => array         (             [source] => array                 (                     [uniqueid] => array                         (                             [id] => username:password                         )                  )          )      [destinationinformation] => array         (             [languagecode] => en         )      [text] => text ) 

useful documentation links:


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -