<student> <exercises> <exercise id="" creation-day="28" creation-month="11" creation-year="02" mod-day="" mod-month="" mod-year="" mod-by="" version="" status="draft"> <staf no="14" ex-number=" 1a "/> <title>Home page personnelle</title> <url>http://tecfa.unige.ch/perso/staf/lattion/welcome.html</url> <description>créer sa homepage en xhtml</description> <report report-url="http://tecfa.unige.ch/staf/staf-i/lattion/staf14/ex1/comment.html"/> </exercise> ....... <exercises> <student>Below is the result generated by php for the following Xpath meaning get all exercise elements (nodes) whose staf child elements have the "no='14'" attribute:
//student/exercises/exercise/staf[@no='14']/.. alternative notation (not used here): "//student/exercises/exercise/staf[@no='14']/parent::*"To the resulting DOM node collection we apply the following Xpath
"title"Of course we also could have used an other DOM function to get at the contents of a simple element...
The source (simple-xpath2.phps or simple-xpath2.text is in this same directory. It is freeware :)
See simple-xpath3.php for still nicer looking output that will use XSLT to render the found fragments or go go back.