Extract an element from XML
| From: | Angelo Zanetti | Date: | Fri, 31 Jul 2009 07:23:27 +0000 |
| Subject: | Extract an element from XML | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-296092@lists.php.net to get a copy of this message | ||
Hi all,
I have the following segment of XML:
<BookingReference ReferenceSource="api">165432 </BookingReference>
Now I want to get the value of the BookingReference where the
ReferenceSource = "api". In other words I want to get the value 165432.
I have the following code:
$ItemConfirmationReference2 = $xpath->query('BookingReference
ReferenceSource' , $Element);
$ItemConfirmationReference =
trim($ItemConfirmationReference2->item(0)->textContent);
The $Element variable passes the node that contains the BookingReference
node.
The tricky part for me is the ="api" part.
Thanks in advance.
A