Extract an element from XML
am 31.07.2009 09:23:27 von ANGELO ZANETTI
Hi all,
I have the following segment of XML:
165432
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Extract an element from XML
am 31.07.2009 11:57:16 von Aschwin Wesselius
Angelo Zanetti wrote:
> Hi all,
>
> I have the following segment of XML:
>
> 165432
>
> 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
>
>
>
Hi 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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Extract an element from XML
am 31.07.2009 11:59:14 von Aschwin Wesselius
Aschwin Wesselius wrote:
> Angelo Zanetti wrote:
>> Hi all,
>> I have the following segment of XML:
>>
>> 165432
>>
>> 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
>>
>>
>>
> Hi 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:
$xpath->query('BookingReference[@ReferenceSource="api"]/');
There was a '/' after BookingReference.....
Kind regards,
Aschwin Wesselius
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php