我正在使用下一个结构废弃XML字符串:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<GetListItemsResult>
<listitems xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:z="#RowsetSchema">
<rs:data ItemCount="13">
<z:row ows_ContentTypeId="0x0100FAE5914930320F40A297829F2BA48F13" ows_Title="one record" ows_LinkTitleNoMenu="qqq" ows_LinkTitle="qqq2" />
<z:row ows_ContentTypeId="0x0100FAE5914930320F40A297829F2BA48F13" ows_Title="two record" ows_LinkTitleNoMenu="www" ows_LinkTitle="www2" />
<z:row ows_ContentTypeId="0x0100FAE5914930320F40A297829F2BA48F13" ows_Title="other record" ows_LinkTitleNoMenu="ddd" ows_LinkTitle="ddd3" />
</rs:data>
</listitems>
</GetListItemsResult>
</GetListItemsResponse>
</soap:Body>
</soap:Envelope>
该XML是cURL调用的结果。
所以,我的PHP代码是:
$crawler = new Crawler( $xml_response );
$first = $crawler->filterXPath('//soap:Envelope/soap:Body');
$cr2 = new Crawler( $first->html() );
$second = $cr2->filter('GetListItemsResponse > GetListItemsResult > listitems');
$cr3 = new Crawler( $second->html() );
$third = $cr3->filter('data');
$cr4 = new Crawler( $third->html() );
$fourth = $cr4->filter('row');
然后,我要进行调试:
echo 'Items :: ' . $fourth->count(); // "Items :: 13"
现在,我迭代$ fourth var,因为它包含13个元素
$fourth->each(function(Crawler $row, $i)
{
echo $i . PHP_EOL; // 0
echo strlen($row->html()) // 0
die; // die for debug
});
在$ row-> html()中,我希望此XML字符串代替一个空字符串:
<row ows_ContentTypeId="0x0100FAE5914930320F40A297829F2BA48F13" ows_Title="one record" ows_LinkTitleNoMenu="qqq" ows_LinkTitle="qqq2"/></row>