Re: XML Get Value of Node DOMXPath

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stephen Alistoun wrote:
Hello all,

Need help to get the value of the node.

We know how to get the value of the city , item and itemPrice nodes below.

How do we get the value of NumberOfRooms?


$hotelElements = $xpath->query( 'xxxx', $searchReponseElement );
						
foreach( $hotelElements as $hotelElement ) {

$city = $xpath->query( 'City' , $hotelElement );
$item = $xpath->query( 'Item' , $hotelElement );
$itemPrice = $xpath->query( 'ItemPrice' , $hotelElement );
$confirmation = $xpath->query( 'Confirmation' , $hotelElement );

}
Here is an example of the XML Response:

<Hotel HasExtraInfo="true">
		      <City Code="AMS"><![CDATA[ Amsterdam ]]></City>
		      <Item Code="JAN"><![CDATA[ JAN LUYKEN HTL AND RESIDENCE]]></Item>
		      <LocationDetails>
		          <Location Code="G1"><![CDATA[ Central ]]></Location>
		      </LocationDetails>
		      <StarRating>4</StarRating>
             <HotelRooms>
<HotelRoom Code="SB" NumberOfRooms="1" /> <HotelRoom Code="TB" ExtraBed="true" NumberCots="1" NumberOfExtraBeds="2" NumberOfRooms="1 SharingBedding="true" /> </HotelRooms>

Thanks

You can do it in a number of ways.

$rooms = $xpath->query('/Hotel/HotelRooms/HotelRoom');

/* Via DOMElement */
foreach ($rooms AS $room) {
    echo $room->getAttribute('NumberOfRooms') . "\n\n";
}


/* Via XPath */
foreach ($rooms AS $room) {
   $numrooms = $xpath->evaluate('number(./@NumberOfRooms)', $room);
   echo $numrooms . "\n\n";
}

Rob

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux