简体   繁体   English

使用php读取命名空间xml数据

[英]reading namespace xml data using php

I have xml data as 我有xml数据

        <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. 使用PHP。

right now i am trying usin DOMDocument 现在我正在尝试使用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  

Use $doc->getElementsByTagNameNS() instead. 使用$doc->getElementsByTagNameNS()代替。

See the manual for details: http://php.net/DOMDocument.getElementsByTagNameNS 有关详细信息,请参见手册: 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://..." . 您需要提供$namespaceUri参数,该参数应在XML文件的根元素中指定为xmlns:ns="http://..."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM