XPATH - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

XPATH

Description:

? XPATH ?????? ????? ????? ? XML. ? XPATH ?????? ???????? ... script type='text/vbscript' set xmlDoc=CreateObject('Microsoft.XMLDOM') xmlDoc.async='false' ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 19
Provided by: Instr166
Category:
Tags: xpath | vbscript

less

Transcript and Presenter's Notes

Title: XPATH


1
XPATH ????
MCSD Doron Amir www.doronamir.com
2
What is XPath?
  • A W3C Standard
  • Not written in XML
  • Defines parts of an XML document
  • Defines a standard functions
  • Major element in XSLT

??? ???? ? w3c ? XPATH ???? XML ? XPATH ??????
????? ????? ? XML ? XPATH ?????? ????????
???????? ?????? ????? XML ? XPATH ???? ??? ???? ?
XSLT
3
XPath Expression
  • XPATH ????? ??????? ??? ????? ????? ?????

????? ?? ???????? Price ????? ???????? CD ?????
????? ????? CATALOG
/catalog/cd/price
The Price Element
Root Element
The CD Element
lt?xml version"1.0" encoding"ISO-8859-1"?gt
ltcataloggt ltcd country"USA"gt lttitlegtEmpire
Burlesquelt/titlegt ltartistgtBob Dylanlt/artistgt
ltpricegt10.90lt/pricegt lt/cdgt ltcataloggt
4
XPath Expression
  • /catalog/cd/price Absolute path
  • //cd All the CD elemen ts in the document

Selecting Unknown Elements
/catalog/cd/
Select All the child elements of all the cd
5
XPath Expression
  • /catalog/cd/
  • All the child elements of all the cd elements
  • /catalog//price
  • All the price elements that are grandchild
    elements of the catalog
  • ///price
  • All price elements which have 2 ancestors
  • //
  • All elements in the document

Parent
/catalog//price
child element
///price
grandchild elements
/catalog/cd/
6
Selecting Branches
  • /catalog/cd1
  • first cd child element
  • /catalog/cdlast()
  • last cd child element
  • /catalog/cdprice
  • element that have a price element
  • /catalog/cdprice10.90
  • all the cd elements that have a price element
    with a value of 10.90
  • /catalog/cdprice10.90/price
  • all the Price elements that have a price element
    with a value of 10.90

7
Several Paths
  • /catalog/cd/title /catalog/cd/artist
  • all the title and artist elements of the cd
    element of the catalog element
  • //title //artist
  • all the title and artist elements in the
    document
  • //title //artist //price
  • all the title, artist and price elements in the
    document
  • /catalog/cd/title //artist
  • all the title elements of the cd element and all
    the artist elements in the document

8
Attributes
  • Specified by the _at_ prefix
  • //_at_country
  • all attributes named country
  • //cd_at_country
  • all cd elements which have an attribute named
    country
  • //cd_at_
  • all cd elements which have any attribute
  • //cd_at_country'UK'
  • all cd elements which have an attribute named
    country with a value of 'UK'

9
Location
Selects the text node children
childtext()
Selects all the children of the current node
childnode()
attributeX
Selects the X attribute of the current node
attribute
Selects all attributes of the current node
10
  • childpriceprice9.90
  • childcdposition()1
  • childcdposition()last()
  • childcdposition()lt6
  • /descendantcdposition()7
  • childcdattributetype"classic"

Selects all price elements that are children of
the current node with a price element that
equals 9.90
Selects the first cd child of the current node
Selects the last cd child of the current node
Selects the first five cd children of the current
node
Selects the seventh cd element in the document
Selects all cd children of the current node that
have a type attribute with value classic
11
short
childcdattributetype"classic"
cd_at_type"classic"
parentnode()/childcd
../cd
12
XPath Expression
13
XPath Expression
14
XPath Expression
15
XPath Functions
  • string-length('Beatles')Result 7
  • substring('Beatles',1,4)Result 'Beat'
  • round(3.14)Result 3
  • number(false())Result 0

16
XPath Functions
  • ceiling(3.14)Result 4
  • floor(3.14)Result 3
  • string(314)Result '314'
  • translate('1230','0123','abcd')Result 'bcda'
  • translate('1230','03','54')Result '1245'

17
Example
lthtmlgt ltbodygt ltscript type"text/vbscript"gt set
xmlDocCreateObject("Microsoft.XMLDOM") xmlDoc.asy
nc"false" xmlDoc.load("cdcatalog.xml") path"//c
dpricelt9.90" set nodesxmlDoc.selectNodes(path)
for each x in nodes document.write("ltxmpgt")
document.write(x.xml) document.write("lt/xmpgt") n
ext lt/scriptgt lt/bodygt lt/htmlgt
ltcdgt lttitlegtSylvias Motherlt/titlegt ltartistgtDr.Ho
oklt/artistgt ltcountrygtUKlt/countrygt ltcompanygtCBSlt/
companygt ltpricegt8.10lt/pricegt ltyeargt1973lt/yeargt lt
/cdgt ltcdgt lttitlegtMaggie Maylt/titlegt ltartistgtRod
Stewartlt/artistgt ltcountrygtUKlt/countr ltcompanygtPic
kwicklt/companygt ltpricegt8.50lt/pricegt ltyeargt1990lt/
yeargt lt/cdgt
18
XPATH ????
MCSD Doron Amir www.doronamir.com
Write a Comment
User Comments (0)
About PowerShow.com