Xpath Basics

  • Upload
    anudeep

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

  • 7/24/2019 Xpath Basics

    1/3

    XPATH

    XML documents can be thought of as a tree structure made up

    parente,child and sibling relationships. Xpath is to query the XML. It is like SQL to R!MS

    Xpath uses e"pressions to #nd elements, attributes and otherinformation.

    $2.5020

    $5.5010

    $1.50

    10

    $.50!010

    $.If %e %ant to #nd the amount of lemonade stock In&entory'drink'lemonade'amount

  • 7/24/2019 Xpath Basics

    2/3

    rink is the child of in&entory. Lemonade and pop are siblings. (rice

    and amount are children of lemonade.

    ). If %e %ant to #nd out the supplier of chips. In&entory'snack'chips*supplier

    +. e can also specify the abo&e one like this In&entory''chips*supplier-. If %e %ant to get all the prices then In&entory''price. If %e %ant to #nd the (rice of /irst Lemonade In&entory'drink'lemonade0$1 22Predicates3. /ind the parent of lemonade In&entory'drink'lemonade'..4. /ind all the children of pop .'in&entory'drink'pop'*22 wild card

    5. /ind all the children in in&entory6last generation7 in&entory'8'8'8$9. /ind all the in&entory %hose quantity : $ in&entory'8'80amount :$1 in&entory'8'80amount :$1'..

    $$. /ind lemonades %hose quantity :$ in&entory'drink'lemonade0amount :$1 in&entory'drink'lemonade'amount0. : $1'..

    $). /ind the drink %hose lemonade quantity : $

    in&entory'drink0lemonade'amount : $1 2 you can %rite "pathinside the 0 1 in&entory'drink'lemonade'amount0. : $1'..'..

    $9. /ind all the children of chips and pop6 (ipe character to merge t%o

    "mls7 in&entory'snack'chips'8 ; in&entory'drink'pop'8

    $$. XPath Functions e can use the built in functions de#ned in Xpath

    $.Position() gi&es the position of the node in the tree. Select

    )ndlemonade 'in&entory0$1'drink0$1'lemonade0position67 < )1 is same as 'in&entory0$1'drink0$1'lemonade0)1

  • 7/24/2019 Xpath Basics

    3/3

    If %e %ant to #nd out #rst ) lemonades'in&entory0$1'drink0$1'lemonade0position67 = +1

    ). Last67 gi&es the last node 'in&entory0$1'drink0$1'lemonade0last672$1

    +. >ode2name6node7 gi&es the Q>ame of the node

    >ode2name6'in&entory0$1'drink0$1'lemonade7 gi&es?@namespaceAlemonadeB

    -. Local2name6node7 ignores the name space and gi&es the

    node name. >umber6?$-.B7 $-.3. Round6-.7 -4. String6-.7 C-.$D

    Eoncat6CFmount for lemonade