Re: Extract an element from XML
| From: | Aschwin Wesselius | Date: | Fri, 31 Jul 2009 09:59:14 +0000 |
| Subject: | Re: Extract an element from XML | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296099@lists.php.net to get a copy of this message | ||
Aschwin Wesselius wrote:
Angelo Zanetti wrote:$xpath->query('BookingReference[@ReferenceSource="api"]/'); There was a '/' after BookingReference..... Kind regards, Aschwin WesseliusHi 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. AHi Angelo, Probably it is something along the lines like: $xpath->query('BookingReference/[@ReferenceSource="api"]/'); Fairly simple and XPath is way powerful! Kind regards, Aschwin Wesselius Ah, sorry about that: