简体   繁体   English

Nusoap:用namespase解析XML得到错误

[英]Nusoap: parseing XML with namespase getting error

I am using NuSoap for webservice. 我正在使用NuSoap进行webservice。 In response i am getting xml with namespace something like : 作为回应我得到xml与名称空间类似:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" s:mustUnderstand="1">ABC.CS.Ia.Cts.Ees.Au/IAuth/A</Action>
  </s:Header>
  <s:Body>
    <A xmlns="ABC.CS.Ia.Cts.Ees.Au">
      <Au xmlns:d1="ABC.CS.Ia.Cts.Ees.Au" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d1:Res>Q1</d1:Res>
        <d1:n>jFn</d1:n>
      </Au>
    </A>
  </s:Body>
</s:Envelope>

$xml_feed = simplexml_load_string($xmlString); $ xml_feed = simplexml_load_string($ xmlString);

Now i want to parse it. 现在我想解析它。 I have used simplexml_load_string function but getting warning and nothing returned by the function. 我使用了simplexml_load_string函数,但是获得了警告,函数没有返回任何内容。

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 7: parser warning : xmlns: URI BC.CS.Ia.Cts.Ees.Au is not absolute in C:\\xampp\\htdocs\\test.php on line 38 Warning: simplexml_load_string() [function.simplexml-load-string]: in C:\\xampp\\htdocs\\test.php on line 38 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\\xampp\\htdocs\\test.php on line 38 警告:simplexml_load_string()[function.simplexml-load-string]:实体:第7行:解析器警告:xmlns:URI BC.CS.Ia.Cts.Ees.Au在C:\\ xampp \\ htdocs \\ test中不是绝对的。第38行的php警告:simplexml_load_string()[function.simplexml-load-string]:第38行的C:\\ xampp \\ htdocs \\ test.php警告:simplexml_load_string()[function.simplexml-load-string]:^ in第38行的C:\\ xampp \\ htdocs \\ test.php

Please help me if any one have know.. 如果有人知道,请帮助我..

-itin -itin

Looks like you aren't accessing the XML objects correctly this function will correctly retrieve xpath child items: 看起来您没有正确访问XML对象,此函数将正确检索xpath子项:

function parseSOAPXmlTest($str) {
  //parse xml      
  $xml = simplexml_load_string($str);
  echo "xml=" . print_r($xml, true);  

  if( $xml === false ) { throw new Exception("OBJ is malformed!"); }
  foreach($xml->xpath('//s:Header') as $header) {
     if( empty($header) ) { throw new Exception("Header is malformed or missing!"); }
     echo "header=" . print_r($header, true);  
  }      

  foreach($xml->xpath('//s:Body') as $body) {

     if( empty($body) ) { throw new Exception("Body is malformed or missing!"); }
     echo "body=" . print_r($body, true);  
     foreach($body->A->Au->xpath('//d1:Res') as $Reschild) {
        echo "Reschild=" . print_r($Reschild, true);  
     }
     foreach($body->A->Au->xpath('//d1:n') as $nchild) {
        echo "nchild=" . print_r($nchild, true);  
     }
  }

} }

SimpleXML can't parse when a soap enveloppe is present. 当soap enveloppe存在时,SimpleXML无法解析。

See below: 见下文:

PHP - SimpleXML not returning object PHP - SimpleXML没有返回对象

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

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