Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Could you clarify which version of PHP you're using (4 or 5)? Also is there a particular reason why you don't want to/can't use PHP 5's SOAP extension? Knowing this information should help us to give you a better answer. </p> <p>The reason the code sample above isn't working is that you're looking in the wrong namespace for the oproduct nodes. While the root node is contained in the SOAP namespace the oproduct ones are under the "http://v3.core.com.productserve.com/" namespace. You also need to use the namespace alias in the XPath query. Try this, although I haven't tested it:</p> <pre><code>$xml = simplexml_load_string($response); $xml-&gt;registerXPathNamespace('ns', 'http://v3.core.com.productserve.com/'); foreach ($xml-&gt;xpath('//ns:oproduct') as $item) { // do something } </code></pre> <p>Hopefully that will solve your immediate problem.</p> <p><strong>EDIT</strong> Thanks for the clarification. Again, untested but maybe this would work:</p> <pre><code>$xml = simplexml_load_string($response); $xml-&gt;registerXPathNamespace('soapenv', 'http://schemas.xmlsoap.org/soap/envelope/'); $xml-&gt;registerXPathNamespace('ns', 'http://v3.core.com.productserve.com/'); foreach ($xml-&gt;xpath('/soapenv:envelope/soapenv:body/ns:getproductlistresponse/ns:oproduct') as $item) { // do something } </code></pre> <p>Perhaps you need to go from the root node to the soap-Env:body to the oproduct nodes in the query. Hopefully that will work.</p> <p><strong>Further edit:</strong> I think I've just cracked this. Try the following code:</p> <pre><code>$xml = simplexml_load_string($response); $ns = $xml-&gt;getNamespaces(true); $soap = $xml-&gt;children($ns['soap-env']); $getproductlistresponse = $soap-&gt;body-&gt;children($ns['ns1']); foreach ($getproductlistresponse-&gt;children() as $item) { //This example just accesses the iid node but the others are all available. echo (string) $item-&gt;iid . '&lt;br /&gt;'; } </code></pre> <p>Not the prettiest code but it works. I was hoping to get this to work with an XPath query but it was beyond my rudimentary knowledge of XPath. Perhaps someone else can post an answer using XPath?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload