Obtain parentnode with a xpath query on cakephp
So, i'm using Cakephp an开发者_如何学Cd I have a xml file that looks something like this:
<something>
<table id="t1">
<columns>
<column id="c1"/>
<column id="c2"/>
</columns>
</table>
<table id="t2">
<columns>
......
</something>
I was using Set::extract to search for the column based on it's id, no problems with that one:
Set::extract("/something/table/columns/column[id=$column_id"]", $array);
Now i need to get the parent table of that column. I tried with Set and SimpleXMLElement, but to no avail.
Can someone help me? thanks
Use:
Set::extract("/something/table[columns/column[id=$column_id"]]", $array);
The XPath expression:
/something/table[columns/column[id=$column_id"]]
selects all table
elements that are children of the top element something
and that have a columns/column
grand-child element the string value of whose id
child is equal to the string value of the variable $column_id
.
精彩评论