Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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解析soapxml_Php_Xml_Soap - Fatal编程技术网

PHP解析soapxml

PHP解析soapxml,php,xml,soap,Php,Xml,Soap,我有以下代码: $xml = '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ServiceQualification"> <x:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-

我有以下代码:

$xml = '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ServiceQualification">
    <x:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:UsernameToken>
                <wsse:Username>'.$username.'</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </x:Header>
    <x:Body>
        <urn:AddressSearch>
            <urn:property>
                <urn:unit_no>'.$unit_no.'</urn:unit_no>
                <urn:house_no>'.$house_no.'</urn:house_no>
                <urn:lot_no>'.$lot_no.'</urn:lot_no>
                <urn:street_name>'.$street_name.'</urn:street_name>
                <urn:street_type>'.$street_type.'</urn:street_type>
                <urn:suburb>'.$suburb.'</urn:suburb>
                <urn:state_name>'.$state_name.'</urn:state_name>
                <urn:postcode>'.$postcode.'</urn:postcode>
            </urn:property>
        </urn:AddressSearch>
    </x:Body>
</x:Envelope>';

$response = curl($url,$xml);

$clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $response);

$xml_response = simplexml_load_string($clean_xml) or die("Error: Cannot create object");
echo "<pre>";
print_r($xml_response);
echo "</pre>";
我想知道为什么我会得到一个空白的回复,因为不应该是这样,因为我试着在中做,我得到了数据

这是邮递员或回飞棒的回应:

<?php
ini_set('display_errors', 1);
$string='<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:ServiceQualification">
    <SOAP-ENV:Body>
        <ns1:AddressSearchResponse xmlns:ns1="urn:ServiceQualification">
            <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:ServiceQualificationResponse[1]">
                <item xsi:type="tns:ServiceQualificationResponse">
                    <status_code xsi:type="xsd:string">1</status_code>
                    <property_id xsi:type="xsd:string">253323</property_id>
                    <unit_no xsi:type="xsd:string">Basement</unit_no>
                    <house_no xsi:type="xsd:string">8</house_no>
                    <lot_no xsi:type="xsd:string">3</lot_no>
                    <street_name xsi:type="xsd:string">Harbour</street_name>
                    <street_type xsi:type="xsd:string">Road</street_type>
                    <suburb xsi:type="xsd:string">Hamilton</suburb>
                    <state_name xsi:type="xsd:string">QLD</state_name>
                    <postcode xsi:type="xsd:string">4007</postcode>
                    <estate_name xsi:type="xsd:string">Hamilton Harbour</estate_name>
                    <stage xsi:type="xsd:string"></stage>
                    <property_class xsi:type="xsd:string">Class 3</property_class>
                </item>
            </return>
        </ns1:AddressSearchResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

$domDocument = new DOMDocument();
$domDocument->loadXML($string);
$carriers=array();
$results=$domDocument->getElementsByTagName("item");
foreach($results as $result)
{
    foreach($result->childNodes as $node)
    {
        if($node instanceof DOMElement)
        {
            array_push($carriers, $node->textContent);
        }
    }

}
print_r($carriers);

1.
253323
地下室
8.
3.
港湾
道路
汉密尔顿
昆士兰
4007
汉密尔顿港
第三类
我的代码有问题吗?我得到的结果是空的


谢谢你的帮助。谢谢。

这里我使用
DOMDocument
解析soap响应


您能分享响应字符串和预期输出吗?@SahilGulati我更新了我的帖子,并展示了一个响应示例。您可以使用DOMDocument进行此操作,您能告诉我您想要提取什么以便我可以帮助您吗?@SahilGulati非常感谢您的帮助。我想提取单元号、房屋号、地块号、街道名、街道类型、郊区中的值。因此,基本上所有值都在:)
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:ServiceQualification">
    <SOAP-ENV:Body>
        <ns1:AddressSearchResponse xmlns:ns1="urn:ServiceQualification">
            <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:ServiceQualificationResponse[1]">
                <item xsi:type="tns:ServiceQualificationResponse">
                    <status_code xsi:type="xsd:string">1</status_code>
                    <property_id xsi:type="xsd:string">253323</property_id>
                    <unit_no xsi:type="xsd:string">Basement</unit_no>
                    <house_no xsi:type="xsd:string">8</house_no>
                    <lot_no xsi:type="xsd:string">3</lot_no>
                    <street_name xsi:type="xsd:string">Harbour</street_name>
                    <street_type xsi:type="xsd:string">Road</street_type>
                    <suburb xsi:type="xsd:string">Hamilton</suburb>
                    <state_name xsi:type="xsd:string">QLD</state_name>
                    <postcode xsi:type="xsd:string">4007</postcode>
                    <estate_name xsi:type="xsd:string">Hamilton Harbour</estate_name>
                    <stage xsi:type="xsd:string"></stage>
                    <property_class xsi:type="xsd:string">Class 3</property_class>
                </item>
            </return>
        </ns1:AddressSearchResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<?php
ini_set('display_errors', 1);
$string='<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:ServiceQualification">
    <SOAP-ENV:Body>
        <ns1:AddressSearchResponse xmlns:ns1="urn:ServiceQualification">
            <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:ServiceQualificationResponse[1]">
                <item xsi:type="tns:ServiceQualificationResponse">
                    <status_code xsi:type="xsd:string">1</status_code>
                    <property_id xsi:type="xsd:string">253323</property_id>
                    <unit_no xsi:type="xsd:string">Basement</unit_no>
                    <house_no xsi:type="xsd:string">8</house_no>
                    <lot_no xsi:type="xsd:string">3</lot_no>
                    <street_name xsi:type="xsd:string">Harbour</street_name>
                    <street_type xsi:type="xsd:string">Road</street_type>
                    <suburb xsi:type="xsd:string">Hamilton</suburb>
                    <state_name xsi:type="xsd:string">QLD</state_name>
                    <postcode xsi:type="xsd:string">4007</postcode>
                    <estate_name xsi:type="xsd:string">Hamilton Harbour</estate_name>
                    <stage xsi:type="xsd:string"></stage>
                    <property_class xsi:type="xsd:string">Class 3</property_class>
                </item>
            </return>
        </ns1:AddressSearchResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

$domDocument = new DOMDocument();
$domDocument->loadXML($string);
$carriers=array();
$results=$domDocument->getElementsByTagName("item");
foreach($results as $result)
{
    foreach($result->childNodes as $node)
    {
        if($node instanceof DOMElement)
        {
            array_push($carriers, $node->textContent);
        }
    }

}
print_r($carriers);
Array
(
    [0] => 1
    [1] => 253323
    [2] => Basement
    [3] => 8
    [4] => 3
    [5] => Harbour
    [6] => Road
    [7] => Hamilton
    [8] => QLD
    [9] => 4007
    [10] => Hamilton Harbour
    [11] => 
    [12] => Class 3
)