Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is it? –w3c standard for… Navigating through an XML document Filtering & finding information –Includes… Expressions for navigating to parts of an.

Similar presentations


Presentation on theme: "What is it? –w3c standard for… Navigating through an XML document Filtering & finding information –Includes… Expressions for navigating to parts of an."— Presentation transcript:

1

2 What is it? –w3c standard for… Navigating through an XML document Filtering & finding information –Includes… Expressions for navigating to parts of an XML document The standard includes functions (e.g. for string & date manipulation)‏ Also used in XSLT for xml transformation

3 What are they? (or sets of nodes) from an XML document –They consist of… A path to the nodes/node sets A predicate (optional)‏ Syntax –Without a predicate: Nodenames, separated by a forward slash (/)‏ –Predicates: Predicates are placed inside [ ]

4 P283746 Anabela Domingues P 2004 M928493 Ann Devon U 2002... student.xml Root nodeChild of root node Children of student

5 What would be the path expression to navigate to the startYear node? What would be the path expression to select the startYear node where the startYear = 2002? ‘/students/student/startYear’ ‘/students/student/startYear[. = “2002”]’ --- OR --- ‘/students/student[startYear = “2002”]/startYear’ www.w3schools.com/xpath/xpath_intro.asp has more details on & examples of path expressions

6  What would be the path expression to select student nodes where the startYear = 2002 and the studyTypeIdD= U? '/students/student[startYear=2003][studyTypeID = "U"]' www.w3schools.com/xpath/xpath_intro.asp has more details on & examples of path expressions

7 The aim of the example used in the following slides is to list data in a XHTML table for all students who started at University in 2002 e.g. Fiona Murray M828827 … … Ann Devon M928493 Name Student Code

8 Steps involved in this example: 1.Create an instance of a simpleXML class by loading the XML file 2.Construct the query expression 3.Call the XPath method to execute the query 4.Loop through the result set

9 // Create a new simplexml instance loading xml file $studentsXML = simplexml_load_file('student.xml'); // Construct an XPath expression, // including a predicate in this instance. $qry = '/students/student[startYear = "2002"] '; // call the simplexml xpath method $students = $studentsXML->xpath($qry);

10 // iterate through the students returned by the xpath query foreach ($students as $student) { } echo " {$student->studentCode} \n"; echo " {$student->forename} "; echo "{$student->surname} \n"; echo " \n"; echo " {$student->studentCode} \n"; echo " {$student->forename} "; echo "{$student->surname} \n"; echo " \n"; echo " Student Code Name \n"; echo " \n";

11  XPath is a w3c standard for  Navigating through an XML document  Filtering & finding information  Path expressions navigate to a particular node or node-set and they may include predicates

12 http://www.zvon.org/xxl/XPathTutorial/General/examples.html - Xpath tutorial http://www.rpbourret.com/xml/XPathIn5.htm - XPath in 5 paragraphs! http://www.w3schools.com/xpath/ - w3schools XPath tutorial & reference *


Download ppt "What is it? –w3c standard for… Navigating through an XML document Filtering & finding information –Includes… Expressions for navigating to parts of an."

Similar presentations


Ads by Google