The xml file that I need to get out data is large and has lot of inner children in children. The XML on what I need to query looks like in the picture and it has more Ref children in company. xml structure
I need to get the company node that has the correct Info->ID. That node has 3 Ref nodes and I need to get Date from the one that has the correct Who.
I got this working with this ugly code:
$query_pod = "//Seller/Company/Info/ID[ID = 'IV'] | //Seller/Company/Ref/Who[Who = 'VA'] | //Seller/Company/Ref/Date";
foreach ($xpath->query( $query_pod ) as $pod)
{
$pod_dates = $xpath->query( "//Seller/Company/Ref/Who[Who = 'VA'] | //Seller/Company/Ref/Date", $pod );
$pod_date = $pod_dates->item(0)->nodeValue;
}
I tryed it shorter but I cant get the select element in [] like this:
$query_pod = "//Seller/Company/Info[ID = 'IV']";
foreach ($xpath->query( $query_pod ) as $pod)
{
$pod_dates = $xpath->query( "//Seller/Company/Ref/Date[Who = 'VA'], $pod );
$pod_date = $pod_dates->item(0)->nodeValue;
}
Can someone help? I'm new to xpath.