I have checked multiple examples and the w3Schools tutorial but I can\'t figure out the structure of the SOAP response. I haven\'t touch php/xml in more than 10 years so you
The problem here is that your attribute has a namespace, so you need to register the ns with SimpleXML XPath and use it in your XPath query.
This element declares two namespaces for its descendants:
To register those namespaces with SimpleXML, you need to use the function registerXPathNamespace. Depending on what other queries you're doing, you might want to register both namespaces. For your query, you need the urn:schemas-microsoft-com:xml-diffgram-v1
(diffgr
) namespace; register it like so:
$sxe = new SimpleXMLElement($your_xml_here);
$sxe->registerXPathNamespace('d', 'urn:schemas-microsoft-com:xml-diffgram-v1');
Now you can access any element or attribute in the diffgr
namespace by prefixing it with the letter d
. Here's an example using the Table
element with id Table1
:
$tables = $sxe->xpath('//Table[@d:id="Table1"]');
foreach ($tables as $t) {
echo $t->ProductSequence . PHP_EOL;
}
Output:
A1999