CH 20 XML Schema.

Slides:



Advertisements
Similar presentations
XML Schema Heewon Lee. Contents 1. Introduction 2. Concepts 3. Example 4. Conclusion.
Advertisements

What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
 Fundamentals of Web Design.  Describe the history and theory of XHTML  Understand the rules for creating valid XHTML documents  Apply a DTD to an.
1 XML DTD & XML Schema Monica Farrow G30
XML Schemas Microsoft XML Schemas W3C XML Schemas.
XML e X tensible M arkup L anguage 1/23.
XML Schemas Lecture 10, 07/10/02. Acknowledgements A great portion of this presentation has been borrowed from Roger Costello’s excellent presentation.
DECO 3002 Advanced Technology Integrated Design Computing Studio Tutorial 6 – XML Schema School of Architecture, Design Science and Planning Faculty of.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Unit 4 – XML Schema XML - Level I Basic.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Introduction to XML: Part I By Sandeep Jangity CS 157B, Section 2 Dr. Lee.
17 Apr 2002 XML Schema Andy Clark. What is it? A grammar definition language – Like DTDs but better Uses XML syntax – Defined by W3C Primary features.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
Lecture 15 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 1 Lecturer.
XML Schema Vinod Kumar Kayartaya. What is XML Schema?  XML Schema is an XML based alternative to DTD  An XML schema describes the structure of an XML.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Dr. Azeddine Chikh IS446: Internet Software Development.
Neminath Simmachandran
CSE4500 Information Retrieval Systems XML Schema – Part 1.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
XML A Single Entity. xml a single entity Objectives Objectives :  understand the data model  describe the XML Document  describe the XML Schema  describe.
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
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.
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 –
Beginning XML 4th Edition. Chapter 5: XML Schemas.
New Perspectives on XML, 2nd Edition
XML Schema. Why Schema? To define a class of XML documents Serve same purpose as DTD “Instance document" used for XML document conforming to schema.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
XML Schema (W3C) Thanks to Jussi Pohjolainen TAMK University of Applied Sciences.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
CSE 6331 © Leonidas Fegaras XML Schema 1 XML Schema Leonidas Fegaras.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content.
XML Schema Lecture 3. Indicators There are seven indicators: Order indicators: All Choice Sequence Occurrence indicators: maxOccurs minOccurs Group indicators:
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
XML SCHEMA 1 CH 20. Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving.
Web Services: Principles & Technology Slide 3.1 Chapter 3 Brief Overview of XML COMP 4302/6302.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
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.
MSc in Communication Sciences Program in Technologies for Human Communication Davide Eynard Facoltà di scienze della comunicazione Università.
XML Schemas Dr. Awad Khalil Computer Science Department AUC.
eXtensible Markup Language
G52IWS: Extensible Markup Language (XML)
XML QUESTIONS AND ANSWERS
Eugenia Fernandez IUPUI
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Introduction to XML: Part I
Introduction to XML Extensible Markup Language
ece 720 intelligent web: ontology and beyond
New Perspectives on XML
Chapter 13 XML Yingcai Xiao.
Extensible Markup Language
Working with Namespaces and Schemas
XML Schema Primer Seong Jong Choi Multimedia Lab.
New Perspectives on XML
Presentation transcript:

CH 20 XML Schema

Objective What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving simple types

What’s wrong with DTDs? XML is being used for object serialization, stock trading, remote procedure calls, vector graphics, and many more things First issue - DTD lack data type, especially for element content - DTD can’t say that a PRICE element must contain a number There’s no way to say that a MONTH element must be an integer between 1 and 12 There’s no way to indicate that a TITLE must contain between 1 and 255 characters

What’s wrong with DTDs? Cont… Data type is not needed for SGML was aimed For computer-to-computer exchange of information, data type is needed 2. The second problem is that DTDs have an unusual non-XML syntax Parsers and APIs that read an XML document can’t read a DTD

What’s wrong with DTDs? Cont… This above example is not a legal XML. Reason You can’t begin an element name with an exclamation point TITLE is not an attribute. Neither is (#PCDATA) 3. The third problem is that DTDs are only marginally extensible and don’t scale very well <!ELEMENT TITLE (#PCDATA)>

What’s wrong with DTDs? Cont… It’s difficult to combine independent DTDs together in a sensible way XML applications can be defined before the entire DTD becomes completely unmanageable and incomprehensible 4. DTDs don’t allow you to do things that it really feels like you ought to be able to do

What’s wrong with DTDs? Cont… DTDs cannot enforce the order or number of child elements in mixed content You can’t enforce constraints such as each PARAGRAPH element must begin with exactly one SUMMARY element that is followed by plain text

What’s wrong with DTDs? Cont… Schemas are an attempt to solve all these problems by defining a new XML-based syntax for describing the permissible contents of XML documents that includes the following Powerful data typing including range checking Namespace-aware validation based on namespace URIs rather than on prefixes Extensibility and scalability

What Is a Schema? Schema simply mean form or shape Schema was a description of all the tables in a database(Oracle, MySQL, etc..) and the fields in the table Schema also described what type of data each field could contain. E.g. CHAR,INT, DATE and so on. An XML Schema describes the structure of an XML document Different kinds of schemas from different technologies, including vocabulary schemas, RDF schemas, organizational schemas, X.500 schemas, and of course, XML schemas

The W3C XML Schema Language Was created by the W3C XML Schema Working Group based on many different submissions from a variety of companies and individuals There are no known patent, trademark, or other intellectual property restrictions that would prevent you from doing anything you might reasonably want to do with schemas

Hello Schemas cont… Schema can be written and saved in any text editor that knows how to save Unicode files Schema documents are XML documents and have all the privileges and responsibilities of other XML documents

Hello Schemas The greeting schema <?xml version=”1.0”?> Hello XML! </GREETING> <?xml version=”1.0”?> <xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <xsd:element name=”GREETING” type=”xsd:string”/> </xsd:schema> Save as .xsd

Hello Schemas The root element of this and all other schemas is schema This must be in the http://www.w3.org/2001/XMLSchema namespace Namespace is bound to the prefix xsd or xs Elements are declared using xsd:element elements

Hello Schemas The name attribute specifies which element is being declared This xsd:element element also has a type attribute whose value is the data type of the element To attach a schema to a document, add an xsi:noNamespaceSchemaLocation attribute to the document’s root element

Complex Types The W3C XML Schema Language divides elements into complex and simple types A simple type element is one such as GREETING that can only contain text and does not have any attributes It cannot contain any child elements Complex type elements can have attributes and can have child elements Most documents need a mix of both complex and simple elements

Complex Types cont… <?xml version=”1.0”?> yesiam.xml <?xml version=”1.0”?> <SONG xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”song.xsd”> <TITLE>Yes I Am</TITLE> <COMPOSER>Melissa Etheridge</COMPOSER> <PRODUCER>Hugh Padgham</PRODUCER> <PUBLISHER>Island Records</PUBLISHER> <LENGTH>4:24</LENGTH> <YEAR>1993</YEAR> <ARTIST>Melissa Etheridge</ARTIST> <PRICE>$1.25</PRICE> </SONG>

Complex Types cont… Schema that describes the xml song.xsd <?xml version=”1.0”?> <xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <xsd:element name=”SONG” type=”SongType”/> <xsd:complexType name=”SongType”> <xsd:sequence> <xsd:element name=”TITLE” type=”xsd:string”/> <xsd:element name=”COMPOSER” type=”xsd:string”/> <xsd:element name=”PRODUCER” type=”xsd:string”/> <xsd:element name=”PUBLISHER” type=”xsd:string”/> <xsd:element name=”LENGTH” type=”xsd:string”/> <xsd:element name=”YEAR” type=”xsd:string”/> <xsd:element name=”ARTIST” type=”xsd:string”/> <xsd:element name=”PRICE” type=”xsd:string”/> </xsd:sequence> </xsd:complexType> </xsd:schema>

Complex Types cont… The xsd:complexType element defines a new type

Complex Types cont… minOccurs and maxOccurs Specify the minimum and maximum number of instances of the element that may appear at that point in the document The value of each attribute is an integer greater than or equal to zero The maxOccurs attribute can also have the value unbounded unbounded to indicate that an unlimited number of the particular element may appear See List 20-7

Complex Types cont… This schema says that every SongType element must have, in order: 1. Exactly one TITLE (minOccurs=”1” maxOccurs=”1”) 2. At least one, and possibly a great many, COMPOSERs (minOccurs=”1” maxOccurs=”unbounded”) 3. Any number of PRODUCERs, although possibly no producer at all (minOccurs=”0” maxOccurs=”unbounded”) 4. Either one PUBLISHER or no PUBLISHER at all (minOccurs=”0” maxOccurs=”1”) 5. Exactly one LENGTH (minOccurs=”1” maxOccurs=”1”) 6. Exactly one YEAR (minOccurs=”1” maxOccurs=”1”) 7. At least one ARTIST, possibly more (minOccurs=”1” 8. An optional PRICE, (minOccurs=”0” maxOccurs=”1”)

Complex Types cont… This is much more flexible and easier to use than the limited ?, *, and + that are available in DTDs If minOccurs and maxOccurs are not present, the default value of each is 1

Complex Types cont… Element content When elements contain other elements Listing 20-9

Complex Types cont… Element Content <xsd:complexType name=”ComposerType”> <xsd:sequence> <xsd:element name=”NAME” type=”xsd:string”/> </xsd:sequence> </xsd:complexType> <xsd:complexType name=”ProducerType”> <TITLE>Hot Cop</TITLE> <COMPOSER> <NAME>Jacques Morali</NAME> </COMPOSER> <NAME>Henri Belolo</NAME> <NAME>Victor Willis</NAME> <PRODUCER> </PRODUCER> <PUBLISHER>PolyGram Records</PUBLISHER> <LENGTH>6:20</LENGTH> <YEAR>1978</YEAR> <ARTIST>Village People</ARTIST> </SONG>

Complex Types cont… Sharing content models <TITLE>Hot Cop</TITLE> <COMPOSER> <NAME>Jacques Morali</NAME> </COMPOSER> <NAME>Henri Belolo</NAME> <NAME>Victor Willis</NAME> <PRODUCER> </PRODUCER> <PUBLISHER>PolyGram Records</PUBLISHER> <LENGTH>6:20</LENGTH> <YEAR>1978</YEAR> <ARTIST>Village People</ARTIST> </SONG> <xsd:complexType name=“PersonType”> <xsd:sequence> <xsd:element name=”NAME” type=”xsd:string”/> </xsd:sequence> </xsd:complexType>

Complex Types cont… Mixed Content <xsd:complexType name=”PersonType”> <xsd:sequence> <xsd:element name=”NAME”> <xsd:complexType mixed=”true”> <xsd:element name=”GIVEN” type=”xsd:string”/> <xsd:element name=”FAMILY” type=”xsd:string”/> </xsd:sequence> </xsd:complexType> </xsd:element> <COMPOSER> <NAME> Mr. <GIVEN>Jacques</GIVEN> <FAMILY>Morali</FAMILY> Esq. </NAME> </COMPOSER> Mr. <GIVEN>Henri</GIVEN> L. <FAMILY>Belolo</FAMILY>, M.D. Mr. <GIVEN>Victor</GIVEN> C. <FAMILY>Willis</FAMILY> <PRODUCER> Mr. <GIVEN>Jacques</GIVEN> S. <FAMILY>Morali</FAMILY> </PRODUCER>

Complex Types cont… Mixed Content de <xsd:complexType name=”PersonType”> <xsd:sequence> <xsd:element name=”NAME”> <xsd:complexType mixed=”true”> <xsd:element name=”GIVEN” type=”xsd:string”/> <xsd:element name=”FAMILY” type=”xsd:string”/> </xsd:sequence> </xsd:complexType> </xsd:element>

Simple Types xsd:gYear and xsd:duration <xsd:element name=”LENGTH” type=”xsd:duration”/> <xsd:element name=”YEAR” type=”xsd:gYear”/> <xsd:element name=”ARTIST” type=”xsd:string” maxOccurs=”unbounded”/> <xsd:element name=”PRICE” type=”xsd:string” minOccurs=”0”/> </xsd:sequence> </xsd:complexType> xsd:gYear and xsd:duration These declarations say that it’s no longer okay for the YEAR and LENGTH elements to contain just any old string of text Instead, they must contain strings in particular formats

Simple Types There are 44 built-in simple types in the W3C XML Schema Language These can be unofficially divided into seven groups ✦ Numeric types ✦ Time types ✦ XML types ✦ String types ✦ The boolean type ✦ The URI reference type ✦ The binary types Go to the Book for Examples

references Schema http://www.w3schools.com/schema/ Attribute http://www.w3schools.com/schema/schema_simple_attributes.asp