2

I have a string like this:

<?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>
<rs:data>
   <z:row ows_MetaInfo='128;#' />
</rs:data>
</listitems>
</GetListItemsResult>
</GetListItemsResponse>
</soap:Body>
</soap:Envelope>

I would like to get the value 128.

I already tried simplexml_load_string which is empty.

How can I get this attribute?

Chetan Ameta
  • 7,696
  • 3
  • 29
  • 44
phpjssql
  • 471
  • 1
  • 4
  • 16
  • Namespace is important, see: http://stackoverflow.com/questions/595946/parse-xml-with-namespace-using-simplexml – Xavjer Nov 30 '15 at 08:58

1 Answers1

0

Namespace is important in soap response. Try below code:

<?php
$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>
                    <rs:data>
                        <z:row ows_MetaInfo=\'128;#\'/>
                    </rs:data>
                </listitems>
            </GetListItemsResult>
        </GetListItemsResponse>
    </soap:Body>
</soap:Envelope>';

$xml_element = simplexml_load_string($xml);
$name_spaces = $xml_element->getNamespaces(true);
$soap = $xml_element->children($name_spaces['soap'])
    ->Body
    ->children($name_spaces['rs'])
    ->GetListItemsResponse
    ->GetListItemsResult
    ->listitems
    ->{'rs:data'}
    ->{'z:row'}['ows_MetaInfo'][0];

echo (string) $soap;
?>
Chetan Ameta
  • 7,696
  • 3
  • 29
  • 44