XPATH - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

XPATH

Description:

... similar to file system. ... Select all attributes _at_id AAA BBB id = 'b1'/ BBB id = 'b2' ... BBB elements which have attribute name with value bbb, ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 40
Provided by: sanjay70
Learn more at: https://web.mst.edu
Category:
Tags: xpath | attribute

less

Transcript and Presenter's Notes

Title: XPATH


1
XPATH
  • http//www.zvon.org/xxl/XPathTutorial/General/exam
    ples.html

2
  • XPath syntax is similar to file system. If the
    path starts with the slash / , then it represents
    an absolute path to the required element.  
  • /AAA (Select the root element AAA)
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           ltCCC/gt      lt/AAAgt

3
  • /AAA/CCC
  • Select all elements CCC which are children of the
    root element AAA
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           ltCCC/gt      lt/AAAgt

4
  • /AAA/DDD/BBB
  • Select all elements BBB which are children of DDD
    which are children of the root element AAA
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltBBB/gt
              ltDDDgt                ltBBB/gt
              lt/DDDgt           ltCCC/gt      lt/AAAgt

5
  • If the path starts with // then all elements in
    the document which fulfill following criteria are
    selected. 
  • //BBB
  • Select all elements BBB
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltDDDgt               
    ltBBB/gt          lt/DDDgt           ltCCCgt         
          ltDDDgt                    ltBBB/gt           
             ltBBB/gt               lt/DDDgt          lt/
    CCCgt      lt/AAAgt

6
  • //DDD/BBB
  • Select all elements BBB which are children of DDD
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltBBB/gt           ltDDDgt               
    ltBBB/gt          lt/DDDgt           ltCCCgt         
          ltDDDgt                    ltBBB/gt           
             ltBBB/gt               lt/DDDgt          lt/
    CCCgt      lt/AAAgt

7
  • The star selects all elements located by
    preceeding path  /AAA/CCC/DDD/
  • Select all elements enclosed by elements
    /AAA/CCC/DDD
  • ltAAAgt         
  • ltXXXgt               ltDDDgt                  
      ltBBB/gt                    ltBBB/gt              
          ltEEE/gt                    ltFFF/gt          
         lt/DDDgt          lt/XXXgt           ltCCCgt    
               ltDDDgt                    ltBBB/gt      
                  ltBBB/gt                    ltEEE/gt  
                      ltFFF/gt               lt/DDDgt   
         
  •   lt/CCCgt           ltCCCgt               ltBBBgt   
                     ltBBBgt                         ltB
    BB/gt                    lt/BBBgt               lt/B
    BBgt          lt/CCCgt      lt/AAAgt

8
  • ////BBB
  • Select all elements BBB which have 3 ancestors
  •      ltAAAgt           ltXXXgt               ltDDDgt
                        ltBBB/gt                    ltBB
    B/gt                    ltEEE/gt                   
     ltFFF/gt               lt/DDDgt          lt/XXXgt
              ltCCCgt              
  •  ltDDDgt                    ltBBB/gt                
        ltBBB/gt                    ltEEE/gt            
            ltFFF/gt               lt/DDDgt          lt/C
    CCgt           ltCCCgt               ltBBBgt        
                ltBBBgt                         ltBBB/gt
                        lt/BBBgt               lt/BBBgt 
             lt/CCCgt      lt/AAAgt

9
  • //
  • Select all elements
  •      ltAAAgt           ltXXXgt               ltDDDgt
                        ltBBB/gt                    ltBB
    B/gt                    ltEEE/gt                   
     ltFFF/gt               lt/DDDgt          lt/XXXgt
              ltCCCgt               ltDDDgt            
            
  • ltBBB/gt                    ltBBB/gt                
        ltEEE/gt                    ltFFF/gt            
       lt/DDDgt          lt/CCCgt           ltCCCgt      
             ltBBBgt                    ltBBBgt         
                    ltBBB/gt                    lt/BBBgt
                   lt/BBBgt          lt/CCCgt
         lt/AAAgt

10
  • Expression in square brackets can further specify
    an element. A number in the brackets gives the
    position of the element in the selected set. The
    function last() selects the last element in the
    selection.   /AAA/BBB1
  • Select the first BBB child of element AAA
  •      ltAAAgt           ltBBB/gt           ltBBB/gt
              ltBBB/gt           ltBBB/gt      lt/AAAgt

11
  • /AAA/BBBlast()
  • Select the last BBB child of element AAA
  •      ltAAAgt           ltBBB/gt           ltBBB/gt
              ltBBB/gt           ltBBB/gt      lt/AAAgt

12
  • Attributes are specified by _at_ prefix. 
  • //_at_id
  • Select all attributes _at_id
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB id "b2"/gt           ltBBB name
    "bbb"/gt           ltBBB/gt      lt/AAAgt

13
  • //BBB_at_id
  • Select BBB elements which have attribute id
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB id "b2"/gt           ltBBB name
    "bbb"/gt           ltBBB/gt      lt/AAAgt

14
  • //BBB_at_name
  • Select BBB elements which have attribute name
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB id "b2"/gt           ltBBB name
    "bbb"/gt           ltBBB/gt      lt/AAAgt

15
  • //BBB_at_
  • Select BBB elements which have any attribute
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB id "b2"/gt           ltBBB name
    "bbb"/gt           ltBBB/gt      lt/AAAgt

16
  • //BBBnot(_at_)
  • Select BBB elements without an attribute
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB id "b2"/gt           ltBBB name
    "bbb"/gt           ltBBB/gt      lt/AAAgt

17
  • Values of attributes can be used as selection
    criteria..   //BBB_at_id'b1'
  • Select BBB elements which have attribute id with
    value b1
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB name " bbb "/gt           ltBBB
    name "bbb"/gt      lt/AAAgt

18
  • //BBB_at_name'bbb'
  • Select BBB elements which have attribute name
    with value 'bbb'
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB name " bbb "/gt           ltBBB
    name "bbb"/gt      lt/AAAgt

19
  • Normalized-space removes leading and starting
    spaces and replaces sequences of whitespace
    characters by a single space
  • //BBBnormalize-space(_at_name)'bbb'
  • Select BBB elements which have attribute name
    with value bbb, leading and trailing spaces are
    removed before comparison
  •      ltAAAgt           ltBBB id "b1"/gt
              ltBBB name " bbb "/gt           ltBBB
    name "bbb"/gt      lt/AAAgt

20
  • Function count() counts the number of selected
    elements
  •   //count(BBB)2
  • Select elements which have two children BBB
  •     ltAAAgt           ltCCCgt               ltBBB/gt
                   ltBBB/gt               ltBBB/gt      
        lt/CCCgt           ltDDDgt               ltBBB/gt
                   ltBBB/gt          lt/DDDgt           

21
  • //count()2
  • Select elements which have 2 children
  •      ltAAAgt           ltCCCgt               ltBBB/gt
                   ltBBB/gt               ltBBB/gt     
         lt/CCCgt           ltDDDgt               ltBBB/gt
                   ltBBB/gt          lt/DDDgt
              ltEEEgt               ltCCC/gt           
        ltDDD/gt          lt/EEEgt      lt/AAAgt

22
  • //count()3
  • Select elements which have 3 children
  •      ltAAAgt           ltCCCgt               ltBBB/gt
                   ltBBB/gt               ltBBB/gt     
         lt/CCCgt           ltDDDgt               ltBBB/gt
                   ltBBB/gt          lt/DDDgt
              ltEEEgt               ltCCC/gt           
        ltDDD/gt          lt/EEEgt      lt/AAAgt

23
  • //name()'BBB'
  • Select all elements with name BBB, equivalent
    with //BBB
  •      ltAAAgt           ltBCCgt               ltBBB/gt
                   ltBBB/gt               ltBBB/gt     
         lt/BCCgt           ltDDBgt               ltBBB/gt
                   ltBBB/gt          lt/DDBgt
              

24
  • //starts-with(name(),'B')
  • Select all elements name of which starts with
    letter B
  •      ltAAAgt           ltBCCgt               ltBBB/gt
                   ltBBB/gt               ltBBB/gt     
         lt/BCCgt           ltDDBgt               ltBBB/gt
                   ltBBB/gt          lt/DDBgt
              ltBECgt               ltCCC/gt           
        ltDBD/gt          lt/BECgt      lt/AAAgt

25
  • //contains(name(),'C')
  • Select all elements name of which contain letter
    C
  •      ltAAAgt           ltBCCgt               ltBBB/gt
                   ltBBB/gt               ltBBB/gt     
         lt/BCCgt           ltDDBgt               ltBBB/gt
                   ltBBB/gt          lt/DDBgt
              ltBECgt               ltCCC/gt           
        ltDBD/gt          lt/BECgt      lt/AAAgt

26
  • //string-length(name()) 3
  • Select elements with three-letter name
  •      ltAAAgt           ltQ/gt           ltSSSS/gt
              ltBB/gt           ltCCC/gt
              ltDDDDDDDD/gt           ltEEEE/gt
         lt/AAAgt

27
  • //string-length(name()) lt 3
  • Select elements name of which has one or two
    characters
  •      ltAAAgt           ltQ/gt           ltSSSS/gt
              ltBB/gt           ltCCC/gt
              ltDDDDDDDD/gt           ltEEEE/gt
         lt/AAAgt
  •  

28
  • //string-length(name()) gt 3
  • Select elements with name longer than three
    characters
  •      ltAAAgt           ltQ/gt           ltSSSS/gt
              ltBB/gt           ltCCC/gt
              ltDDDDDDDD/gt           ltEEEE/gt
         lt/AAAgt

29
  • Several paths can be combined with separator. 
    //CCC //BBB
  • Select all elements CCC and BBB
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltDDDgt               ltCCC/gt          lt
    /DDDgt           ltEEE/gt      lt/AAAgt

30
  • /AAA/EEE //BBB
  • Select all elements BBB and elements EEE which
    are children of root element AAA
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltDDDgt               ltCCC/gt          lt
    /DDDgt           ltEEE/gt      lt/AAAgt

31
  • /AAA/EEE //DDD/CCC /AAA //BBB
  • Number of combinations is not restricted
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
              ltDDDgt               ltCCC/gt          lt
    /DDDgt           ltEEE/gt      lt/AAAgt

32
  • The child axis contains the children of the
    context node. The child axis is the default axis
    and it can be omitted.   /AAA
  • Equivalent of /childAAA
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
         lt/AAAgt

33
  • /AAA/BBB
  • Equivalent of /childAAA/childBBB
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
         lt/AAAgt

34
  • /childAAA/BBB
  • Both possibilities can be combined
  •      ltAAAgt           ltBBB/gt           ltCCC/gt
         lt/AAAgt

35
  • /descendant
  • Select all descendats of document root and
    therefore all elements
  •      ltAAAgt           ltBBBgt               ltDDDgt
                        ltCCCgt                        
     ltDDD/gt                         ltEEE/gt          
              lt/CCCgt               lt/DDDgt          lt
    /BBBgt           

36
  • /AAA/BBB/descendant
  • Select all descendants of /AAA/BBB
  •      ltAAAgt           ltBBBgt               ltDDDgt
                        ltCCCgt                        
     ltDDD/gt                         ltEEE/gt          
              lt/CCCgt               lt/DDDgt          lt
    /BBB

37
  • //CCC/descendant
  • Select all elements which have CCC among its
    ancestors
  •      ltAAAgt           ltBBBgt               ltDDDgt
                        ltCCCgt                        
     ltDDD/gt                         ltEEE/gt          
              lt/CCCgt               lt/DDDgt          lt
    /BBBgt           ltCCCgt               
  • ltDDDgt        ltEEEgt               ltDDDgt         
                  ltFFF/gt                      lt/DDDgt
                        lt/EEEgt               lt/DDDgt 
             lt/CCCgt      lt/AAAgt

38
  • //CCC/descendantDDD
  • Select elements DDD which have CCC among its
    ancestors
  •      ltAAAgt           ltBBBgt               ltDDDgt
                        ltCCCgt                        
     ltDDD/gt                         ltEEE/gt          
              lt/CCCgt               lt/DDDgt          lt
    /BBBgt           ltCCCgt               
  •          ltDDDgt                    ltEEEgt         
                ltDDDgt                       ltFFF/gt  
                       lt/DDDgt                    lt/EE
    Egt               lt/DDDgt          lt/CCCgt
         lt/AAAgt

39
  • The parent axis contains the parent of the
    context node, if there is one.   //DDD/parent
  • Select all parents of DDD element
  •      ltAAAgt           ltBBBgt               ltDDDgt
                        ltCCCgt                        
     ltDDD/gt                         ltEEE/gt          
              lt/CCCgt               lt/DDDgt          lt
    /BBBgt           ltCCCgt               ltDDDgt      
                  
  • ltEEEgt                       ltDDDgt               
            ltFFF/gt                     lt/DDDgt       
                 lt/EEEgt               lt/DDDgt        
      lt/CCCgt      lt/AAAgt
Write a Comment
User Comments (0)
About PowerShow.com