1 / 18

XPATH מבוא

XPATH מבוא. MCSD Doron Amir www.doronamir.com. 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

yitro
Download Presentation

XPATH מבוא

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 בחירת כל האלמנטים Price שבתוך האלמנטים CD שבתוך אלמנט השורש CATALOG • XPATH מכילה ביטויים עבר זיהוי צמתים במסמך “/catalog/cd/price” The Price Element Root Element The CD Element <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd country="USA"> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <price>10.90</price> </cd> <catalog>

  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/cd[1] • first cd child element • /catalog/cd[last()] • last cd child element • /catalog/cd[price] • element that have a price element • /catalog/cd[price=10.90] • all the cd elements that have a price element with a value of 10.90: • /catalog/cd[price=10.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 andall the artist elements in the document

  8. Attributes Specified by the @ prefix • //@country all attributes named country • //cd[@country] all cd elements which have an attribute named country: • //cd[@*] all cd elements which have any attribute: • //cd[@country='UK'] all cd elements which have an attribute named country with a value of 'UK':

  9. Location Selects the text node children child::text() child::node() Selects all the children of the current node attribute::X Selects the X attribute of the current node attribute::* Selects all attributes of the current node

  10. 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 • child::price[price=9.90] • child::cd[position()=1] • child::cd[position()=last()] • child::cd[position()<6] • /descendant::cd[position()=7] • child::cd[attribute::type="classic"] 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 child::cd[attribute::type="classic"] cd[@type="classic"] parent::node()/child::cd ../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('12:30','0123','abcd')Result: 'bc:da' • translate('12:30','03','54')Result: '12:45'

  17. Example <html> <body> <script type="text/vbscript"> set xmlDoc=CreateObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("cdcatalog.xml") path="//cd[price<9.90]" set nodes=xmlDoc.selectNodes(path) for each x in nodes document.write("<xmp>") document.write(x.xml) document.write("</xmp>") next </script> </body> </html> <cd> <title>Sylvias Mother</title> <artist>Dr.Hook</artist> <country>UK</country> <company>CBS</company> <price>8.10</price> <year>1973</year> </cd> <cd> <title>Maggie May</title> <artist>Rod Stewart</artist> <country>UK</countr <company>Pickwick</company> <price>8.50</price> <year>1990</year> </cd>

  18. XPATH מבוא MCSD Doron Amir www.doronamir.com

More Related