Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Xpath Nodes

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 497
    Comment on it

    Xpath Nodes:

    We will use following XML to cover Xpath nodes:
     

    <Film>
        <title> Harry Potter </title>
        <Director> Mr. X </Director>
        <Producer> $500 </Producer>
    </Film>

    1. Parent: "Film" is the parent of "title, Director and Producer".
    2. Children: "title, Director, Producer" are the children of Parent "Film"
    3. Siblings: "title, Director and Producer" are siblings.
    4. Ancestors: Ancestor is a node's parent, parent's parent etc
    For example:

    <Hollywood>
                    <Film>
                        <title> Harry Potter </title>
                        <Director> Mr. X </Director>
                        <Producer> $500 </Producer>
                    </Film>
    
    </Hollywood>

    Here, "title" has "Film and Hollywood" as its ancestors.

    5. Descendants: Descendant is the node's children, children's children, etc.

    #Selecting nodes: We can select nodes using the following symbols:
    /  :  Selects from the root node
    //  :  Selects nodes anywhere in the document from the current node.
    :  Selects the current node
    ..   : Selects the parent node
    @  : Selects attributes

    #Predicates: The condition provided between the square brackets "[]" is called Predicates.
    For example:
     /Hollywood/Film[1]  :  Selects the first Film element that is child of "Hollywood".
    //film[@lang]  :  Selects all the 'film' element that has attribute "lang"

    Following are some of the examples to show how "*" and other symbols work:
    : matches any element node
    Eg: /Hollywood/*  :  selects all the child element nodes of the 'Hollywood' element.
    //*  :  selects all the elements in the document.
    @*  :  matches any attribute node
    Eg: //title[@*]   : select all title elements which have atleast one attribute of any kind.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: