Presentation is loading. Please wait.

Presentation is loading. Please wait.

More XML: semantics, DTDs, XPATH February 18, 2004.

Similar presentations


Presentation on theme: "More XML: semantics, DTDs, XPATH February 18, 2004."— Presentation transcript:

1 More XML: semantics, DTDs, XPATH February 18, 2004

2 XML Document Mary Maple 345 Seattle John Thailand 23456 Mary Maple 345 Seattle John Thailand 23456 person elements name elements attributes

3 XML Terminology Elements –enclosed within tags: … –nested within other elements: … –can be empty abbreviated as –can have Attributes … XML document has as single ROOT element

4 Buzzwords What is XML? –W3C data exchange format –Hierarchical data model –Self-describing –Semi-structured

5 XML as a Tree !! Mary Maple 345 Seattle John Thailand 23456 Mary Maple 345 Seattle John Thailand 23456 data person Mary name address streetnocity Maple345 Seattle name address John Thai phone 23456 id o555 Element node Text node Attribute node Minor Detail: Order matters !!!

6 XML is self-describing Schema elements become part of the data –In XML,, are part of the data, and are repeated many times –Relational schema: persons(name,phone) defined separately for the data and is fixed Consequence: XML is much more flexible

7 Relational Data as XML John 3634 Sue 6343 Dick 6363 John 3634 Sue 6343 Dick 6363 person name phone “John”3634“Sue”“Dick”63436363 persons XML:

8 XML is semi-structured Missing elements: Could represent in a table with nulls John 1234 Joe John 1234 Joe  no phone ! namephone John1234 Joe-

9 XML is semi-structured Repeated elements Impossible in tables: Mary 2345 3456 Mary 2345 3456  two phones ! namephone Mary23453456 ???

10 XML is semi-structured Elements with different types in different objects Heterogeneous collections: – can contain both s and s John Smith 1234 John Smith 1234  structured name !

11 Document Type Definition: DTD an XML document may have a DTD –rules about the contents of elements –like a schema for an XML document XML document: well-formed = if tags are correctly closed valid = if it has a DTD and conforms to it validation is useful in data exchange part of the original XML specification

12 Very Simple DTD <!DOCTYPE company [ ]> <!DOCTYPE company [ ]> Element What’s in the element? Root Element

13 DTD: The Content Model Content model: –Complex = a regular expression over other elements –Text-only = #PCDATA –Empty = EMPTY –Any = ANY –Mixed content = (#PCDATA | A | B | C)* content model

14 Very Simple DTD 123456789 John B432 1234 987654321 Jim B123... 123456789 John B432 1234 987654321 Jim B123... Example of valid XML document:

15 DTD: Regular Expressions <!ELEMENT name (firstName, lastName)).......... <!ELEMENT name (firstName?, lastName)) DTDXML <!ELEMENT person (name, phone*)) sequence optional <!ELEMENT person (name, (phone|email))) Kleene star alternation...................... lots of other features

16 Querying XML Data XPath = simple navigation through the tree XQuery = the SQL of XML XSLT = recursive traversal –will not discuss in class

17 Sample Data for 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 Addison-Wesley Serge Abiteboul Rick Hull Victor Vianu Foundations of Databases 1995 Freeman Jeffrey D. Ullman Principles of Database and Knowledge Base Systems 1998

18 Data Model for XPath bib book publisherauthor.. Addison-WesleySerge Abiteboul The root The root element

19 XPath: Simple Expressions Result: 1995 1998 Result: empty (there were no papers) /bib/book/year /bib/paper/year

20 XPath: Restricted Kleene Closure Result: Serge Abiteboul Rick Hull Victor Vianu Jeffrey D. Ullman Result: Rick //author /bib//first-name

21 Xpath: Text Nodes Result: Serge Abiteboul 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 /bib/book/author/text()

22 Xpath: Wildcard Result: Rick Hull * Matches any element //author/*

23 Xpath: Attribute Nodes Result: “55” @price means that price is an attribute /bib/book/@price

24 Xpath: Predicates Result: Rick Hull /bib/book/author[firstname]

25 Xpath: More Predicates Result: … … /bib/book/author[firstname][address[//zip][city]]/lastname

26 Xpath: More Predicates /bib/book[@price < “60”] /bib/book[author/@age < “25”] /bib/book[author/text()]

27 Xpath: Summary bibmatches a bib element *matches any element /matches the root element /bibmatches a bib element under root bib/papermatches a paper in bib bib//papermatches a paper in bib, at any depth //papermatches a paper at any depth paper|bookmatches a paper or a book @pricematches a price attribute bib/book/@pricematches price attribute in book, in bib bib/book/[@price<“55”]/author/lastname matches…


Download ppt "More XML: semantics, DTDs, XPATH February 18, 2004."

Similar presentations


Ads by Google