简体   繁体   中英

PHP SOAP response in XML - how to read it as variable

I get response from SOAP WSDL call:

$client = new SoapClient($settings['address']);
$params = new stdClass();
$params->Username = $settings['username'];
$params->Password = $settings['password'];
var_dump($client->Get_Brands($params));

Below is response. How to actually read it in PHP? Do I need to traverse it with DOMDocument or is there something like returning SOAP result into object or array?

<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table" msdata:UseCurrentLocale="true">
        <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="Table">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="ID" type="xs:decimal" minOccurs="0"/>
                            <xs:element name="Description" type="xs:string" minOccurs="0"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    <DocumentElement xmlns="">
        <Table diffgr:id="Table1" msdata:rowOrder="0">
            <ID>1</ID>
            <Description>Alfa Romeo</Description>
        </Table>

        <Table diffgr:id="Table2" msdata:rowOrder="1">
            <ID>2</ID>
            <Description>Alpina</Description>
        </Table>
    </DocumentElement>
</diffgr:diffgram>

You should pass valid WSDL definition as first argument of SoapClient(). You may also set some specific options as second argument (for example soap_version). Normally there is no need to parse SOAP response - you should get method result of certain type. However if SOAP response in not valid SoapClient can't recognize and parse it automatically, you may need to parse it manually using DOMDocument or SimpleXML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM