1

I have a xml. as shown in the attachment .. How can I read the contents via php

http://agency.lastminute-hr.com/slike/xml_read1.jpg "XML"

Now I read this xml:

<?

    $request            = new SimpleXMLElement('<HotelInfoRequest/>');
    $request->Username  = 'SERUNCD';
    $request->Password  = 'TA78UNC';
    $request->HotelID  = '123';



    $url    = "http://wl.filos.com.gr/services/WebService.asmx/HotelInfo";
    $result = simplexml_load_file($url . "?xml=" . urlencode($request->asXML()));



    function RecurseXML($xml,$parent="")
    {
       $child_count = 0;
       foreach($xml as $key=>$value)
       {
          $child_count++;   

          if(RecurseXML($value,$parent.".".$key) == 0)  // no childern, aka "leaf node"
          {

             print($parent . "." . (string)$key . " = " . (string)$value . "<BR>\n");       
          }    
       }
       return $child_count;
    } 

    RecurseXML($result); 
?>

this result look:

..
..
.Response.Hotels.Hotel.Rooms.Room.Quantity = 0
.Response.Hotels.Hotel.Rooms.Room.MaxPax = 3
.Response.Hotels.Hotel.Rooms.Room.MinPax = 2
.Response.Hotels.Hotel.Rooms.Room.RoomType.languages.lang = Room Double Standard
.Response.Hotels.Hotel.Rooms.Room.RoomType.languages.lang = Camera single standard
...
...

I need you to display the value and adttribut

<Rooms>
    <Room ID = "5556">
      <Quantity> 0 </ Quantity>
      <MaxPax> 3 </ MaxPax>
      <MinPax> 2 </ MinPax>
      <Roomtype> </ roomtype>
</ Room>
....
..
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
sale2211
  • 51
  • 1
  • 13
  • possible duplicate of [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Kevin Nov 04 '14 at 07:39

1 Answers1

1

Try (the first part is only for testing):

$string = <<<XML
<?xml version='1.0'?>
<Rooms>
    <Room ID = "5556">
      <Quantity> 0 </Quantity>
      <MaxPax> 3 </MaxPax>
      <MinPax> 2 </MinPax>
      <Roomtype> </Roomtype>
    </Room>
</Rooms>
XML;

$result = simplexml_load_string($string);

function RecurseXML($xml,$parent=".Response.Hotels.Hotel.Rooms"){
    $children = $xml->children();
    if ( empty($children) ) {
        print($parent . "." . $xml->nodeName .  " = " . (string)$xml . "<BR>\n");
    }
   else {
        foreach($children as $key=>$value) {
            RecurseXML($value, $parent . "." . $key);
        }
    }
}

RecurseXML($result);
M. Page
  • 2,694
  • 2
  • 20
  • 35
  • Yes, that's why I wrote: it's "pseudo-code". This means that you have to replace `is leaf` by the actual test indicating whether the current node is a leaf. I don't know what you are using for analyzing your XML (SimpleXML, DOM XML, ...), that's why I wrote it like this. – M. Page Nov 04 '14 at 10:29