0

I have xml data as

        <ns:PartyIDs>
          <ns:ID schemeName="PartyTypeNumber">009</ns:ID>
          <ns:ID schemeName="PartyNumber">00038</ns:ID>
          <ns:ID schemeName="PartySubNumber">00038</ns:ID>
        </ns:PartyIDs>

i need to read this and print the attributes and value. Using PHP.

right now i am trying usin DOMDocument

 $soap_do = curl_init(); 
curl_setopt($soap_do, CURLOPT_URL,            $url ); 
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT,        10); 
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($soap_do, CURLOPT_POST,           true ); 
curl_setopt($soap_do, CURLOPT_POSTFIELDS,    $domObject->saveXML()); 
curl_setopt($soap_do, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($domObject->saveXML()) )); 

 $response = curl_exec($soap_do);  
    $xml = new SimpleXMLElement($response);   //file from response
     $fileName="Response".date("Ymd_H_i_s");
      $xml->saveXML($fileName);

 $doc = new DOMDocument();
 $doc->load($fileName);//loading response file  
Santy
  • 3
  • 1
  • You should ask a question? what is going wrong? what have you tried? – Clayton Wilkinson Sep 10 '15 at 05:25
  • You should look into XPath for processing data in DOMDocument by certain node names. See here for inspiration: http://stackoverflow.com/questions/230592/xpath-query-with-php – Dan Belden Sep 10 '15 at 05:41
  • when i try using $PartyIDs=$doc->getElementsByTagName('ns:PartyIDs'); $id=$PartyIDs->item(0); echo $id->nodeValue; it gives me error saying Trying to get property of non-object – Santy Sep 10 '15 at 05:42
  • Hello Dan how to do the same with XPath when tags are with names space like – Santy Sep 10 '15 at 05:52

1 Answers1

0

Use $doc->getElementsByTagNameNS() instead.

See the manual for details: http://php.net/DOMDocument.getElementsByTagNameNS

You'll need to provide the $namespaceUri parameter which should have been specified in the root element of the XML file as xmlns:ns="http://...".

Steven Hilder
  • 222
  • 2
  • 6