I need a little help to figure out XPath search inside XML output simple_xml_load in PHP. I have this XML:
<PRODUCTS>
<PRODUCT>
<CODE>5009444</CODE>
<NAME>Prova</NAME>
<IMG>prova.jpg</IMG>
</PRODUCT>
....
....
</PRODUCTS>
I want to filter and iterate through this data to find and return all occurrences with a variable code. I used this syntax but didn't work
$id = 1;
$struct = \App\Models\Structures::where('id', $id)->first();
$url = 'http://demo.villaggissimi.it/public/xml/CMP_' . $struct->operators->pk .'.xml';
$xc = simplexml_load_file($url) or die("Non sono stati trovati risultati");
$xml2 = $xc->xpath("/PRODUCTS/PRODUCT[CODE='$struct->code']");
return response()->json($xml2);
[@CODE=
in XPath – Nigel Ren$url
and$struct
), and the output you got. – IMSoP