我还没有将XML与PHP结合使用,但由于我在SOAP调用后收到了XML,所以我想我必须处理它。
好的。因此,我得到了以下内容:
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/jRecordBroadcastRowWS" xmlns:bcr="http://soap.sforce.com/schemas/class/jRecordUtils" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:body>
<queryrequestsresponse>
<result>
<bcr:customid>REQ16569</bcr:customid>
<bcr:externalid xsi:nil="true">
<bcr:recordid>a035700001CM60kAAD</bcr:recordid>
<bcr:requestid>a1J5700000857EYEAY</bcr:requestid>
</bcr:externalid>
</result>
<result>
<bcr:customid>SRQ100784</bcr:customid>
<bcr:externalid xsi:nil="true">
<bcr:recordid>a033E000001PxfAQAS</bcr:recordid>
<bcr:requestid>a1J3E0000000GSaUAM</bcr:requestid>
</bcr:externalid>
</result>
</queryrequestsresponse>
</soapenv:body>
</soapenv:envelope>所以我试着拿到recordid的。但是它并没有存储在recordid的
$xmlresponse = new SimpleXMLElement($response);
$recordid = $xmlresponse->children('soapenv', true)->Body->queryrequestsresponse->result->children('BCR', true)->externalid->recordid;
var_dump($recordid);只需确保(因为我使用BCR作为大写)以确保正确,我在检索getNamespaces()后执行了vardump,结果如下所示。
array(4) {
["soapenv"]=> string(41) "http://schemas.xmlsoap.org/soap/envelope/"
[""]=> string(58) "http://soap.sforce.com/schemas/class/jRecordBroadcastRowWS"
["BCR"]=> string(49) "http://soap.sforce.com/schemas/class/jRecordUtils"
["xsi"]=> string(41) "http://www.w3.org/2001/XMLSchema-instance"
}那么我该如何解析这些ID呢,我是不是把语法放错了?
发布于 2017-05-18 17:11:29
混合命名空间的SimpleXML很难实现。使用XPath更容易:
foreach ($xmlresponse->xpath('//bcr:recordid') as $sxe) {
echo (string) $sxe . "\n";
}输出:
a035700001CM60kAAD
a033E000001PxfAQAShttps://stackoverflow.com/questions/41593157
复制相似问题