1 / 54

Xpath

Xpath. XPath is a language for finding information in an XML document. training. http:// www.w3schools.com/xpath/xpath_intro.asp. Naviguer dans les documents XML avec XPath. Introduction Les axes Les filtres Les prédicats Les fonctions prédéfinies Syntaxe abrégée.

dexter-orr
Download Presentation

Xpath

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Xpath XPath is a language for finding information in an XML document.

  2. training • http://www.w3schools.com/xpath/xpath_intro.asp

  3. Naviguer dans les documents XML avec XPath • Introduction • Les axes • Les filtres • Les prédicats • Les fonctions prédéfinies • Syntaxe abrégée

  4. Naviguer dans les documents XML avec XPath • Introduction • Les axes • Les filtres • Les prédicats • Les fonctions prédéfinies • Syntaxe abrégée

  5. Introduction • Chaque document XML est une instance d'un arbre XML. XPath est un langage général d'adressage dans cet arbre XML.

  6. Remarques • Le nœud racine est unique et obligatoire • Il ne faut pas le confondre avec l'élément document, souvent appelé racine du document. • Cette distinction est justifiée par le fait que quatre types de nœuds différents peuvent être fils du nœud racine. • le nœud déclaration de domaine • les instructions de traitement • les commentaires • l'élément document qui est unique • Si les nœuds sont ordonnés, les attributs ne le sont pas, ainsi nous ne pourrons pas recherche le nième attributs.

  7. LocationPath • http://www.w3.org/TR/xpath#NT-LocationPath [1] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath [2] AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath • Un RelativeLocationPath sert à sélectionner un ensemble de noeuds basés sur leur position par rapport au noeud contextuel. • Un AbsoluteLocationPath sert à sélectionner un ensemble de noeuds basées sur leur position dans le document par rapport au noeud racine.

  8. Récursivité • http://www.w3.org/TR/xpath#NT-LocationPath [1] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath [2] AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath • Un RelativeLocationPath sert à sélectionner un ensemble de noeuds basés sur leur position par rapport au noeud contextuel. • Un AbsoluteLocationPath sert à sélectionner un ensemble de noeuds basées sur leur position dans le document par rapport au noeud racine.

  9. Exemple • /child::doc/child::chapter[position()=5]/ child::section[ position()=2] • selects the second section of the fifth chapter of the doc document element

  10. Exemple • child::para [position()=2][attribute::pe="warning"] • selects the second para child of the context node if that child has a type attribute with value warning

  11. Naviguer dans les documents XML avec XPath • Le langage d’adressage utilise des chemins pour désigner un ensemble d’objets • Une étape de localisation se fait en 3 temps : • un axe, est un chemin à travers l'arbre du document, débutant au nœud origine et suivant une relation particulière entre les nœuds. • un filtre, qui spécifie le type du noeud obtenus par l'étape de localisation • 0 ou n prédicats, qui sont des expressions arbitraires pour raffiner l'ensemble des noeuds

  12. Exemples • child::para[ position()=5][attribute::type="warning"] • selects the fifth para child of the context node if that child has a type attribute with value warning • Une étape de localisation se fait en 3 temps : • un axe, est un chemin à travers l'arbre du document, débutant au nœud origine et suivant une relation particulière entre les nœuds. • un filtre, qui spécifie le type du noeud obtenus par l'étape de localisation • 0 ou n prédicats, qui sont des expressions arbitraires pour raffiner l'ensemble des noeuds

  13. Naviguer dans les documents XML avec XPath • Introduction • Les axes • Les filtres • Les prédicats • Les fonctions prédéfinies • Syntaxe abrégée

  14. AxisName • Un AxisName est utilisé dans un Step pour identifier un chemin à suivre depuis un nœud donné vers les autres nœuds liés. • http://www.w3.org/TR/xpath#axes • AxisName ::= | 'ancestor' | 'ancestor-or-self' | 'attribute' | 'child' | 'descendant' | 'descendant-or-self' | 'following' | 'following-sibling' | 'namespace' | 'parent' | 'preceding' | 'preceding-sibling' | 'self'

  15. | 'ancestor'

  16. | 'ancestor' 2 1

  17. 'ancestor-or-self'

  18. 'ancestor-or-self' 3 2 1

  19. | 'child'

  20. | 'child' 1 2

  21. | 'descendant'

  22. | 'descendant' 1 2 3 4 5

  23. | 'descendant-or-self'

  24. | 'descendant-or-self' 1 2 3 4 5 6

  25. | 'following'

  26. | 'following' 4 1 2 3

  27. | 'following-sibling'

  28. | 'following-sibling' 2 1

  29. | 'parent'

  30. | 'parent' 1

  31. | 'preceding'

  32. | 'preceding' 3 2 1

  33. | 'preceding-sibling'

  34. | 'preceding-sibling' 1

  35. | 'self' 1

  36. AxisSpecifier • Un AxisSpecifier est soit un nom d'axe, soit une abréviation pour un nom d'axe. Il définit une direction de navigation à travers le document en définissant une liste ordonnée de nœuds qui peuvent être visités. • http://www.w3.org/TR/xpath#NT-AxisSpecifier • AxisSpecifier ::= AxisName '::' | AbbreviatedAxisSpecifier • http://www.w3.org/TR/xpath#NT-AbbreviatedAxisSpecifier • [13]   AbbreviatedAxisSpecifier   ::=   '@'?

  37. Exemple • ancestor:: • spécifie l'axe ancêtre • Preceding-sibling:: • Spécifie l'axe enfant précédent • @ • spécifie l'axe attribut

  38. Naviguer dans les documents XML avec XPath • Introduction • Les axes • Les filtres • Les prédicats • Les fonctions prédéfinies • Syntaxe abrégée

  39. Predicate • Un prédicat est une expression qualificative utilisée pour sélectionner un sous ensemble des noeuds d'une ensemble de noeuds ou de Step. • http://www.w3.org/TR/xpath#predicates • [8]   Predicate   ::=   '[' PredicateExpr ']' # noter les [] • [9]   PredicateExpr   ::=   Expr

  40. Exemple • Para[ 1] ou Para[ position()=1] • Le premier élément enfant <para> du noeud contextuel • para[ last()] • le dernier élément enfant du noeud contextuel.

  41. Naviguer dans les documents XML avec XPath (3) • Les axes:self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA>           <XXX>                <DDD>                     <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>                </DDD>           </XXX> <CCC>               <DDD>                     <BBB/>                     <BBB id=“b”/>                     <GGG/>                     <FFF/>                </DDD> </CCC> <CCC>               <BBB name=“bbb”>                     <BBB id=“bbb”>                          <BBB/>                     </BBB>                </BBB> </CCC></AAA> //CCC/self::*

  42. Naviguer dans les documents XML avec XPath (3) • Les axes: self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA>           <XXX>                <DDD>                     <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>                </DDD>           </XXX>           <CCC>                <DDD>                     <BBB/>                     <BBB id=“b”/>                     <GGG/>                     <FFF/>                </DDD>          </CCC>           <CCC> <BBB name=“bbb”>                    <BBB id=“bbb”>                          <BBB/>                     </BBB>  </BBB>          </CCC> </AAA> //CCC/child::*

  43. Naviguer dans les documents XML avec XPath (3) • Les axes: self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA>           <XXX>                <DDD>                     <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>                </DDD>           </XXX>           <CCC>                <DDD>                     <BBB/>                     <BBB id=“b”/>                     <GGG/>                     <FFF/>                </DDD>           </CCC>           <CCC>                <BBB name=“bbb”>                     <BBB id=“bbb”>                          <BBB/>                     </BBB>                </BBB>           </CCC> </AAA> //CCC/parent::*

  44. Naviguer dans les documents XML avec XPath (3) • Les axes: self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA>           <XXX>                <DDD> <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>               </DDD>           </XXX>           <CCC>                <DDD>  <BBB/>                     <BBB id=“b”/>                     <GGG/>                     <FFF/>                </DDD>           </CCC>           <CCC>                <BBB name=“bbb”>                     <BBB id=“bbb”>                          <BBB/>                     </BBB>                </BBB>           </CCC> </AAA> //DDD/descendant::*

  45. Naviguer dans les documents XML avec XPath (3) • Les axes: self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA>           <XXX>               <DDD>                     <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>                </DDD> </XXX>           <CCC>               <DDD>                     <BBB/>                     <BBB id=“b”/>                     <GGG/>                     <FFF/>                </DDD>           </CCC>           <CCC>                <BBB name=“bbb”>                     <BBB id=“bbb”>                          <BBB/>                     </BBB>                </BBB>           </CCC> </AAA> //DDD/ancestor::*

  46. Naviguer dans les documents XML avec XPath (3) • Les axes: self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA>           <XXX>                <DDD>                     <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>                </DDD>           </XXX>           <CCC>                <DDD>                     <BBB/>                     <BBB id=“b”/>                     <GGG/>                     <FFF/>                </DDD>           </CCC>           <CCC>                <BBB name=“bbb”>                     <BBB id=“bbb”>                          <BBB/>                     </BBB>                </BBB>           </CCC> </AAA> //GGG/preceding::*

  47. Naviguer dans les documents XML avec XPath (3) • Les axes: self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA> <XXX>                <DDD>                     <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>                </DDD>           </XXX>           <CCC>                <DDD>                     <BBB/>                     <BBB id=“b”/>                     <GGG/>                     <FFF/>                </DDD>           </CCC>           <CCC>                <BBB name=“bbb”>                     <BBB id=“bbb”>                          <BBB/>                     </BBB>                </BBB>           </CCC> </AAA> //GGG/preceding-sibling::*

  48. Naviguer dans les documents XML avec XPath (3) • Les axes: self, child, parent, descendant, descendant-or-self, ancestor, ancestor-or-self, preceding, preceding-sibling, following, following-sibling, attribute <AAA>           <XXX>                <DDD>                     <BBB/>                     <BBB/>                     <EEE/>                     <FFF/>                </DDD>           </XXX>           <CCC>                <DDD>                     <BBB/> <BBB id=“b”/>                    <GGG/>                     <FFF/>                </DDD>           </CCC>           <CCC>                <BBB name=“bbb”>                     <BBB id=“bbb”>                         <BBB/>                     </BBB>               </BBB>           </CCC> </AAA> //*[attribute::id]

  49. Naviguer dans les documents XML avec XPath • Introduction • Les axes • Les filtres • Les prédicats • Les fonctions prédéfinies • Syntaxe abrégée

  50. FilterExpr • FilterExpr est utilisé pour appliquer un ou plusieurs Predicates à un ensemble de noeuds, en sélectionnant un sous ensemble de ces noeuds satisfaisant certaines conditions. • http://www.w3.org/TR/xpath#NT-FilterExpr • [20]   FilterExpr   ::=   PrimaryExpr| FilterExprPredicate

More Related