vendredi 7 juin 2019

DomCrawler count() method returns 13 but html() returns empty string

I'm scrapping an XML string with the next structure:

<?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>

That XML is result of a cURL call.

So, my PHP code is:


$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');

Then, for debug I do:

echo 'Items :: ' . $fourth->count(); // "Items :: 13"

Now, I iterate $fourth var because contains 13 elements

$fourth->each(function(Crawler $row, $i)
{
    echo $i . PHP_EOL; // 0
    echo strlen($row->html()) // 0

    die; // die for debug

});

In the $row->html() I expect this XML String instead an empty string:

<row ows_ContentTypeId="0x0100FAE5914930320F40A297829F2BA48F13" ows_Title="one record" ows_LinkTitleNoMenu="qqq" ows_LinkTitle="qqq2"/></row>



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2EWI1py
via IFTTT

Aucun commentaire:

Enregistrer un commentaire