PHP and Xpath, filtering results based on greatgrandchildren

NickHart

New Member
Consider the following test.xml\[code\]<root> <parent> <ID>1</ID> <child1>Value1</child1> <child2>value11</child2> <child3> <grandchild> <greatgrandchild>value1111</greatgrandchild> </grandchild> </child3> </parent> <parent> <ID>2</ID> <child1>value2</child1> <child3> <grandchild> <greatgrandchild>value2222</greatgrandchild> </grandchild> </child3> </parent> <parent> <ID>3</ID> <child1>value3</child1> <child2>value33</child2> <child3> <grandchild> <greatgrandchild>value3333</greatgrandchild> </grandchild> </child3> </parent> <parent> <ID>4</ID> <child1>value4</child1> <child2>value44</child2> <child3> <grandchild> <greatgrandchild>value4444</greatgrandchild> </grandchild> </child3> </parent></root>\[/code\]When I use the following for xpath '/root/parent', I can easily get the values of ID, child1, and child2. However I do not get the values of the greatgrandchild of grandchild.What can I do to get these values.\[code\]$query = '/root/parent'$xQuery = $xml->xpath($query);foreach($xQuery as $results){ echo $results->ID; echo $results->child1; echo $results->child2; echo $results->greatgrandchild;}\[/code\]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.Is this possible using xpath? I have edited the wording of the question and used the proper test.xml as I had errors in it the first time around.
 
Back
Top