如何解析此 SOAP 响应


How can I parse this SOAP response

我得到带有PHP CURL的SOAP响应,如下所示

<?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/">
    <SOAP-ENV:Body>
        <ns1:GetRTResponse
            xmlns:ns1="http://advtest.forexpros.com/">
            <GetRTResponse xsi:type="xsd:ArrayOfString">
                <root>
                    <symbol id="53085" lastTimeStamp="1419026361">
                        <data symbol="53085" ask='11474.6' bid='11392.8' other='11433.7' date="12/19/2014 21:59:21.000" change='518.0' changep='4.75' tick="none" />
                    </symbol>
                </root>
            </GetRTResponse>
        </ns1:GetRTResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如何使用 PHP 从数据中解析bid属性?为什么var_dump退货string(679)""

在PHP中,有几种方法,使用SimpleXML或创建DOMDocument,尝试XPath或使用XSLT样式表或简单的字符串匹配或preg匹配文件...最后 2 种可能性是最糟糕的...我认为"string(679("说,这个XML是一个长度为679的字符串。

为什么不使用原生 PHP 类 SoapClient 来触发请求,然后接收数组或 stdClass 作为响应?例如,您可以使用PackageGenerator创建一个PHP包,该包将简化您发送请求的方式,而无需处理XML请求,因为您将拥有一个PHP对象。