Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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 具有名称空间的SimpleXMLelement_Php_Xml - Fatal编程技术网

Php 具有名称空间的SimpleXMLelement

Php 具有名称空间的SimpleXMLelement,php,xml,Php,Xml,我还没有在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/sc

我还没有在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>
只需确保(因为我使用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呢?我是否把语法放错了?

SimpleXML和混合名称空间很难。使用XPath更容易:

foreach ($xmlresponse->xpath('//bcr:recordid') as $sxe) {
    echo (string) $sxe . "\n";
}
输出:

a035700001CM60kAAD
a033E000001PxfAQAS
a035700001CM60kAAD
a033E000001PxfAQAS