Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 636 Data Integration XML Semistructured Data Document Type Definitions.

Similar presentations


Presentation on theme: "CSE 636 Data Integration XML Semistructured Data Document Type Definitions."— Presentation transcript:

1 CSE 636 Data Integration XML Semistructured Data Document Type Definitions

2 2 Semistructured Data Another data model, based on trees Motivation: flexible representation of data –Often, data comes from multiple sources with differences in notation, meaning, etc. Motivation: sharing of documents among systems and databases

3 3 Nodes = objects Labels on arcs (attributes, relationships) Atomic values at leaf nodes (nodes with no arcs out) Flexibility: no restriction on: –Labels out of a node –Number of successors with a given label Graphs of Semistructured Data

4 4 Bud A.B. Gold1995 MapleJoe’s M’lob beer bar manf servedAt name addr prize yearaward root The bar object for Joe’s Bar The beer object for Bud Example: Data Graph

5 5 XML HTML Uses tags for formatting the presentation (e.g., “italic”) Hard for applications to process XML = Extensible Markup Language Uses tags for semantics (e.g., “this is an address”) –Similar to labels in semistructured data Allows you to invent your own tags Easy for applications to process

6 6 HTML  XML Bibliography Foundations of Databases Abiteboul, Hull, Vianu Addison Wesley, 1995 Data on the Web Abiteboul, Buneman, Suciu Morgan Kaufmann, 1999 Foundations of Databases Abiteboul Hull Vianu Addison Wesley 1995 …

7 7 Why XML is of Interest to Us XML is just syntax for data –Note: we have no syntax for relational data –But XML is not relational: semistructured This is exciting because: –Can translate any data to XML –Can ship XML over the Web (HTTP, SOAP) –Can input XML into any application –Thus: data sharing and exchange on the Web

8 8 XML Data Sharing and Exchange  Applications Relational DB Web Site Web Service TransformIntegrate Warehouse XML Data Web (HTTP, SOAP) XML DB  Applications

9 9 XML Tags & Elements Tags: book, title, author, … –XML tags are case sensitive Tags, as in HTML, are normally matched pairs – … –Start tag:, End tag: Elements: everything between tags –Example 1: Foundations of Databases –Example 2: Foundations of Databases Elements may be nested arbitrarily Empty element: –Abbreviation

10 10 XML Attributes Foundations of Databases Abiteboul … 1995 Attributes are alternative ways to represent data

11 11 Replacing Attributes with Elements Foundations of Databases Abiteboul … 1995 55 USD

12 12 Elements vs. Attributes Too many attributes make documents hard to read Attributes do not specify document structure Attributes are good for simple information

13 13 More XML: CDATA Section Syntax: Example: <>]]>

14 14 More XML: Entity References << >> && &apos;‘ "“ &Unicode char Syntax: &entityname; Example: this is less than < Some entities:

15 15 More XML: Comments Syntax Yes, they are part of the data model !!!

16 16 Mary Maple 345 Seattle John Thailand 23456 XML Semantics: a Tree ! data Mary person name address name address streetnocity Maple345 Seattle John Thai phone 23456 age 25 Element node Text node Attribute node Order matters!!!

17 17 Well-Formed XML Start the document with a declaration, surrounded by Normal declaration is: –“Standalone” = “no DTD provided” Has single root element surrounding nested elements Has matching tags

18 18 XML Data XML is self-describing Schema elements become part of the data –Relational schema: person(name, phone) –In XML,, are part of the data, and are repeated many times Consequence: XML is much more flexible XML = semistructured data –Well-Formed XML with nested tags is exactly the same idea as trees of semistructured data –XML also enables nontree structures, as does the semistructured data model

19 19 XML is Semistructured Data Missing attributes: Could represent in a table with nulls John 1234 Joe John 1234 Joe  no phone ! namephone John1234 Joe-

20 20 XML is Semistructured Data Repeated attributes Impossible in tables: Mary 2345 3456 Mary 2345 3456  two phones ! namephone Mary23453456 ???

21 21 XML is Semistructured Data Attributes with different types in different objects Nested collections (no 1NF) Heterogeneous collections: – contains both s and s John Smith 1234 John Smith 1234  structured name !

22 22 Document Type Definition (DTD) Part of the original XML specification An XML document may have a DTD Valid XML: if it has a DTD and conforms to it Validation is useful in data exchange

23 23 Very Simple DTD <!DOCTYPE db [ ]> <!DOCTYPE db [ ]>

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

25 25 … … … … … … … … … … … … … … … … … … DTD: Regular Expressions <!ELEMENT name (firstName, lastName)) <!ELEMENT name (firstName?, lastName)) <!ELEMENT person (name, phone*)) sequence optional <!ELEMENT person (name, (phone|email))) zero or more alternation DTDXML <!ELEMENT person (name, phone+)) one or more

26 26 DTD: Attributes <!ATTLISTperson age CDATA #REQUIRED height CDATA #IMPLIED> <!ATTLISTperson age CDATA #REQUIRED height CDATA #IMPLIED> <personage=“25” height=“6”>... <personage=“25” height=“6”>...

27 27 DTD: Attributes Types: CDATA= string (Mon | Wed | Fri)= enumeration ID= key IDREF= foreign key IDREFS= foreign keys separated by space others= rarely used Kind: #REQUIRED #IMPLIED= optional “value”= default value “value” #FIXED= the only value allowed

28 28 XML: IDs and References Attributes can be pointers from one object to another –Compare to HTML’s NAME = “foo” and HREF = “#foo” Allows the structure of an XML document to be a general graph, rather than just a tree

29 29 XML: Creating ID’s Give an element E an attribute A of type ID When using tag in an XML document, give its attribute A a unique value Example:

30 30 XML: Creating References To allow objects of type F to refer to another object with an ID attribute, give F an attribute of type IDREF Or, let the attribute have type IDREFS, so the F –object can refer to any number of other objects

31 31 Jane Mary John Jane Mary John XML: IDs and References IDs and references in XML are just syntax

32 32 DTD: ID and IDREF(S) Attributes <!ATTLIS personageCDATA#REQUIRED idID#REQUIRED managerIDREF#REQUIRED managesIDREFS#REQUIRED > <!ATTLIS personageCDATA#REQUIRED idID#REQUIRED managerIDREF#REQUIRED managesIDREFS#REQUIRED > <person age=“25” id=“p29432” manager=“p48293” manages=“p34982 p423234”>....... <person age=“25” id=“p29432” manager=“p48293” manages=“p34982 p423234”>.......

33 33 Use of DTDs 1.Set standalone = “no” 2.Either: a)Include the DTD as a preamble of the XML document, or b)Follow DOCTYPE and the by SYSTEM and a path to the file where the DTD can be found, or c)Mix the two... (e.g. to override the external definition)

34 34 <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document Example (a)

35 35 Assume the BARS DTD is in file bar.dtd Joe’s Bar Bud 2.50 Miller 3.00 … Example (b) Get the DTD from the file bar.dtd

36 36 DTDs as Grammars <!DOCTYPE db [ ]> <!DOCTYPE db [ ]>

37 37 DTDs as Grammars Same thing as: A DTD is a EBNF (Extended BNF) grammar An XML tree is precisely a derivation tree A valid XML document = a parse tree for that grammar db::= (book|publisher)* book::= (title,author*,year?) title::= string author::= string year::= string publisher::= string db::= (book|publisher)* book::= (title,author*,year?) title::= string author::= string year::= string publisher::= string

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

39 39 DTDs as Schemas Not so well suited: impose unwanted constraints on order: – references cannot be constrained –ID/IDREFS can reference any ID can be too vague: –

40 40 DTDs as Schemas No context-dependant typing Cannot distinguish between used car ads and new car ads –Different structure in different contexts dealer UsedCarsNewCars adad adad modelyear

41 41 XML APIs Document Object Model - DOM –Manipulation of XML Data –Provides a representation of an XML Document as a tree –Reads XML Document into memory –http://www.w3.org/DOMhttp://www.w3.org/DOM –Many implementations (Sun JAXP, Apache Xerces, …) Simple API for XML - SAX –Event-based framework for parsing XML data –http://www.saxproject.org/http://www.saxproject.org/

42 42 References Lecture Slides –Jeffrey D. Ullman –http://www-db.stanford.edu/~ullman/dscb/pslides/pslides.htmlhttp://www-db.stanford.edu/~ullman/dscb/pslides/pslides.html –Dan Suciu –http://www.cs.washington.edu/homes/suciu/COURSES/590DS/02xmlsynta x.htmhttp://www.cs.washington.edu/homes/suciu/COURSES/590DS/02xmlsynta x.htm –http://www.cs.washington.edu/homes/suciu/COURSES/590DS/11dtd.htmhttp://www.cs.washington.edu/homes/suciu/COURSES/590DS/11dtd.htm –Alon Levy –http://www.cs.washington.edu/education/courses/csep544/02sp/lectures/l ecture5cut.ppthttp://www.cs.washington.edu/education/courses/csep544/02sp/lectures/l ecture5cut.ppt BRICS XML Tutorial –A. Moeller, M. Schwartzbach –http://www.brics.dk/~amoeller/XML/index.htmlhttp://www.brics.dk/~amoeller/XML/index.html W3C's XML homepage –http://www.w3.org/XMLhttp://www.w3.org/XML XML School: an XML tutorial –http://www.w3schools.com/xmlhttp://www.w3schools.com/xml


Download ppt "CSE 636 Data Integration XML Semistructured Data Document Type Definitions."

Similar presentations


Ads by Google