Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could try use <a href="http://www.w3schools.com/xpath/" rel="nofollow noreferrer">xpath</a> instead of your nested loops method..</p> <p>Running the query </p> <pre><code>gallerylisting//folder[@subfolder="yes"]/text() </code></pre> <p>on your xml doc given above using <a href="http://www.xmlme.com/XpathTool.aspx" rel="nofollow noreferrer">this xpath tester</a> gives the results Events and Beach_Clean_2010, which is what I think you want. The query will find all folder elements under the root node gallerylisting, and if they have a subfolder attribute equal to "yes", the text in the node will be returned. </p> <p>So, in PHP, we have</p> <pre><code>&lt;?php $xmldoc = new DOMDocument(); $xmldoc-&gt;load('gallerylisting.xml'); $xpathvar = new Domxpath($xmldoc); $queryResult = $xpathvar-&gt;query('gallerylisting//folder[@subfolder="yes"]/text()'); foreach($queryResult as $result){ echo $result-&gt;textContent; } ?&gt; </code></pre> <p>Im not a PHP guy, so I am trusting the code in <a href="https://stackoverflow.com/questions/230592/xpath-query-with-php">this StackOverflow question</a> works. One thing to be aware of is that using the //name in xpath means find all nodes descended from the current position that match the name. This can be very slow on large documents. </p> <p>It seems there is multiple ways to process xpath with PHP. An example from <a href="http://www.w3schools.com/php/func_simplexml_xpath.asp" rel="nofollow noreferrer">this page</a> does the query like so: <pre><code> $result = $xml-&gt;xpath("gallerylisting//folder[@subfolder="yes"]/text()"); print_r($result); ?&gt; </code></pre>
 

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