XML and Databases 198 541 XML Motivation XML
XML and Databases 198: 541
XML Motivation
XML Motivation Huge amounts of unstructured data on the web: HTML documents w No structure information w Only format instructions (presentation) Integration of data from different sources w Structural differences Closely related to semistructured data
Semistructured Data Integration of heterogeneous sources Data sources with non rigid structures w Biological data w Web data Need for more structural information than plain text, but less constraints on structure than in relational data
Characteristics of Semistructured Data Missing or additional tuples Multiple attributes Different types in different objects Heterogeneous collection Self-describing, irregular data with no apriori structure
HTML Document Example Type of information <h 1> Bibliography </h 1> Title <p> <i> Foundations of Databases </i> Authors Abiteboul, Hull, Vianu Year Addison Wesley, 1995 <p> <i> Data on the Web </i> Abiteoul, Buneman, Suciu book Morgan Kaufmann, 1999
The Idea Behind XML Easily support information exchange between applications / computers Reuse what worked in HTML w Human readable w Standard w Easy to generate and read But allow arbitrary markup Uniform language for semistructured data w Data Management
XML
XML e. Xtensible Markup Language Universal standard for documents and data w Defined by W 3 C Set of emerging technologies w XLink, XPointer, XSchema, DOM, SAX, XPath, XQuery, …
XML gives a syntax, not a semantic XML defines the structure of a document, not how it is processed Separate structural information from format instructions
XML Example <bibliography> <book> <title> Foundations… </title> <author> Abiteboul </author> <author> Hull </author> <author> Vianu </author> <publisher> Addison Wesley </publisher> <year> 1995 </year> </book> … </bibliography>
XML Terminology Tags: book, title, author, … w w Start tag: <book> End Tag: </book> Elements are nested Empty Element w <reviews></reviews> => <reviews/> XML Document: single root element XML Document is well formed: matching tags
XML Attributes are <name, value> pairs that characterize an element. <book price = “ 55” currency = “USD”> <title> Foundations of Databases </title> <author> Abiteboul </author> … <year> 1995 </year> </book> Can define oid, but they are just syntax
More XML Text can be CDATA or PCDATA Entity References: &: &, >: >, … Processing Instructions: <? blink? > Comments: <!-- comment text -->
Well Formed XML Documents Elements must be properly nested <book><title> Foundations of Databases </title></book> But Not: <book><title> Foundations of Databases </book></title> There must be a unique root element Elements can be of w ‘element content’ w or ‘mixed content’: w <title>This is <b>Mixed</b>Content</title>
XML: Potential Flexible enough to represent anything w Stock market, DNA, Music, Chemicals w Weather information w Wireless network configuration Enables easy information exchange w Between companies w Within companies Standard: everybody uses the same technology
XML: Limitations XML is only a syntax for documents We need tools! w Editors and parsers w Programming APIs (for Java, C++, etc. ) w Languages to manipulate XML (how many books? ) w Schemas (What is a book like? ) w Storage (What if you have a lot of XML? ) w Transfer protocols (How do you exchange it? ) w What about XML in Chinese…? w How can XML fit into my phone…? w Query processing? w…
XML Schema Language
DTDs: Document Type Descriptors Similar to a schema Grammar describing constraints on document structure and content <!ELEMENT Book (title, author*)> <!ELEMENT title #PCDATA> <!ELEMENT author (name, address, age? )> <!ATTLIST Book id ID #REQUIRED> <!ATTLIST Book pub IDREF #IMPLIED> XML Documents can be validated against a DTD
Shortcomings of DTDs Useful for documents, but not so good for data: No support for structural re-use w Object-oriented-like structures aren’t supported No support for data types w Can’t do data validation Can have a single key item (ID), but: w w w No support for multi-attribute keys No support foreign keys (references to other keys) No constraints on IDREFs (reference only a Section)
XSchema In XML format Includes primitive data types (integers, strings, dates, …) Supports value-based constraints (integers > 100) Inheritance Foreign keys …
Example of XSchema <schema version=“ 1. 0” xmlns=“http: //www. w 3. org/1999/XMLSchema”> <element name=“author” type=“string” /> <element name=“date” type = “date” /> <element name=“abstract”> <type> … </type> </element> <element name=“paper”> <type> <attribute name=“keywords” type=“string”/> <element ref=“author” min. Occurs=“ 0” max. Occurs=“*” /> <element ref=“date” /> <element ref=“abstract” min. Occurs=“ 0” max. Occurs=“ 1” /> <element ref=“body” /> </type> </element> </schema>
XML Storage
Storing XML Data Different approaches: w Storing as text w Using RDBMS w Using a native system Tailored for XML, (NATIX, Tamino, Ipedo, etc. ) Performance of the various approaches depends on your application
Storing XML as Text Simple Easy to compress No updates Need to parse the document every time it is needed
Storing XML in RDBMS Uses existing RDBMS techniques Costly in space, takes time to reconstruct original document Example techniques: w Schema with 2 relations: tag and value w Schema with n relations: 1 per element name
Accessing and Querying XML Data
XML as a Tree: DOM = Document Object Model Class hierarchy serving as an API to XML trees Methods of those classes can be used to manipulate XML (e. g. , Node: : child, Node: : name) Can be used from Java, C++ to develop XML applications. Each node has an identity (i. e. , a unique identifier) in the whole document
XML as a DOM Tree Class hierarchy(node, element attribute) bibliography book title author Foundations Abiteboul of Databases author Hull book author publisher Vianu Addison Wesley year 1995
XML as a Stream: SAX XML document = event stream. E. g. , w Opening tag ‘book’ w Opening tag ‘title’ w Text “Foundations of databases” w Closing tag ‘title’ w Opening tag ‘author’ w Etc. SAX allow you to associate actions with those events to build applications Very efficient since it corresponds to events during parsing, but not always sufficient.
XPath Language for navigating in an XML document (seen as a tree) One root node types of nodes: root, element, text, attribute, comment, … XPath expression defines navigation in the tree following axis: child, descendant, parent, ancestor, …
XPath: Examples Find all the titles of all the books: w //book/title Find the title of all books written by Charles Dickens w //book[author=“Charles Dickens”]/title Find the title of the first section in the second chapter in “Great Expectations” w //book[title=“Great Expectations”]/chapter[2]/section[1]/title Find the title of all sections that come after the second chapter in “Great Expectations”: w //book[title=“Great Expectations”]/chapter[2]/following: : section/title
Querying XML Data Need for a language to query XML data Should yield XML output Should support standard query operations No schema required Several work on an XML query language: XML-QL, XQuery, . .
XQuery XPath included in XQuery FLWR expressions: for let where return FOR $x IN document("bib. xml")/bib/book WHERE $x/year > 1995 RETURN $x/title Result: <title> abc </title> <title> def </title> <title> ghi </title>
How to process XML Queries? Use indexes n n Need to identify nodes Need to know relations between nodes Labeling Schemes n n Dewey encoding Prefix-Postfix encoding Twigstack
Web Services
What are Web Services Programming interfaces for application to application communication on the Web n n n platform-independent, language-independent object model-independent Possibility to activate methods on remote web servers (RPC) 2 main applications n n E-commerce Access to remote data
XML and Web Services Exchange of information between application is in XML w Input and Result w Use of SOAP to generate messages Descriptions of the web service functionality given in XML, according to the WSDL schema Web Services standards use XML heavily
Conclusions XML: a very active area n n Many research directions Many applications Standards not finalized yet: n n n XQuery XML Schema Web Services…
Some Important XML Standards XSL/XSLT: presentation and transformation standards RDF: resource description framework (metainfo such as ratings, categorizations, etc. ) XPath/XPointer/XLink: standard for linking to documents and elements within Namespaces: for resolving name clashes DOM: Document Object Model for manipulating XML documents SAX: Simple API for XML parsing …
References XML w http: //www. w 3. org/XML/ w Sudarshan S. Chawathe: Describing and Manipulating XML Data. IEEE Data Engineering Bulletin 22(3)(1999) XML Standards w http: //www. w 3. org/ (XSL, XPath, XSchema, DOM…) Storing XML Data w Daniela Florescu, Donald Kossmann: Storing and Querying XML Data using an RDMBS. IEEE Data Engineering Bulletin 22(3)(1999) w Hartmut Liefke, Dan Suciu: XMILL: An Efficient Compressor for XML Data. SIGMOD Conference 2000 XQuery w http: //www. w 3. org/TR/xquery/ w Peter Fankhauser: XQuery Formal Semantics: State and Challenges. SIGMOD Record 30(3)(2001) Web Services w http: //www. w 3. org/2002/ws/
- Slides: 41