Model Xpath 1.0 PDF Print E-mail
User Rating: / 0
PoorBest 
Thursday, 10 July 2008

0. XML example
The xml which serve mainly as an example for the rest of the course:
<? xml version = "1.0" encoding = "UTF-8"?>
<? xml-stylesheet type = "text / xsl" href = "xml-xpath.xslt"?>
<employes>
<employe Num="1">
<name> Smith </ name>
<firstname> Robert </ first name>
<sexe> M </ sex>
<service> Human resources </ service>
<tel> 0645 </ tel>
<! - Internal post ->
<date_arrivée> 03-04-2004 </ date_arrivée>
<! - Arriving in society ->
</ Employee>
<employe Num="2">
<name> Dupond </ name>
<firstname> Mauritius </ first name>
<sexe> M </ sex>
<service> Engineering </ service>
<tel> 0842 </ tel>
<date_arrivée> 02-07-2004 </ date_arrivée>
</ Employee>
<employe Num="3">
<name> Bertold </ name>
<firstname> Lucia </ first name>
<sexe> F </ sex>
<service> Human resources </ service>
<tel> 0675 </ tel>
<date_arrivée> 01-04-2005 </ date_arrivée>
</ Employee>
<employe Num="5">
<name> Faubert </ name>
<firstname> Jerome </ first name>
<sexe> M </ sex>
<service> Design </ service>
<tel> 0856 </ tel>
<date_arrivée> 30-11-2000 </ date_arrivée>
</ Employee>
<employe Num="6">
<name> Geraltt </ name>
<firstname> Jerome </ first name>
<sexe> M </ sex>
<service> Engineering </ service>
<tel> 0956 </ tel>
<date_arrivée> 23-11-2000 </ date_arrivée>
</ Employee>
</ employee>
I. Syntax and vocabulary of an expression Xpath 1.0
An expression Xpath is composed of three parts an axis, a test and a predicate.
     * A axis can move in the tree nodes xml: parents, son, ancestors etc. .....
       For example: Child, parent, ancestor, self ....
     * A test can identify the type of knot looking for: attribute, etc. ..... root it follows the axis and must be preceded by::.
       For example: parent:: *, child: how () etc. ....
     * A predicate: it will be studied in another way, it is a condition on nodes driven. It is framed by [].

II. The different types of knots in Xpath 1.0

     * Node parent: the type of knot that can contain it
     * Node son: the type of knot that you can find in this node
     * Xpath expression: expressions xpath for targeting this type of knot: test and / or axe
     * Text value: the value used in a display or a comparison

II-A. Root node (Root)
     * Node parent: none
     * Node son: element, comment, processing-instruction
     * Expression xpath: node () (test) / (axis)
     * Text value: all nodes contained texts that are its descendants

If we use the xml example, the value text is: DupontRobertMressources humaines06 4503-04-2004DupondMauriceMIngénierie08 4202-07-2004BertoldLucieFressources humaines06 7501-04-2005FaubertJeromeMConception08 5630-11-2000GeralttJeromeMingénierie09 5623-11-2000, little use.

The root node (root) is the highest hierarchical document is the crux "invisible" which contains all autres.Il must differentiate the root element (root), which is the single node (and therefore the first) type element that can have as son

II-B. Node element (Element)
     * Node parent: root, element
     * Node son: attribute, namespace, element, comment, text
     * Expression xpath: node () (test), * (test) (default except behind and namespace attribute)
     * Text value: all nodes contained texts that are its descendants

The type element nodes are the most obvious, the tags that provide a structure information. In the example we have: Employees, employee, name, gender, service, such date_arrivée.Le node employees is the root element (root)

II-C. Node text (text)
     * Node parent: Element
     * Node son: none
     * Expression xpath: node () (test), text () (test)
     * Text value: string contained
channels between the tags contained a xml are in fact also view as noeuds.Ici for example Dupont is the text node son of the first node element name.

II-D. Node attribute (attribute)

     * Node parent: Element
     * Node son: none
     * Expression xpath: @ *, attribute: * (+ axis test). The standard should allow node () but only limits the parser prevents général.C is therefore * above the axis which determines the type Search
     * Text value: string between the quote after =
<employe Num="1">
<name> Smith </ name>
<firstname> Robert </ first name>
<sexe> M </ sex>
<service> Human resources </ service>
<tel> 06 45 </ tel>
<! - Internal post ->
<date_arrivée> 03-04-2004 </ date_arrivée>
<! - Arriving in society ->
</ Employee>
  By the value of the text node attribute num node element employee is 1.
Do not forget that a single case of "name" attribute node is also autorisée.Attention to employment 'and'.

II-E. Node comment (how)
     * Node parent: element, root
     * Node son: none
     * Expression xpath node () (test), how () (test)
     * Text value: The channel between <- and ->

Even syntax for HTML, the comment is to "explain". Nevertheless Xpath allowing it to focus and therefore to use its content.
<employe Num="1">
<name> Smith </ name>
<firstname> Robert </ first name>
<sexe> M </ sex>
<service> Human resources </ service>
<tel> 06 45 </ tel>
<! - Internal post ->
<date_arrivée> 03-04-2004 </ date_arrivée>
<! - Arriving in society ->
</ Employee>
2 knots here how son type of knot used. the first with the value text: the second post internal: arrival in society
II-F. Node namespace (namespace)

     * Node parent: Element
     * Node son: none
     * Expression xpath: namespace: * (+ axis test). The standard should allow node () but only limits the parser prevents général.C is therefore * above the axis which determines the type sought
     * Text value: URI namespace which is associated with the prefix namespaceURI
The namespace can involve some node through their behalf expanded their URI to a particular treatment. Take for example a sheet xslt:
<? xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template Match="/">
<test>
<xsl:value-of Select="."> </ xsl: value-of>
</ Test>
</ Xsl: template>
</ xsl: stylesheet>
</ xsl: stylesheet>

namespace node is xmlns: xsl, its value text: http://www.w3.org/1999/XSL/Transform All nodes starting with xsl: (the name expanded) as indicated by xmlns: xsl will be associated with the URI, and in this case, if read by an XSLT processor will be considered as instructions rather than just text.

II-G. Node instruction processing (processing-instruction)
     * Node parent: Root
     * Node son: none
     * Expression xpath: node () (test), processing-instruction () (test)
     * Text value: what is contained between <? and?>

These nodes are instructions treatment processor. Example:
<? xml-stylesheet type = "text / xsl" href = "xml-xpath.xslt"?>

Who orders involve the xslt content with my fichier.xslt xml Treaty. Here, for example, the text is of value: xml-stylesheet type = "text / xsl" href = "xml-xpath.xslt"

<? xml version = "1.0" encoding ="......"?>
The header file can never be achieved by Xpath, it is out of the root node.

II-H. CDATA, except

Areas CDATA are not knots, but a zone of characters "protected". Any character of a zone type CDATA is treated as character data.
When the parser, it would pass above all signs <and> are replaced respectively by <and>. Finally at the treatment Xpath <[CDATA [and]]> are ignored

<? xml version = "1.0" encoding = "UTF-8"?>
<test> this is test <[CDATA [values <and>]]>. </ test>

Here the text value test (that of his node text) will be: this is test on the values <and>.
 
< Prev   Next >
School Joomla Templates and Joomla Tutorials