Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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 simplexml\u加载\u值的字符串路径_Php_Xml_Soap - Fatal编程技术网

Php simplexml\u加载\u值的字符串路径

Php simplexml\u加载\u值的字符串路径,php,xml,soap,Php,Xml,Soap,我通过SOAP获得不同的XML字符串 但是对于我来说,用PHP从XML中获取值是非常困难的 XML示例: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.

我通过SOAP获得不同的XML字符串

但是对于我来说,用PHP从XML中获取值是非常困难的

XML示例:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <GetUserInfoResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/">
        <GetUserInfoResult>
            <GetUserInfo>
                <User ID="23" />
            </GetUserInfo>
        </GetUserInfoResult>
    </GetUserInfoResponse>
</soap:Body>
</soap:Envelope>


<?xml version = "1.0" encoding = "utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
            <GetListItemsResult>
                <listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
     xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
     xmlns:rs='urn:schemas-microsoft-com:rowset'
     xmlns:z='#RowsetSchema'>
                    <rs:data>
                        <z:row ows_ID="128" />
                    </rs:data>
                </listitems>
            </GetListItemsResult>
        </GetListItemsResponse>
    </soap:Body>
</soap:Envelope>
但大多数时候我不知道如何获得我的价值


是否可以显示整个数组或如何获取值的路径?

要获取“ows_ID”的值,可以使用
simplexmlement
方法并为子元素添加名称空间

您可以使用该方法获取“ows_ID”的值

例如:

$responseContent = <<<XML
<?xml version = "1.0" encoding = "utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
            <GetListItemsResult>
                <listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
     xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
     xmlns:rs='urn:schemas-microsoft-com:rowset'
     xmlns:z='#RowsetSchema'>
                    <rs:data>
                        <z:row ows_ID="128" />
                    </rs:data>
                </listitems>
            </GetListItemsResult>
        </GetListItemsResponse>
    </soap:Body>
</soap:Envelope>
XML;

$xml_element = simplexml_load_string($responseContent);
$name_spaces = $xml_element->getNamespaces(true);

$rows = $xml_element
    ->children($name_spaces['soap'])
    ->Body
    ->children()
    ->GetListItemsResponse
    ->GetListItemsResult
    ->listitems
    ->children($name_spaces['rs'])
    ->children($name_spaces['z']);

foreach ($rows as $row) {
    $ows_ID =  $row->attributes()->ows_ID;
}

$responseContent=要获取“ows_ID”的值,可以使用
simplexmlement
方法,还可以为子元素添加名称空间

您可以使用该方法获取“ows_ID”的值

例如:

$responseContent = <<<XML
<?xml version = "1.0" encoding = "utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
            <GetListItemsResult>
                <listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
     xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
     xmlns:rs='urn:schemas-microsoft-com:rowset'
     xmlns:z='#RowsetSchema'>
                    <rs:data>
                        <z:row ows_ID="128" />
                    </rs:data>
                </listitems>
            </GetListItemsResult>
        </GetListItemsResponse>
    </soap:Body>
</soap:Envelope>
XML;

$xml_element = simplexml_load_string($responseContent);
$name_spaces = $xml_element->getNamespaces(true);

$rows = $xml_element
    ->children($name_spaces['soap'])
    ->Body
    ->children()
    ->GetListItemsResponse
    ->GetListItemsResult
    ->listitems
    ->children($name_spaces['rs'])
    ->children($name_spaces['z']);

foreach ($rows as $row) {
    $ows_ID =  $row->attributes()->ows_ID;
}
$responseContent=