我试图访问下面的xml的'code'元素,使用simplexml,并遇到错误。
$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;
这打印错误:警告:yyy上的/home/xxx/xxx/test.php中不再存在节点
detail没有名称空间soapenv
$soap_fault = $xml->children('soapenv', true)
->Body->children('soapenv', true)
->Fault->children() // no namespace
->detail->children('ns1', true)
->HpiSoapFault
->Error
->Code;