XPath - PowerPoint PPT Presentation

About This Presentation
Title:

XPath

Description:

Select all attributes named aa' //_at_aa. Select all CITIES elements with an attribute named aa ... attribute: Contains all attributes of the current node //BBB ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 16
Provided by: Yan174
Learn more at: https://www.cse.unt.edu
Category:
Tags: attribute | xpath

less

Transcript and Presenter's Notes

Title: XPath


1
XPath
2
XPath
  • Used to access part of XML document
  • Compact, non-XML syntax
  • Use a pattern expression to identify nodes in an
    XML document
  • Have a library of standard functions
  • W3C Standard

3
XPath Example
  • Sample XML
  • The root element
  • /STATES
  • The SCODE of all STATE elements of STATES element
  • /STATES/STATE/SCODE
  • All the CAPTIAL element with a CNAME sub-element
    of the STATE element of the STATES element
  • /STATES/STATE/CAPITALCNAMEAtlanta
  • All CITIES elements in the XML document
  • //CITIES

4
More XPath Example
  • Element AA with two ancestors
  • ///AA
  • First BB element of AA element
  • /AA/BB1
  • All the CC elements of the BB elements which has
    an sub-element A with value 3
  • /BBA3/CC
  • Any elements AA or elements CC of elements BB
  • //AA /BB/CC

5
Even More XPath Example
  • Select all sub-elements of elements BB of
    elements AA
  • /BB/AA/
  • When you do not know the sub-elements
  • Different from /BB/AA
  • Select all attributes named aa
  • //_at_aa
  • Select all CITIES elements with an attribute
    named aa
  • //CITIES_at_aa
  • Select all CITIES elements with an attribute
    named aa with value 123
  • //CITIES_at_aa 123

6
Axis
  • Context node
  • Evaluation of XPath is from left to right
  • The context node the current node (set) being
    evaluated
  • Axis
  • Specifies the relationship of the resulting
    nodes relative to context node
  • Example
  • /childAA children of AA, abbreviated by /AA
  • //AA/ancestorBB BB elements who are ancestor
    of any AA elements

7
Axes
  • ancestor //BBB/ancestor
  •  ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           ltCCC/gt   lt/AAAgt

8
Axes
  • ancestor //BBB/ancestorDDD
  •  ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           ltCCC/gt   lt/AAAgt

9
Axes
  • attribute Contains all attributes of the current
    node
  • //BBB/attribute abbreviated by //_at_
  • ltAAAgt           ltBBB aa1/gt           ltCCC/gt
              ltBBB aa2 /gt           ltBBB aa3
    /gt           ltDDDgt                ltBBB bb31
    /gt           lt/DDDgt           ltCCC/gt   lt/AAAgt
  • //BBB/attributebb

10
Axes
  • child
  • /AAA/DDD/childBBB child can be omitted for
    abbreviation
  •  ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           ltCCC/gt   lt/AAAgt

11
Axes
  • descendant
  • /AAA/descendent
  • ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           ltCCC/gt   lt/AAAgt
  • /AAA/descendentCCC ?

12
Axes
  • parent
  • //BBB/parent
  • ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           lt CCC/gt   lt/AAAgt
  • //BBB/parentDDD ?

13
Axes
  • descendant-or-self
  • following
  • following-sibling
  • preceding
  • preceding-sibling
  • self

14
Predicates
  • Filters a element set
  • A predicate is placed inside square brackets (
    )
  • Example //BBBposition() mod 2 0
  •    ltAAAgt           ltBBB/gt           ltBBB/gt
              ltBBB/gt           ltBBB/gt
              ltBBB/gt           ltBBB/gt
              ltBBB/gt           ltBBB/gt
              ltCCC/gt           ltCCC/gt
              ltCCC/gt      lt/AAAgt

15
Predicates
  • //BBB_at_aa31
  • ltAAAgt           ltBBB aa1/gt           ltCCC/gt
              ltBBB aa2 /gt           ltBBB aa3
    /gt           ltDDDgt                ltBBB bb31
    /gt           lt/DDDgt           ltCCC/gt   lt/AAAgt
  • Is it different from //BBB/attributebb?
Write a Comment
User Comments (0)
About PowerShow.com