<legend id='ZVUf7'><style id='ZVUf7'><dir id='ZVUf7'><q id='ZVUf7'></q></dir></style></legend>
  • <small id='ZVUf7'></small><noframes id='ZVUf7'>

        <bdo id='ZVUf7'></bdo><ul id='ZVUf7'></ul>

        <i id='ZVUf7'><tr id='ZVUf7'><dt id='ZVUf7'><q id='ZVUf7'><span id='ZVUf7'><b id='ZVUf7'><form id='ZVUf7'><ins id='ZVUf7'></ins><ul id='ZVUf7'></ul><sub id='ZVUf7'></sub></form><legend id='ZVUf7'></legend><bdo id='ZVUf7'><pre id='ZVUf7'><center id='ZVUf7'></center></pre></bdo></b><th id='ZVUf7'></th></span></q></dt></tr></i><div id='ZVUf7'><tfoot id='ZVUf7'></tfoot><dl id='ZVUf7'><fieldset id='ZVUf7'></fieldset></dl></div>
        <tfoot id='ZVUf7'></tfoot>

      1. SimpleXML SOAP 响应命名空间问题

        时间:2024-05-11
          <legend id='pMv6F'><style id='pMv6F'><dir id='pMv6F'><q id='pMv6F'></q></dir></style></legend>
        1. <i id='pMv6F'><tr id='pMv6F'><dt id='pMv6F'><q id='pMv6F'><span id='pMv6F'><b id='pMv6F'><form id='pMv6F'><ins id='pMv6F'></ins><ul id='pMv6F'></ul><sub id='pMv6F'></sub></form><legend id='pMv6F'></legend><bdo id='pMv6F'><pre id='pMv6F'><center id='pMv6F'></center></pre></bdo></b><th id='pMv6F'></th></span></q></dt></tr></i><div id='pMv6F'><tfoot id='pMv6F'></tfoot><dl id='pMv6F'><fieldset id='pMv6F'></fieldset></dl></div>

              • <bdo id='pMv6F'></bdo><ul id='pMv6F'></ul>
                  <tbody id='pMv6F'></tbody>

                <tfoot id='pMv6F'></tfoot>

                <small id='pMv6F'></small><noframes id='pMv6F'>

                  本文介绍了SimpleXML SOAP 响应命名空间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在为此花费了几个令人沮丧的小时后,我正在寻求您的帮助.

                  我正在尝试从 SOAP 响应中获取特定节点的内容.

                  回应是

                  <?xml version="1.0" encoding="UTF-8"?><env:信封 xmlns:env="<a href="http://www.w3.org/2003/05/soap-envelope">http://www.w3.org/2003/05/肥皂信封</a>"<xmlns:ns1="<a href="http://soap.xxxxxx.co.uk/">http://soap.xxxxxx.co.uk/</a>"><env:身体><ns1:PlaceOrderResponse><xxxxxOrderNumber></xxxxxOrderNumber><错误数组><错误><错误代码>24</错误代码><ErrorText>+client+order+number+3002254+is+already+in+use</ErrorText></错误><错误><错误代码>1</错误代码><ErrorText>正在中止</ErrorText></错误></错误数组></ns1:PlaceOrderResponse></env:正文></env:信封>

                  我正在尝试获取 <ErrorArray> 的节点和子节点.由于 XML 包含命名空间

                  $XmlArray = new SimpleXMLElement($XmlStr);foreach ($XmlArray->env:Envelope->env:Body->ns1:PlaceOrderResponse->ErrorArray->Error as $Error){echo $Error->ErrorCode."<br/>";}

                  不起作用.我已经阅读了许多文章,例如

                  • http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/
                  • http://blog.stuartherbert.com/php/2007/01/07/using-simplexml-to-parse-rss-feeds/

                  还有关于这个网站的大约 20 个问题,很遗憾没有帮助.

                  即使写作,

                  $XmlArray = new SimpleXMLElement($XmlStr);echo "<br/><br/><pre>
                  ";print_r($XmlArray);echo "<pre><br/><br/>
                  ";

                  给予

                  SimpleXMLElement 对象()

                  这让我想知道肥皂响应 ($XmlStr) 是否实际上是 SimpleXMLElement 的有效输入.

                  好像是行

                  $XmlArray = new SimpleXMLElement($XmlStr);

                  没有按照我的预期去做.

                  非常欢迎任何有关如何从上述 XML 中获取节点的帮助.

                  显然,让它发挥作用(有一个有效的例子)是我在短期内需要的,但如果有人能帮助我理解我做错了什么,从长远来看会更好.

                  干杯.斯图

                  解决方案

                  你必须使用 SimpleXMLElement::children(),尽管此时使用 XPath 可能会更容易.

                  children("env", true)->Body->children("ns1", true)->PlaceOrderResponse->children()->ErrorArray->Error;foreach ($t as $error) {echo $error->ErrorCode, " " , $error->ErrorText, "<br/>";}

                  给予:

                  <上一页>24 The+client+order+number+3002254+is+already+in+use1 中止

                  After spending SEVERAL frustrated hours on this I am asking for your help.

                  I am trying to get the content of particular nodes from a SOAP response.

                  The response is

                  <?xml version="1.0" encoding="UTF-8"?>
                  <env:Envelope xmlns:env="<a href="http://www.w3.org/2003/05/soap-envelope">http://www.w3.org/2003/05/soap-envelope</a>"<xmlns:ns1="<a href="http://soap.xxxxxx.co.uk/">http://soap.xxxxxx.co.uk/</a>">
                      <env:Body>
                          <ns1:PlaceOrderResponse>
                              <xxxxxOrderNumber></xxxxxOrderNumber>
                              <ErrorArray>
                                  <Error>
                                      <ErrorCode>24</ErrorCode>
                                      <ErrorText>The+client+order+number+3002254+is+already+in+use</ErrorText>
                                  </Error>
                                  <Error>
                                      <ErrorCode>1</ErrorCode>
                                      <ErrorText>Aborting</ErrorText>
                                  </Error>
                              </ErrorArray>
                          </ns1:PlaceOrderResponse>
                      </env:Body>
                  </env:Envelope>
                  

                  I am trying to get at the nodes and children of <ErrorArray>. Because of the XML containing namespaces

                  $XmlArray   = new SimpleXMLElement($XmlStr);
                  
                  foreach ($XmlArray->env:Envelope->env:Body->ns1:PlaceOrderResponse->ErrorArray->Error as $Error)
                  {
                      echo $Error->ErrorCode."<br />";
                  }
                  

                  doesn't work. I have read a number of articles such as

                  • http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/
                  • http://blog.stuartherbert.com/php/2007/01/07/using-simplexml-to-parse-rss-feeds/

                  and about 20 questions on this site, which unfortunately are not helping.

                  Even writing,

                  $XmlArray   = new SimpleXMLElement($XmlStr);
                  
                  echo "<br /><br /><pre>
                  ";
                  print_r($XmlArray);
                  echo "<pre><br /><br />
                  ";
                  

                  gives

                  SimpleXMLElement Object
                  (
                  )
                  

                  which makes me wonder if the soap response ($XmlStr) is actually a valid input for SimpleXMLElement.

                  It seems that the line

                  $XmlArray   = new SimpleXMLElement($XmlStr);
                  

                  is not doing what I expect it to.

                  Any help on how to get the nodes from the XML above would be very welcome.

                  Obviously getting it to work (having a working example) is what I need in the short term, but if someone could help me understand what I am doing wrong would be better in the long term.

                  Cheers. Stu

                  解决方案

                  You have to use SimpleXMLElement::children(), though at this point it would probably be easier to use XPath.

                  <?php
                      $XmlStr = <<<XML
                  <?xml version="1.0" encoding="UTF-8"?>
                  <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"  xmlns:ns1="http://soap.xxxxxx.co.uk/" >
                      <env:Body>
                          <ns1:PlaceOrderResponse>
                              <xxxxxOrderNumber></xxxxxOrderNumber>
                              <ErrorArray>
                                  <Error>
                                      <ErrorCode>24</ErrorCode>
                                      <ErrorText>The+client+order+number+3002254+is+already+in+use</ErrorText>
                                  </Error>
                                  <Error>
                                      <ErrorCode>1</ErrorCode>
                                      <ErrorText>Aborting</ErrorText>
                                  </Error>
                              </ErrorArray>
                          </ns1:PlaceOrderResponse>
                      </env:Body>
                  </env:Envelope>
                  XML;
                  
                      $XmlArray   = new SimpleXMLElement($XmlStr);
                  
                      $t = $XmlArray->children("env", true)->Body->
                          children("ns1", true)->PlaceOrderResponse->
                          children()->ErrorArray->Error;
                      foreach ($t as $error) {
                          echo $error->ErrorCode, " " , $error->ErrorText, "<br />";
                      } 
                  

                  gives:

                  24 The+client+order+number+3002254+is+already+in+use
                  1 Aborting
                  

                  这篇关于SimpleXML SOAP 响应命名空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP 命名空间和内置类的问题,如何解决? 下一篇:如何使用 SimpleXML 解析包含自定义命名空间的 XML?

                  相关文章

                  <i id='MGOOj'><tr id='MGOOj'><dt id='MGOOj'><q id='MGOOj'><span id='MGOOj'><b id='MGOOj'><form id='MGOOj'><ins id='MGOOj'></ins><ul id='MGOOj'></ul><sub id='MGOOj'></sub></form><legend id='MGOOj'></legend><bdo id='MGOOj'><pre id='MGOOj'><center id='MGOOj'></center></pre></bdo></b><th id='MGOOj'></th></span></q></dt></tr></i><div id='MGOOj'><tfoot id='MGOOj'></tfoot><dl id='MGOOj'><fieldset id='MGOOj'></fieldset></dl></div>
                1. <tfoot id='MGOOj'></tfoot>

                    <small id='MGOOj'></small><noframes id='MGOOj'>

                    • <bdo id='MGOOj'></bdo><ul id='MGOOj'></ul>
                  1. <legend id='MGOOj'><style id='MGOOj'><dir id='MGOOj'><q id='MGOOj'></q></dir></style></legend>