RE: Extract code from XML

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

 




-----Original Message-----
From: Per Jessen [mailto:per@xxxxxxxxxxxx] 
Sent: 30 January 2009 11:53
To: php-general@xxxxxxxxxxxxx
Subject: Re:  Extract code from XML

Angelo Zanetti wrote:

> Hi all,
> 
> I have the following snippet of XML:
> 
> Code:
> 
> <HotelDetails>
> 
> <Hotel HasExtraInfo="true" HasMap="true" HasPictures="true">
> 
> <Item Code="AME"><![CDATA[ AMERICAN ]]></Item>
> 
> I need to get the Code for the item, IE get the value "AME" from the
> XML. I am using PHP5 and the following code which I can extract the
> value of the Item: "AMERICAN".
> 
> PHP Code:
> 
>  $hotelElements = $xpath->query( 'HotelDetails/Hotel',
> $searchHotelPriceReponseElement );
> 
>     foreach( $hotelElements as $hotelElement ) {
> 
>         $item = $xpath->query( 'Item' , $hotelElement );
> 
> 
> 
> I know you can use an @ sign but I am not 100% sure.

Yes, you use an '@' to retrieve attributes of an element.

query( 'HotelDetails/Hotel/@Code' ....


Thanks Per but I didn't send all the XML but you see that there is a city
code and an item code: 

  <Hotel HasExtraInfo="true" HasMap="true" HasPictures="true">
                                 <Recommended = "true">
			<City Code="AMS"><![CDATA[ Amsterdam ]]></City>
			<Item Code="AME"><![CDATA[ AMERICAN ]]></Item>

How would I get the Item code then? Based on your answer above?

Thanks
Angelo



-- 
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