Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and Xpath, filtering results based on greatgrandchildren
    text
    copied!<p>Consider the following test.xml</p> <pre><code>&lt;root&gt; &lt;parent&gt; &lt;ID&gt;1&lt;/ID&gt; &lt;child1&gt;Value1&lt;/child1&gt; &lt;child2&gt;value11&lt;/child2&gt; &lt;child3&gt; &lt;grandchild&gt; &lt;greatgrandchild&gt;value1111&lt;/greatgrandchild&gt; &lt;/grandchild&gt; &lt;/child3&gt; &lt;/parent&gt; &lt;parent&gt; &lt;ID&gt;2&lt;/ID&gt; &lt;child1&gt;value2&lt;/child1&gt; &lt;child3&gt; &lt;grandchild&gt; &lt;greatgrandchild&gt;value2222&lt;/greatgrandchild&gt; &lt;/grandchild&gt; &lt;/child3&gt; &lt;/parent&gt; &lt;parent&gt; &lt;ID&gt;3&lt;/ID&gt; &lt;child1&gt;value3&lt;/child1&gt; &lt;child2&gt;value33&lt;/child2&gt; &lt;child3&gt; &lt;grandchild&gt; &lt;greatgrandchild&gt;value3333&lt;/greatgrandchild&gt; &lt;/grandchild&gt; &lt;/child3&gt; &lt;/parent&gt; &lt;parent&gt; &lt;ID&gt;4&lt;/ID&gt; &lt;child1&gt;value4&lt;/child1&gt; &lt;child2&gt;value44&lt;/child2&gt; &lt;child3&gt; &lt;grandchild&gt; &lt;greatgrandchild&gt;value4444&lt;/greatgrandchild&gt; &lt;/grandchild&gt; &lt;/child3&gt; &lt;/parent&gt; &lt;/root&gt; </code></pre> <p>When I use the following for xpath '/root/parent', I can easily get the values of ID, child1, and child2. </p> <p>However I do not get the values of the greatgrandchild of grandchild.</p> <p>What can I do to get these values.</p> <pre><code>$query = '/root/parent' $xQuery = $xml-&gt;xpath($query); foreach($xQuery as $results){ echo $results-&gt;ID; echo $results-&gt;child1; echo $results-&gt;child2; echo $results-&gt;greatgrandchild; } </code></pre> <p>I would like to filter the result based on the value of greatgrandchild. I can successfully filter the results of ID and child1 and child2. I want to be getting a parent and all of its children and grandchildren and greatgrandchild based on the value of greatgrandchild.</p> <p>Is this possible using xpath? </p> <p>I have edited the wording of the question and used the proper test.xml as I had errors in it the first time around. </p>
 

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