Lecture #6 XML November 2 nd, 2000. Administration Thanks for the mid-term comments Comment on the book & readings Project #2 Project #1 Homework #4 Homework.

Slides:



Advertisements
Similar presentations
XML e X tensible M arkup L anguage (XML) By: Albert Beng Kiat Tan Ayzer Mungan Edwin Hendriadi.
Advertisements

Spring Part III: Introduction to XPath XML Path Language.
XML May 3 rd, XQuery Based on Quilt (which is based on XML-QL) Check out the W3C web site for the latest. XML Query data model –Ordered !
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 311 Database Systems I The Semistructured Data Model.
Database Management Systems, R. Ramakrishnan1 Introduction to Semistructured Data and XML Chapter 27, Part D Based on slides by Dan Suciu University of.
1 Part 3: Query Languages Managing XML and Semistructured Data.
Agenda from now on Done: SQL, views, transactions, conceptual modeling, E/R, relational algebra. Starting: XML To do: the database engine: –Storage –Query.
CSE 636 Data Integration XML Semistructured Data Document Type Definitions.
Querying XML (cont.). Comments on XPath? What’s good about it? What can’t it do that you want it to do? How does it compare, say, to SQL?
1 Lecture 10 XML Wednesday, October 18, XML Outline XML (4.6, 4.7) –Syntax –Semistructured data –DTDs.
1 Lecture 10: Database Design XML Wednesday, October 20, 2004.
1 COS 425: Database and Information Management Systems XML and information exchange.
1 Statistics XML: –Altavista: 800,000 pages returned. –Amazon.com: 242 books. In comparison: –God: 12,000 books, 7 Million pages –Bible: 32,000 books,
XML May 2 nd, Agenda XML as a data model Querying XML Manipulating XML A lot of discussion, politics and stories.
Managing XML and Semistructured Data Lecture 6: XPath Prof. Dan Suciu Spring 2001.
XML May 1 st, XML for Representing Data John 3634 Sue 6343 Dick 6363 John 3634 Sue 6343 Dick 6363 row name phone “John”3634“Sue”“Dick” persons.
1 Introduction to Database Systems CSE 444 Lecture 11 Xpath/XQuery April 23, 2008.
1 Lecture 11: Xpath/XQuery Friday, October 20, 2006.
1 Introduction to XML Yanlei Diao UMass Amherst April 19, 2007 Slides Courtesy of Ramakrishnan & Gehrke, Dan Suciu, Zack Ives and Gerome Miklau.
4/15/2002Bo Du 1 - Bo Du, April 15, XML - QL A Query Language for XML.
XML and Databases 198:541. XML Motivation  Huge amounts of unstructured data on the web: HTML documents  No structure information  Only format instructions.
Fundamentals, Design, and Implementation, 9/e Text and XML databases Instructor: Dragomir R. Radev Winter 2005.
End of SQL XML April 22 th, Null Values If x=Null then 4*(3-x)/7 is still NULL If x=Null then x=“Joe” is UNKNOWN Three boolean values: –FALSE =
1 Lecture 08: XML and Semistructured Data. 2 Outline XML (Section 17) –XML syntax, semistructured data –Document Type Definitions (DTDs) XPath.
Managing XML and Semistructured Data Lecture 2: XML Prof. Dan Suciu Spring 2001.
1 Lecture 08: XML and Semistructured Data. 2 Outline XML (Section 17) –XML syntax, semistructured data –Document Type Definitions (DTDs) XPath.
1 Lecture 16: Querying XML Data: XPath, XQuery Friday, February 11, 2005.
Querying XML February 12 th, Querying XML Data XPath = simple navigation through the tree XQuery = the SQL of XML XSLT = recursive traversal –will.
XML: Extensible Markup Language FST-UMAC Gong Zhiguo.
IS432: Semi-Structured Data Dr. Azeddine Chikh. 1. Semi Structured Data Object Exchange Model.
XML by Dan Suciu 1 Introduction to Semistructured Data and XML Based on slides by Dan Suciu University of Washington.
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.
Semistructured data and XML CS 645 April 5, 2006 Some slide content courtesy of Ramakrishnan & Gehrke, Dan Suciu, Zack Ives.
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Winter 2006Keller, Ullman, Cushing18–1 Plan 1.Information integration: important new application that motivates what follows. 2.Semistructured data: a.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
1 What Is XML? eXtensible Markup Language for data –Standard for publishing and interchange –“Cleaner” SGML for the Internet Applications: –Data exchange.
Management of XML and Semistructured Data Lecture 5: Query Languages Wednesday, 4/1/2001.
Lecture 6: XML Query Languages Thursday, January 18, 2001.
Lecture 5: XML Tuesday, January 16, Outline XML, DTDs (Data on the Web, 3.1) Semistructured data in XML (3.2) Exporting Relational Data in XML (8.3.1)
CSE 636 Data Integration Fall 2006 XML Query Languages XPath.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
XML query. introduction An XML document can represent almost anything, and users of an XML query language expect it to perform useful queries on whatever.
1 Introduction to Semistructured Data and XML. 2 How the Web is Today  HTML documents often generated by applications consumed by humans only easy access:
More XML: semantics, DTDs, XPATH February 18, 2004.
The Semistructured-Data Model Programming Languages for XML Spring 2011 Instructor: Hassan Khosravi.
XML e X tensible M arkup L anguage (XML) By: Albert Beng Kiat Tan Ayzer Mungan Edwin Hendriadi.
1 XQuery Slides From Dr. Suciu. 2 XQuery Based on Quilt, which is based on XML-QL Uses XPath to express more complex queries.
XML May 6th, Instructor AnHai Doan Brief bio –high school in Vietnam & undergrad in Hungary –M.S. at Wisconsin –Ph.D. at Washington under Alon &
IS432 Semi-Structured Data Lecture 4: XPath Dr. Gamal Al-Shorbagy.
Lecture 17: XPath and XQuery Wednesday, Nov. 7, 2001.
1 Lecture 12: XML, XPath, XQuery Friday, October 24, 2003.
SEMI-STRUCTURED DATA (XML) 1. SEMI-STRUCTURED DATA ER, Relational, ODL data models are all based on schema Structure of data is rigid and known is advance.
Lecture 14: Relational Algebra Projects XML?
Lecture 10 XML Monday, Oct. 21, 2001.
XML path expressions CSE 350 Fall 2003.
Lecture 11: Xpath/XQuery
Lecture 11 XML Wednesday, Oct. 24, 2001.
eXtensible Markup Language (XML)
Lecture 12: XML, XPath, XQuery
Semi-Structured data (XML Data MODEL)
Lecture 9: XML Monday, October 17, 2005.
Lecture 8: XML Data Wednesday, October
CSE591: Data Mining by H. Liu
Introduction to Database Systems CSE 444 Lecture 10 XML
Lecture 15: Querying XML Friday, October 27, 2000.
Semi-Structured data (XML)
Lecture 11: XML and Semistructured Data
Presentation transcript:

Lecture #6 XML November 2 nd, 2000

Administration Thanks for the mid-term comments Comment on the book & readings Project #2 Project #1 Homework #4 Homework #5

Outline XML: –Introduction –Syntax, DTDs, –Politics, –Exporting relational data to XML. Querying XML: –Xpath, XML-QL, Quilt, XSLT XML data management: –Storing XML in relational databases.

What is XML ? From HTML to XML HTML describes the presentation: easy for humans

HTML Bibliography Foundations of Databases Abiteboul, Hull, Vianu Addison Wesley, 1995 Data on the Web Abiteboul, Buneman, Suciu Morgan Kaufmann, 1999 HTML is hard for applications

XML Foundations… Abiteboul Hull Vianu Addison Wesley 1995 … XML describes the content: easy for applications

XML eXtensible Markup Language Roots: comes from SGML (very nasty language). After the roots: a format for sharing data Emerging format for data exchange on the Web and between applications

XML Applications Sharing data between different components of an application. Format for storing all data in Office EDI: electronic data exchange: –Transactions between banks –Producers and suppliers sharing product data (auctions) –Extranets: building relationships between companies –Scientists sharing data about experiments.

XML Syntax Very simple: <db> <book> <title>Complete Guide to DB2</title> <author>Chamberlin</author> </book> < > <title>Transaction Processing</title> <author>Bernstein</author> < >Newcomer</author> </book> <publisher> <name>Morgan Kaufman</name> <state>CA</state> </publisher> </db>

XML Terminology tags: book, title, author, … start tag:, end tag: start tags must correspond to end tags, and conversely

XML Terminology an element: everything between tags –example element: Complete Guide to DB2 –example element: Complete Guide to DB2 Chamberlin elements may be nested empty element: abbreviated an XML document has a unique root element well formed XML document: if it has matching tags

The XML Tree db book publisher titleauthor titleauthor namestate “Complete Guide to DB2” “Chamberlin”“Transaction Processing” “Bernstein”“Newcomer” “Morgan Kaufman” “CA” Tags on nodes Data values on leaves

More XML Syntax: Attributes Complete Guide to DB2 Chamberlin 1998 price, currency are called attributes

Replacing Attributes with Elements Complete Guide to DB2 Chamberlin USD attributes are alternative ways (worse ) to represent data

XML References  ID’s and IDREFs are used to reference objects.

“Types” (or “Schemas”) for XML Document Type Definition – DTD Define a grammar for the XML document, but we use it as substitute for types/schemas Will be replaced by XML-Schema (will extend DTDs)

An Example DTD <!DOCTYPE db [ ]> PCDATA means Parsed Character Data (a mouthful for string)

DTDs as Grammars db ::= (book|publisher)* book ::= (title,author*,year?) title ::= string author ::= string year ::= string publisher ::= (name, state) name ::= string state ::= string A DTD is a EBNF (Extended BNF) grammar An XML tree is precisely a derivation tree XML Documents that have a DTD and conform to it are called valid

More on DTDs as Grammars <!DOCTYPE paper [ ]> <!DOCTYPE paper [ ]> … XML documents can be nested arbitrarily deep

XML for Representing Data John 3634 Sue 6343 Dick 6363 row name phone “John”3634“Sue”“Dick” persons XML: persons

XML vs Data Models XML is self-describing Schema elements become part of the data –Reational schema: persons(name,phone) –In XML,, are part of the data, and are repeated many times Consequence: XML is much more flexible XML = semi-structured data

Semi-structured Data Explained Missing attributes: – John 1234 – Joe no phone ! Repeated attributes – Mary

S-S Data Further Explained Attributes with different types in different objects – John Smith 1234 Nested collections Heterogeneous collections: – contains both s and s

XML Data v.s. E/R, ODL, Relational Q: is XML better or worse ? A: serves different purposes –E/R, ODL, Relational models: For centralized processing, when we control the data –XML: Data sharing between different systems we do not have control over the entire data E.g. on the Web Do NOT use XML to model your data ! Use E/R, ODL, or relational instead.

Why Do People Like XML so much? It’s easy to learn. It’s human readable. No need for proprietary formats anymore. Lots of tools out there for basis manipulations, editing, validation, simple querying. It’s very flexible: –Data is self-describing –Can add attributes easily –Data can be irregular Note: (common fallacy) without common DTD’s data sharing is not solved!

Why are we DB’ers interested? It’s data, stupid. That’s us. Proof by Altavista: –database+XML -- 40,000 pages. Database issues: –How are we going to model XML? (trees). –How are we going to query XML? (XML-QL,Quilt) –How are we going to store XML (in a relational database? object-oriented?) –How are we going to process XML efficiently? (uh… well..., um..., ah..., get some good grad students!)

Exporting Relational Data to XML

Data Sharing with XML: Easy Data source (e.g. relational Database) Application Web XML

Exporting Relational Data to XML Product(pid, name, weight) Company(cid, name, address) Makes(pid, cid, price) productcompany makes

Export data grouped by companies GizmoWorks Tacoma gizmo … Bang Kirkland gizmo … … Redundant representation of products

The DTD

Export Data by Products Gizmo GizmoWorks Tacoma Bang Kirkland … OneClick … Redundant representation of companies

Which One Do We Choose ? The structure of the XML data is determined by agreement, with our partners, or dictated by committees –Many XML dialects (called applications) XML Data is often nested, irregular, etc No normal forms for XML

Querying XML At first, there was XQL (XPath): weak, impoverished. Then, Dbers noticed that XML is a variant on semi-structured data: invented XML-QL. A lot of people got excited – formed a committee. Committee is still working: –Inside scoop: Quilt – the best of XML-QL, SQL and Xpath.

Running Example Addison-Wesley Serge Abiteboul Rick Hull Victor Vianu Foundations of Databases 1995 Freeman Jeffrey D. Ullman Principles of Database and Knowledge Base Systems 1998

XPath Introduction Syntax for XML document navigation and node selection A recommendation of the W3C (i.e., a standard) Building block for other W3C standards: – XSL Transformations (XSLT) – XML Link (XLink) – XML Pointer (XPointer)

XPath Traversal /bib/book/year Result: /bib/paper/year Result: empty (there were no papers)

XPath Unbounded Traversal //author Result: Serge Abiteboul Rick Hull Victor Vianu Jeffrey D. Ullman /bib//first-name Result: Rick

XPath Text Selection /bib/book/author/text() Result: Serge Abiteboul Jeffrey D. Ullman Rick Hull doesn’t appear because he has firstname, lastname

XPath Wild Star //author/* Result: Rick Hull * Matches any element

XPath Attribute Navigation Result: means that price is has to be an attribute

XPath Existential Constraint /bib/book/author[firstname] Result: Rick Hull

XPath Existentials < “60”] < “25”] /bib/book[author/text()]

XPath Expressions 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 a price attribute price attribute in book, in bib matches…

XML-QL Hello World Matching data using elements patterns. WHERE Addison-Wesley $t $a IN “ CONSTRUCT $a

XML-QL Element-As Matching data using elements patterns. WHERE Addison-Wesley $t $a ELEMENT-AS $e IN “ CONSTRUCT $e

Constructing XML Data WHERE Addison-Wesley $t $a IN “ CONSTRUCT $a $t

Grouping with Nested Queries WHERE $t, Addison-Wesley CONTENT_AS $p IN “ CONSTRUCT $t WHERE $a IN $p CONSTRUCT $a

Joining Elements by Value WHERE $f $l ELEMENT_AS $e IN “ $f $l IN “ y > 1995 CONSTRUCT $e Find all articles whose writers also published a book after 1995.

Tag Variables WHERE $f $l ELEMENT_AS $e IN “ $f $l IN “ y > 1995 CONSTRUCT $e Find all articles whose writers have done something after 1995.

Regular Path Expressions WHERE $r Ford IN " CONSTRUCT $r Find all parts whose brand is Ford, no matter what level they are in the hierarchy.

Regular Path Expressions WHERE $r IN " CONSTRUCT $r

XML Data Integration WHERE ELEMENT_AS $n $ssn IN “ $ssn ELEMENT_AS $I IN “ CONSTRUCT $n $I Query can access more than one XML document.

Quilt: Hello World List all titles of books published by Morgan Kaufmann in 1998: FOR $b IN document(“bib.xml”)/book WHERE $b/publisher = “Morgan Kaufmann” AND $b/year = “1998” RETURN $b/title

Quilt: Creating XML Output Find all names with a firstname and lastname; group them in a FOR $a IN document(“bib.xml”)//author, $f IN $a/firstName, $l IN $a/lastName RETURN $f $l

Quilt: Joins Retrieve the titles of the books written by Laing before 1967, together with their reviews. FOR $b in $r in document(“reviews.xml”)//review WHERE $b/authors/lastname=“Laing” and RETURN $b/title/text(), $r

Quilt: FLWR Expressions Retrieve the titles of the books written by Laing before 1967 together with their reviews. FOR $b in LET $R = WHERE $b/authors/lastname=“Laing” RETURN $t $R

Quilt: another example List all authors that published both in 1998 and 1999 FOR $a IN distinct(document(“bib.xml”)/book/author, WHERE contains(document(“bib.xml”)/book[year=1998]/author, $a) AND contains(document(“bib.xml”)/book[year=1999]/author, $a) RETURN $a

XSL A.k.a XSLT A recommendation of the W3C (standard) Initial goal: translate XML to HTML Became: translate XML to XML –HTML is just a special case Interesting politics

Query Processing For XML Approach 1: store XML in a relational database. Translate an XML-QL/Quilt query into a set of SQL queries. –Leverage 20 years of research & development. Approach 2: store XML in an object-oriented database system. –OO model is closest to XML, but systems do not perform well and are not well accepted. Approach 3: build a native XML query processing engine. –Still in the research phase; see Zack next week.

Relational Approach Step 1: given a DTD, create a relational schema. Step 2: map the XML document into tuples in the relational database. Step 3: given a query Q in XML-QL/Quilt, translate it to a set of queries P over the relational database. Step 4: translate the tuples returned from the relational database into XML elements.

Which Relational Schema? The key question! Affects performance. No magic solution. Some options: –The EDGE table: put everything in one table –The Attribute tables: create a table for every tag name. –The inlining method: inline as much data into the tables.

An Example DTD <!DOCTYPE db [ ]> PCDATA means Parsed Character Data (a mouthful for string)

The Edge Approach sourceID tag destID destValue - Don’t need a DTD. - Very simple to implement.

The Attribute Approach rootID bookId bookID title rootID pubID pubID pubName bookID author Book Title Author Publisher pubID state PubName PubState

The In-lining Approach bookID title pubName pubState bookID author BookAuthor Book sourceID tag destID destValue Publisher

Let the Querying Begin! Matching data using elements patterns. WHERE Bernstein $t IN “ CONSTRUCT $t

The Edge Approach SELECT e3.destValue FROM E as e1, E as e2, E as e3 WHERE e1.tag = “book” and e1.destID=e2.sourceID and e2.tag=“title” and e1.destID=e3.sourceID and e3.tag=“author” and e2.author=“Bernstein”

The Attribute Approach SELECT Title.title FROM Book, Title, Author WHERE Book.bookID = Author.bookID and Book.bookID = Title.bookID and Author.author = “Bernstein”

The In-lining Approach SELECT Book.title FROM Book, BookAuthor WHERE Book.bookID =BookAuthor.bookID and BookAuthor.author = “Bernstein”

Reconstructing XML Elements Matching data using elements patterns. WHERE Bernstein $t ELEMENT-AS $e IN “ CONSTRUCT $e

Open Questions Native query processing for XML To order or not to order? Combining IR-style keyword queries with DB-style structured queries Updates Automatic selection of a relational schema How should we extend relational engines to better support XML storage and querying?