CS 480: Database Systems Lecture 26 March 18, 2013.

Slides:



Advertisements
Similar presentations
Chapter 23: XML.
Advertisements

An Introduction to XML Based on the W3C XML Recommendations.
1 DTD (Document Type Definition) Imposing Structure on XML Documents (W3Schools on DTDs)W3Schools on DTDs.
1 XML DTD & XML Schema Monica Farrow G30
CS 898N – Advanced World Wide Web Technologies Lecture 21: XML Chin-Chih Chang
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
XML(EXtensible Markup Language). XML XML stands for EXtensible Markup Language. XML is a markup language much like HTML. XML was designed to describe.
Introduction to XML This material is based heavily on the tutorial by the same name at
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
XML Databases and introducing their languages, XQuery, XSLT, and XPath
4/20/2017.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XML Validation I DTDs Robin Burke ECT 360 Winter 2004.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
©Silberschatz, Korth and Sudarshan10.1Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium (W3C) Originally.
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Chapter 10: XML.
Maziar Sanaii Ashtiani – SCT – EMU, Fall 2011/12.
Chapter 23: XML Structure of XML Data XML Document Schema
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
Computing & Information Sciences Kansas State University Friday, 17 Oct 2007CIS 560: Database System Concepts Lecture 21 of 42 Friday, 17 October 2008.
Chapter 10: XML XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data.
Document Type Definitions Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XMLI Structure of XML Data Structure of XML Data XML Document Schema XML Document Schema XPATH XPATH.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
XML. 2 XML- Some Links XML Tutorials – Some Links me=htmlhttp://
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
Of 33 lecture 3: xml and xml schema. of 33 XML, RDF, RDF Schema overview XML – simple introduction and XML Schema RDF – basics, language RDF Schema –
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
XML Name: Niki Sardjono Class: CS 157A Instructor : Prof. S. M. Lee.
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
Chapter 23 XML. 2 Introduction  XML: eXtensible Markup Language (What is a Markup language?)  Defined by the WWW Consortium (W3C)  Originally intended.
Tutorial 13 Validating Documents with Schemas
The Semistructured-Data Model Programming Languages for XML Spring 2011 Instructor: Hassan Khosravi.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
ADT 2010 Introduction to XML, XPath (& XQuery) Chapter 10 in Silberschatz, Korth, Sudarshan “Database System Concepts” Stefan Manegold
Introduction to DTD A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Other Topics 1: Object.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
Chapter 8: XML. 2 XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data.
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.
CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful.
Extensible Markup Language (XML) Pat Morin COMP 2405.
CS 480: Database Systems Lecture 25 March 15, 2013.
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Intro to Relational Model
XML QUESTIONS AND ANSWERS
Chapter 23: XML Database System concepts,6th Ed.
CS 480: Database Systems Lecture 28 March 22, 2013.
XML and Databases.
Chapter 3: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
CSCE 315 – Programming Studio Spring 2013
New Perspectives on XML
DTD (Document Type Definition)
Chapter 2: Intro to Relational Model
Semi-Structured data (XML)
New Perspectives on XML
Presentation transcript:

CS 480: Database Systems Lecture 26 March 18, 2013

XML: Motivation n Data interchange is critical in today’s networked world l Examples:  Banking: funds transfer  Order processing (especially inter-company orders)  Scientific data – Chemistry: ChemML, … – Genetics: BSML (Bio-Sequence Markup Language), … l Paper flow of information between organizations is being replaced by electronic flow of information n Each application area has its own set of standards for representing information n XML has become the basis for all new generation data interchange formats

Comparison with Relational Data n Inefficient: tags, which in effect represent schema information, are repeated n Better than relational tuples as a data-exchange format l Unlike relational tuples, XML data is self-documenting due to presence of tags l Non-rigid format: tags can be added l Allows nested structures l Wide acceptance, not only in database systems, but also in browsers, tools, and applications

Structure of XML Data n Tag: label for a section of data n Element: section of data beginning with and ending with matching n Elements must be properly nested l Proper nesting  … …. l Improper nesting  … …. l Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element. n Every document must have a single top-level element

Example of Nested Elements P-101 …. RS1 Atom powered rocket sled SG2 Superb glue 1 liter 29.95

Motivation for Nesting n Nesting of data is useful in data transfer l Example: elements representing item nested within an itemlist element (no need to do joins to get all the items). n Nesting is not supported, or discouraged, in relational databases l With multiple orders, customer name and address are stored redundantly l normalization replaces nested structures in each order by foreign key into table storing customer name and address information l Nesting is supported in object-relational databases n But nesting is appropriate when transferring data l External application does not have direct access to data referenced by a foreign key

Structure of XML Data n Mixture of text with sub-elements is legal in XML. l Example: This course is being offered for the first time in BIO-399 Computational Biology Biology 3 l Useful for document markup, but discouraged for data representation

Attributes n Elements can have attributes Intro. to Computer Science Comp. Sci. 4 n Attributes are specified by name=value pairs inside the starting tag of an element n An element may have several attributes, but each attribute name can only occur once

Attributes vs. Subelements n Distinction between subelement and attribute l In the context of documents, attributes are part of markup, while subelement contents are part of the basic document contents l In the context of data representation, the difference is unclear and may be confusing  Same information can be represented in two ways – … – CS-101 … l Suggestion: use attributes for identifiers of elements, and use subelements for contents

Namespaces n XML data has to be exchanged between organizations n Same tag name may have different meaning in different organizations, causing confusion on exchanged documents n Specifying a unique string as an element name avoids confusion n Better solution: use unique-name:element-name n Avoid using long unique names all over document by using XML Namespaces … CS-101 Intro. to Computer Science Comp. Sci. 4 …

More on XML Syntax n Elements without subelements or text content can be abbreviated by ending the start tag with a /> and deleting the end tag l n To store string data that may contain tags, without the tags being interpreted as subelements, use CDATA as below l … ]]> Here, and are treated as just strings CDATA stands for “character data”

XML Document Schema n Database schemas constrain what information can be stored, and the data types of stored values n XML documents are not required to have an associated schema n However, schemas are very important for XML data exchange l Otherwise, a site cannot automatically interpret data received from another site n Two mechanisms for specifying XML schema l Document Type Definition (DTD)  Widely used l XML Schema  Newer, increasing use

Document Type Definition (DTD) n The type of an XML document can be specified using a DTD n DTD constraints structure of XML data l What elements can occur l What attributes can/must an element have l What subelements can/must occur inside each element, and how many times. n DTD does not constrain data types l All values represented as strings in XML n DTD syntax l

Element Specification in DTD n Subelements can be specified as l names of elements, or l #PCDATA (parsed character data), i.e., character strings l EMPTY (no subelements) or ANY (anything can be a subelement) n Example n Subelement specification may have regular expressions  Notation: – “|” - alternatives – “+” - 1 or more occurrences – “*” - 0 or more occurrences

University DTD ]>

Attribute Specification in DTD n Attribute specification : for each attribute l Name l Type of attribute  CDATA  ID (identifier) or IDREF (ID reference) or IDREFS (multiple IDREFs) – more on this later l Whether  mandatory (#REQUIRED)  has a default value (value),  or neither (#IMPLIED) n Examples l, or l <!ATTLIST course course_id ID #REQUIRED dept_name IDREF #REQUIRED instructors IDREFS #IMPLIED >

IDs and IDREFs n An element can have at most one attribute of type ID n The ID attribute value of each element in an XML document must be distinct l Thus the ID attribute value is an object identifier n An attribute of type IDREF must contain the ID value of an element in the same document n An attribute of type IDREFS contains a set of (0 or more) ID values. Each ID value must contain the ID value of an element in the same document

University DTD with Attributes n University DTD with ID and IDREF attribute types. · · · declarations for title, credits, building, budget, name and salary · · · ]>

XML Data with ID and IDREF attributes Taylor Watson <course course id=“CS-101” dept name=“Comp. Sci” instructors=“ ”> Intro. to Computer Science 4 …. Srinivasan ….

Limitations of DTDs n No typing of text elements and attributes l All values are strings, no integers, reals, etc. n Difficult to specify unordered sets of subelements l Order is usually irrelevant in databases (unlike in the document-layout environment from which XML evolved) l (A | B)* allows specification of an unordered set, but  Cannot ensure that each of A and B occurs only once n IDs and IDREFs are untyped l The instructors attribute of an course may contain a reference to another course, which is meaningless  instructors attribute should ideally be constrained to refer to instructor elements

XML Schema n XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports l Typing of values  E.g. integer, string, boolean, etc  Also, constraints on min/max values l User-defined, complex types l Many more features, including  uniqueness and foreign key constraints, inheritance n XML Schema is itself specified in XML syntax, unlike DTDs l More-standard representation, but verbose n XML Schema is integrated with namespaces n BUT: XML Schema is significantly more complicated than DTDs.

XML Schema Version of Univ. DTD …. … Contd.

XML Schema Version of Univ. DTD (Cont.) …. n Choice of “xs:” was ours -- any other namespace prefix could be chosen n Element “university” has type “universityType”, which is defined separately l xs:complexType is used later to create the named complex type “UniversityType”

More Features of XML Schema n Attributes specified by xs:attribute tag: l l adding the attribute use = “required” means value must be specified, default value of attribute use is “optional” n Key constraint: “department names form a key for department elements under the root university element: n Foreign key constraint from course to department:

XML Schema n XML Schema offers several benefits over DTDs l It allows the text that appears in elements to be constrained to specific types (numeric, complex, etc.) l It allows user-defined types to be created l It allows uniqueness and foreign-key constraints l It is integrated with namespaces to allow different parts of a document to conform to different schemas. n Other features we haven’t seen that XML Schema has over DTDs l It allows types to be restricted to specialized types, for instance by specifying minimum and maximum values. l It allows complex types to be extended by using a form of inheritance.