Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP registerXPathNamespace()错误_Php_Xml_Soap_Simplexml - Fatal编程技术网

PHP registerXPathNamespace()错误

PHP registerXPathNamespace()错误,php,xml,soap,simplexml,Php,Xml,Soap,Simplexml,致命错误:在第83行的/home/gateway/public_html/index.php中的非对象上调用成员函数registerXPathNamespace() 我得到的错误在上面,这一行是 $host = "services.incard.com.au/telechoicetransservice.asmx"; $timestamp = getGMTtimestamp(); $vars = "<?xml version=\"1.0\" encoding=\"UTF-8\"?&g

致命错误:在第83行的/home/gateway/public_html/index.php中的非对象上调用成员函数registerXPathNamespace()

我得到的错误在上面,这一行是

$host = "services.incard.com.au/telechoicetransservice.asmx";

$timestamp = getGMTtimestamp();

$vars = 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" .
    "<soap:Body>" .
        "<ProcessPayment xmlns=\"https://services.incard.com.au\">".
        "<auth>" .
            "<AccountCode>". urlencode($_POST['AccountCode'])."</AccountCode>".
            "<Username>". urlencode($_POST['AccountCode'])."</Username>".
            "<Password>". urlencode($_POST['AccountCode'])."</Password>".
        "</auth>" .
        "<MerchantNumber>".urlencode($_POST['MerchantNumber'])."</MerchantNumber>" .
        "<CustomerNumber>".urlencode($_POST['CustomerNumber'])."</CustomerNumber>".
        "<Amount>".urlencode($_POST['Amount'])."</Amount>".
        "<Description>".urlencode($_POST['Description'])."</Description>".
        "</ProcessPayment>".
"</soap:Body></soap:Envelope>";

$response = openSocket($host, $vars);

$xmlres = array();
$xmlres = makeXMLTree ($response);
$xml = simplexml_load_string($response); 
$xml->registerXPathNamespace('soap:Envelope', 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//soap:Envelope:ResponseCode') as $item) {
    echo (string) $item; 
}
foreach ($xml->xpath('//soap:Envelope:ResponseDescription') as $item) {
    echo (string) $item; 
}
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ProcessPaymentResponse xmlns="https://services.incard.com.au">
      <ProcessPaymentResult>
        <ResponseCode>string</ResponseCode>
        <ResponseDescription>string</ResponseDescription>
      </ProcessPaymentResult>
    </ProcessPaymentResponse>
  </soap:Body>
</soap:Envelope>
$host=“services.envod.com.au/telecohoicetransservice.asmx”;
$timestamp=getGMTtimestamp();
$vars=
"" .
"" .
"" .
"".
"" .
"". urlencode($_POST['AccountCode'])。“”。
"". urlencode($_POST['AccountCode'])。“”。
"". urlencode($_POST['AccountCode'])。“”。
"" .
“.urlencode($\u POST['MerchantNumber'])。”。
“.urlencode($\u POST['CustomerNumber'])。”。
“.urlencode($\u POST['Amount'])。”。
“.urlencode($\u POST['Description'])。”。
"".
"";
$response=openSocket($host,$vars);
$xmlres=array();
$xmlres=makeXMLTree($response);
$xml=simplexml\u load\u字符串($response);
$xml->registerXPathNamespace('soap:Envelope','http://schemas.xmlsoap.org/soap/envelope/');
foreach($xml->xpath('//soap:Envelope:ResponseCode')作为$item){
回声(字符串)$项;
}
foreach($xml->xpath('//soap:Envelope:ResponseDescription')作为$item){
回声(字符串)$项;
}
我不明白为什么它不起作用

我们从请求的服务器返回的响应如下

$host = "services.incard.com.au/telechoicetransservice.asmx";

$timestamp = getGMTtimestamp();

$vars = 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" .
    "<soap:Body>" .
        "<ProcessPayment xmlns=\"https://services.incard.com.au\">".
        "<auth>" .
            "<AccountCode>". urlencode($_POST['AccountCode'])."</AccountCode>".
            "<Username>". urlencode($_POST['AccountCode'])."</Username>".
            "<Password>". urlencode($_POST['AccountCode'])."</Password>".
        "</auth>" .
        "<MerchantNumber>".urlencode($_POST['MerchantNumber'])."</MerchantNumber>" .
        "<CustomerNumber>".urlencode($_POST['CustomerNumber'])."</CustomerNumber>".
        "<Amount>".urlencode($_POST['Amount'])."</Amount>".
        "<Description>".urlencode($_POST['Description'])."</Description>".
        "</ProcessPayment>".
"</soap:Body></soap:Envelope>";

$response = openSocket($host, $vars);

$xmlres = array();
$xmlres = makeXMLTree ($response);
$xml = simplexml_load_string($response); 
$xml->registerXPathNamespace('soap:Envelope', 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//soap:Envelope:ResponseCode') as $item) {
    echo (string) $item; 
}
foreach ($xml->xpath('//soap:Envelope:ResponseDescription') as $item) {
    echo (string) $item; 
}
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ProcessPaymentResponse xmlns="https://services.incard.com.au">
      <ProcessPaymentResult>
        <ResponseCode>string</ResponseCode>
        <ResponseDescription>string</ResponseDescription>
      </ProcessPaymentResult>
    </ProcessPaymentResponse>
  </soap:Body>
</soap:Envelope>
HTTP/1.1200正常
内容类型:text/xml;字符集=utf-8
内容长度:长度
一串
一串
尝试更换

<?php
$xml->registerXPathNamespace('soap:Envelope', 
                                   'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//soap:Envelope:ResponseCode') as $item) {
    echo (string) $item; 
}
foreach ($xml->xpath('//soap:Envelope:ResponseDescription') as $item) {
    echo (string) $item; 
}
?>
registerXPathNamespace('soap:Envelope',
'http://schemas.xmlsoap.org/soap/envelope/');
foreach($xml->xpath('//soap:Envelope:ResponseCode')作为$item){
回声(字符串)$项;
}
foreach($xml->xpath('//soap:Envelope:ResponseDescription')作为$item){
回声(字符串)$项;
}
?>

registerXPathNamespace('soap',
'http://schemas.xmlsoap.org/soap/envelope/' );
$result=$xml->xpath('//soap:Body');
foreach($result作为$body){
echo$body->ProcessPaymentResponse->ProcessPaymentResult->ResponseCode。“
”; echo$body->ProcessPaymentResponse->ProcessPaymentResult->ResponseDescription。“
”; } ?>

希望这能有所帮助。

您对
simplexml\u load\u string()
的调用失败。@Michael请解释为什么会这样。