I am trying to access the 'code' element of the below xml, using simplexml, and experiencing an error.
$response = '<?xml version=\'1.0\' encoding=\'utf-8\'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>Invalid Request. Please refer to detail section for more information</faultstring>
<detail>
<ns1:HpiSoapFault xmlns:ns1="http://webservices.hpi.co.uk/SupplementaryEnquiryV1">
<ns1:Error>
<ns1:Code>012</ns1:Code>
<ns1:Description>VRM is invalid</ns1:Description>
</ns1:Error>
</ns1:HpiSoapFault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>';
$xml = @simplexml_load_string($response);
$soap_fault = $xml->children('soapenv', true)
->Body->children('soapenv', true)
->Fault->children('soapenv', true)
->detail->children('ns1', true)
->HpiSoapFault
->Error
->Code;
This prints error: Warning: Node no longer exists in /home/xxx/xxx/test.php on line yyy
detail doesn't have namespace soapenv
$soap_fault = $xml->children('soapenv', true)
->Body->children('soapenv', true)
->Fault->children() // no namespace
->detail->children('ns1', true)
->HpiSoapFault
->Error
->Code;