Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since no one followed my closevote, I think I can just as well put my own comments as an answer:</p> <p>First of all, SimpleXml can load URIs directly and it can do so with stream wrappers, so your three calls in the beginning can be shortened to (note that you are not using <code>$file</code> at all)</p> <pre><code>$merchantProductFeed = new SimpleXMLElement("compress.zlib://$url", null, TRUE); </code></pre> <p>To get the values you can either use the implicit SimpleXml API and drill down to the wanted elements (like shown multiple times elsewhere on the site):</p> <pre><code>foreach ($merchantProductFeed-&gt;merchant-&gt;prod as $prod) { echo $prod-&gt;cat-&gt;awCat , PHP_EOL; } </code></pre> <p>or you can use an XPath query to get at the wanted elements directly</p> <pre><code>$xml = new SimpleXMLElement("compress.zlib://$url", null, TRUE); foreach ($xml-&gt;xpath('/merchantProductFeed/merchant/prod/cat/awCat') as $awCat) { echo $awCat, PHP_EOL; } </code></pre> <p><a href="http://codepad.viper-7.com/IHPC6L" rel="nofollow noreferrer">Live Demo</a></p> <p>Note that fetching all <code>$awCat</code> elements from the source XML is rather pointless though, because all of them have "Bodycare &amp; Fitness" for value. Of course you can also mix XPath and the implict API and just fetch the prod elements and then drill down to the various children of them.</p> <p>Using XPath should be somewhat faster than iterating over the SimpleXmlElement object graph. Though it should be noted that the difference is in an neglectable area (read 0.000x vs 0.000y) for your feed. Still, if you plan to do more XML work, it pays off to familiarize yourself with XPath, because it's quite powerful. Think of it as SQL for XML.</p> <p>For additional examples see</p> <ul> <li><a href="https://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of-xml-file">A simple program to CRUD node and node values of xml file</a> and </li> <li><a href="http://us2.php.net/manual/en/simplexml.examples-basic.php" rel="nofollow noreferrer">PHP Manual - SimpleXml Basic Examples</a></li> </ul>
    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.
    3. 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