带有 simplexml 的 SOAP
SOAP with simplexml
我正在尝试使用简单xml 访问下面 xml 的 'code' 元素,但遇到错误。
$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;
这会打印错误:
警告:节点不再存在于 /home/xxx/xxx/test.php 行 yyy
详细信息没有命名空间 soapenv
$soap_fault = $xml->children('soapenv', true)
->Body->children('soapenv', true)
->Fault->children() // no namespace
->detail->children('ns1', true)
->HpiSoapFault
->Error
->Code;
我正在尝试使用简单xml 访问下面 xml 的 'code' 元素,但遇到错误。
$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;
这会打印错误: 警告:节点不再存在于 /home/xxx/xxx/test.php 行 yyy
详细信息没有命名空间 soapenv
$soap_fault = $xml->children('soapenv', true)
->Body->children('soapenv', true)
->Fault->children() // no namespace
->detail->children('ns1', true)
->HpiSoapFault
->Error
->Code;