14xpath-2up - 14 XPath 07 Oct, 2010 CSCC09F Programming on...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
14 XPath 07 Oct, 2010 CSCC09 Programming on the Web 1 14XPath CSCC09 Programming on the Web 1 XPath An expression language for selecting XML Document Components CSCC09F Programming on the Web 14XPath CSCC09 Programming on the Web 3 XPath b XPath language provides a means of identifying a particular element, group of elements, text fragment, or other part of an XML document, that is modelled as a tree of nodes: c root node b implicit top-level element (the document root element is a child of this node, as are usually some PI nodes). c element, attribute, namespace, processing instruction (PI), comment and text (maximal groupings of characters) nodes b specified independent of XSL, intended for use with XSLT, as well as XQuery, XPointer and XLink b in the case of XSLT, template rules use XPath patterns to define part(s) of the tree the template is to apply to ( match="…" ) transformations.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14 XPath 07 Oct, 2010 CSCC09 Programming on the Web 2 14XPath CSCC09 Programming on the Web 4 XPath b XPath – why should you care? b XML technologies have huge and growing market presence (backed by W3C, and MS, IBM, Oracle, Cisco, Juniper, Sun, BMO, PWC, . ..) b Data representation and query: XQuery is designed to query anything that can appear as XML, including databases. b Generic XML hyperlinks: XLink and XPointer define a standard for hyperlinks in XML documents. b New generation of remote procedure calls and distributed documents based on XML (Web Services with SOAP, WSDL, XSchema) b Data transformation: XSLT b Web 2.0: jQuery can use XPath to select elements 14XPath CSCC09 Programming on the Web 5 XPath: motivational examples b XPath excels in expressive ability to define complex subtree selections and relationships, e.g.: c //CD // looks at entire tree, matches CD elements c select only CD’s whose ARTIST child element content has text value “Bob Dylan” //CD[ARTIST="Bob Dylan"] c selects all CD’s with id attribute value “cd12” – analogous to getElementById("cd12") in DOM //CD[@id="cd12"] c now we want to select only the Bob Dylan CD’s costing more than $10.00 //CD[ARTIST="Bob Dylan" and PRICE>"10.00"] c How would we select the YEAR of these Dylan CD’s? c //CD[ARTIST="Bob Dylan" and PRICE>"10.00"]/YEAR b Consider how you would write these expressions using the DOM addressing model (ugh!)
Background image of page 2
14 XPath 07 Oct, 2010 CSCC09 Programming on the Web 3 14XPath CSCC09 Programming on the Web 7 XPath: motivational challenges b How would you select the described subtrees using the XPath addressing model? c select all CD’s with a price lower than the current node’s price c //CD[price < current()/price] selects all CD’s with a price lower than the current node’s price c select all CD elements that are first in a subtree list c //CD[1] selects all CD elements that are first in a subtree list (note XPath uses 1-based indexing) c output the titles of all CD's from same year as current CD, but do not show current CD title in this list. c
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

14xpath-2up - 14 XPath 07 Oct, 2010 CSCC09F Programming on...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online