Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML and XPath. Web Services: XML+XPath2 EXtensible Markup Language (XML) a W3C standard to complement HTML A markup language much like HTML origins: structured.

Similar presentations


Presentation on theme: "XML and XPath. Web Services: XML+XPath2 EXtensible Markup Language (XML) a W3C standard to complement HTML A markup language much like HTML origins: structured."— Presentation transcript:

1 XML and XPath

2 Web Services: XML+XPath2 EXtensible Markup Language (XML) a W3C standard to complement HTML A markup language much like HTML origins: structured text SGML motivation: HTML describes presentation XML describes content HTML  XML  SGML http://www.w3.org/TR/2000/REC-xml-20001006 (version 2, 10/2000)

3 Web Services: XML+XPath3 HTML Describes the Presentation

4 Web Services: XML+XPath4 HTML Describes the Presentation Bibliography Foundations of Databases Abiteboul, Hull, Vianu Addison Wesley, 1995 Data on the Web Abiteoul, Buneman, Suciu Morgan Kaufmann, 1999

5 Web Services: XML+XPath5 XML Describes the Contents Foundations… Abiteboul Hull Vianu Addison Wesley 1995 …

6 Web Services: XML+XPath6 More on XML XML was designed to describe data contents XML tags are not predefined in XML. You must “invent” your own tags XML uses a Document Type Definition (DTD) or an XML Schema to describe the data XML with a DTD or XML Schema is designed to be self-descriptive

7 Web Services: XML+XPath7 Applications and Impact of XML Data can be stored outside HTML Data can be exchanged between incompatible systems Financial information can be exchanged over the Internet Plain text files can be used to share data Data is available to more users Used to create new languages WML, WSDL, BPEL, ……

8 Web Services: XML+XPath8 Benefits of Using XML XML is structured XML documents are easily committed to a persistence layer XML is platform independent, textual information XML is an open standard XML is language independent DOM and SAX are open, language-independent set of interfaces XML is web enabled XML is totally extensible XML supports shareable structure (using DTDs) XML enables interoperability

9 Web Services: XML+XPath9 XML Terminology tags: book, title, author, … start tag:, end tag: elements: …, … elements are nested empty element: abbrv. an XML document: single root element well formed XML document: if it has matching tags

10 Web Services: XML+XPath10 Attributes are Alternative Ways to Represent Data Foundations of Databases Abiteboul … 1995

11 Web Services: XML+XPath11 CDATA Section Syntax: <![CDATA[ function matchwo (a, b) { if (a < b && a < 0) then { return 1 } else { return 0 } } ]]>

12 Web Services: XML+XPath12 Entity References Syntax: &entityname; Example: this is less than < Some entities: < < > > & & &apos; ‘ " “ & Unicode char

13 Web Services: XML+XPath13 Processing Instructions Syntax: Example: Alarm Clock 19.99 What do they mean ?

14 Web Services: XML+XPath14 XML Comments Syntax Yes, they are part of the data model !!!

15 Web Services: XML+XPath15 Name Conflicts Solution: prefix Apples Bananas African Coffee Table 80 120 Apples Bananas African Coffee Table 80 120

16 Web Services: XML+XPath16 … XML Namespaces syntactic:, semantic: provide URL for schema

17 Web Services: XML+XPath17 XML Namespaces http: // www.w3.org/TR/REC-xml-names (1/99) name ::= [prefix:]localpart … 15 …

18 Web Services: XML+XPath18 http://www.w3.org/TR/xpath (11/99) Building block for other W3C standards: XSL Transformations (XSLT) XML Link (XLink) XML Pointer (XPointer) XML Query Was originally part of XSL XPath

19 Web Services: XML+XPath19 Example for XPath Queries Addison-Wesley Serge Abiteboul Rick Hull Victor Vianu Foundations of Databases 1995 Freeman Jeffrey D. Ullman Principles of Database and Knowledge Base Systems 1998

20 Web Services: XML+XPath20 Data Model for XPath bib book publisherauthor.. Addison-WesleySerge Abiteboul The root The root element Processing instruction Comment

21 Web Services: XML+XPath21 Simple Expressions / bib / book / year Result: 1995 1998 / bib / paper / year Result: empty (there were no papers)

22 Web Services: XML+XPath22 Restricted Kleene Closure // author Result: Serge Abiteboul Rick Hull Victor Vianu Jeffrey D. Ullman / bib // first-name Result: Rick

23 Web Services: XML+XPath23 Functions /bib/book/author/text() Result: Serge Abiteboul Victor Vianu Jeffrey D. Ullman Rick Hull doesn’t appear because he has firstname, lastname Functions in XPath: text() = matches the text value node() = matches any node (= * or @* or text()) name() = returns the name of the current tag

24 Web Services: XML+XPath24 Wildcard // author /  Result: Rick Hull  Matches any element

25 Web Services: XML+XPath25 Attribute Nodes / bib / book / @price Result: “55” @price means that price is has to be an attribute

26 Web Services: XML+XPath26 Qualifiers / bib / book / author[first-name] Result: Rick Hull / bib / book / author[firstname][address[ // zip][city]] / lastname Result: … …

27 Web Services: XML+XPath27 More Qualifiers / bib / book[@price < “60”] / bib / book[author / @age < “25”] / bib / book[author / text()]

28 Web Services: XML+XPath28 XPath Summary bib matches a bib element  matches any element / matches the root element / bib matches a bib element under root bib / paper matches a paper in bib bib // paper matches a paper in bib, at any depth // paper matches a paper at any depth paper|book matches a paper or a book @pricematches a price attribute bib / book / @price matches price attribute in book, in bib bib / book[@price<“55”] / author / lastname matches…

29 Web Services: XML+XPath29 XPath : More Details An XPath expression, p, establishes a relation between: A context node, and A node in the answer set In other words, p denotes a function: S[ p ] : Nodes -> {Nodes} Examples: author / firstname. = self.. = parent part /  /  / subpart /.. / name = part /  /  [subpart] / name

30 Web Services: XML+XPath30 The Root 1 2 bib is the document element The root is above bib / bib = returns the document element / = returns the root Why? Because we may have comments before and after ; they become siblings of This is advanced xmlogy

31 Web Services: XML+XPath31 XPath Navigation We can navigate along 13 axes: ancestor ancestor-or-self attribute child descendant descendant-or-self following following-sibling namespace parent preceding preceding-sibling self We’ve only seen these, so far

32 Web Services: XML+XPath32 Examples Examples: child::author / child::lastname = author / lastname child::author / descendant::zip = author // zip child::author / parent::  = author /.. child::author / attribute::age = author / @age What does this mean ? paper / publisher / parent::  / author / bib // address[ancestor::book] / bib // author / ancestor::  // zip

33 Web Services: XML+XPath33 More Examples name() = the name of the current node / bib //  [name()=book] same as / bib // book What does this mean ? / bib //  [ancestor::  [name()!=book]] Navigation axis gives us strictly more power !


Download ppt "XML and XPath. Web Services: XML+XPath2 EXtensible Markup Language (XML) a W3C standard to complement HTML A markup language much like HTML origins: structured."

Similar presentations


Ads by Google