Good day everyone ! i am not too good at xpathing, but created an xml structure of this sort:
<Pages> <!--This is the root node--> <Home> <description>This is my site</description> <url>views/home/home.php</url> <menu> <item>Help</item> <item>About</item> <item>Contact</item> </menu> </Home> <Help> <!--i need to select this if its listed in Home/menu/item above--> ... some stuffy child nodes ... </Help> <About> <!--And Or select this if its listed in Home/menu/item above--> ... some stuffy child nodes ... </About> <Contact> <!--And Or select this if its listed in Home/menu/item above--> ... some stuffy child nodes ... </Contact> </Pages>
i've been dieing with an xpath expression that selects Home (excluding its menu child; if possible) and any other page (say About and/or Contact) which is listed in Home/menu/*; that is, any sibling of Home that is enlisted (itemised) in Home's menu child. currently, here is what i can think :
$SimpleObj = new XMLManager('thefile.xml') //my custom class that creates and manages xml DOM $SimpleObj->Xpath("Pages/*[name() = 'Home' and ./name() != 'menu'] | Pages/*[name() = ./menu/item[./text()] ] ");
the above expression proved abbortive. what sin have i commited ? or am i asking for something impossible ? any guide will be greately appreciated. thanks !
One possible XPath :
/Pages/*[self::Home or name()=preceding-sibling::Home/menu/item]
The above XPath selects all child element of
Pagesif it is a
<Home>element*, or it is an element having name equals one of the
*) You can't exclude any element from a parent element using XPath since
Homeelement along with it's content is one unit. XPath returns unit(s) of the source XML as it is.