XML : simplexml_load_string path to value

I get different XML strings via SOAP.

But it is very difficult for me to get the value from XML with PHP.

XML examples:

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

I would like to get the id.

I tried it like this:

  $xml_element = simplexml_load_string($responseContent);  $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_ID'][0];    

But most time I dont know how to get my value.

Is it possible to display a whole array or how do I get the path to the value?

No comments:

Post a Comment