XML Schema.

Slides:



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

1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
1 XML DTD & XML Schema Monica Farrow G30
XML Schema Definition Language
XML Schemas Lecture 10, 07/10/02. Acknowledgements A great portion of this presentation has been borrowed from Roger Costello’s excellent presentation.
Lecture 14 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
XML Schemas. “Schemas” is a general term--DTDs are a form of XML schemas –According to the dictionary, a schema is “a structured framework or plan” When.
XML Schema Basics SD2520 Databases using XML and Jquery Chapter 12
Introduction to XML This material is based heavily on the tutorial by the same name at
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 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Lecture 15 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
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.
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.
Li Tak Sing COMPS311F. XML Schemas XML Schema is a more powerful alternative to DTD to describe XML document structures. The XML Schema language is also.
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 DTD and XML Schema Discussion Sessions 1A and 1B Session 2.
Schemas 1www.tech.findforinfo.com. What is a Schema a schematic or preliminary plan Description of a structure, details... 2www.tech.findforinfo.com.
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.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 5 XML Schema (Based on Møller and Schwartzbach,
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
XML Schema. Why Validate XML? XML documents can generally have any structure XML grammars define specific document structures Validation is the act of.
EGEE is a project funded by the European Union under contract IST XML Schema 3 – 4 June
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 1 of 36 Objectives In this lesson, you will learn to: * Declare attributes in an.
XML Validation II Schemas Robin Burke ECT 360. Outline Namespaces Documents  Data types XML Schemas Elements Attributes Derived data types RELAX NG.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
XML Schema – Simple Type Web site:
CITA 330 Section 4 XML Schema. XML Schema (XSD) An alternative industry standard for defining XML dialects More expressive than DTD Using XML syntax Promoting.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
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.
ACG 4401 XML Schemas XML Namespaces XLink.
ACG 4401 XML Schemas XML Namespaces XLink.
CMP 051 XML Introduction Session IV
Lecture 9 XML & its applications
XML Schema Languages Dongwon Lee, Ph.D.
Database Systems Week 12 by Zohaib Jan.
2017, Fall Pusan National University Ki-Joune Li
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Discussion on XSD open issues
XML Validation III Schemas
ISSGC’05 XML Schemas (XSD)
دانشكده مهندسي كامپيوتر
Design and Implementation of Software for the Web
CMP 051 XML Introduction Session IV Chapter 10 – Defining Simple Types
DTD and XML Schema.
ece 720 intelligent web: ontology and beyond
CMP 051 XML Introduction Session III
XML Technologies X-Schema.
XML Schema In this first lesson, XML Schema, you will learn to:
Lecture 9 XML & its applications
More XML XML schema, XPATH, XSLT
XML: The new standard -Eric Taylor.
XML Schema Diyar A. Abdulqder
New Perspectives on XML
Presentation transcript:

XML Schema

A successor to DTD XML Schema is a successor to DTD Like DTD, it is used to specify the tags and attributes of an XML-based mark-up language But, unlike DTD, XML Schema has an XML-based syntax itself It is also more powerful that DTD, because It supports data types It supports namespaces

An Example Before we consider the XML Schema language in detail, let’s consider an example usage We will see an XML Schema file We will see two XML documents which claim to be valid according to this schema But only one of them is valid We will a use a tool which identifies the error

Example XML Schema Location: http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd Contents: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cosmos.ucc.ie" elementFormDefault="qualified"> <xs:element name="memo"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

Example XML document Location: http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo1.xml Contents: <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd"> <to>Fred</to> <from>Bill</from> <heading>Meeting tomorrow</heading> <body>It will be in Room 209</body> </memo>

2nd example XML document Location: http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo2.xml Contents: <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd"> <to>Fred</to> <from>Bill</from> <date>May 2, 2008</date> <heading>Meeting tomorrow</heading> <body>It will be in Room 209</body> </memo>

An XML Schema validator The W3C provide an online tool for checking whether an XML document is valid according to an XML Schema Location: http://www.w3.org/2001/03/webdata/xsv

Checking memo1.xml

Checking memo2.xml

A simple XML document <?xml version="1.0" ?> <memo> <to>Fred</to> <from>Bill</from> <heading>Meeting tomorrow</heading> <body>It will be in Room 209</body> </memo>

Referring to a schema <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd “ > <memo> <to>Fred</to> <from>Bill</from> <heading>Meeting tomorrow</heading> <body>It will be in Room 209</body> </memo>

Examining a schema reference <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd “ > The attribute xmlns=“http://cosmos.ucc.ie” specifies that the tag memo belongs to the namespace http://cosmos.ucc.ie

Examining a schema reference (contd.) <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd “ > The attribute xsi:schemaLocation=“http://cosmos.ucc.ie ... ” specifies that the schema for the namespace http://cosmos.ucc.ie is at this URL:

Examining a schema reference (contd. again) <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd “ > The attribute xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” specifies the URI for the namespace xsi which is needed for the schemaLocation attribute

The <schema> element The root element in every XML Schema is the <schema> element It usually contains some attributes, which will be discussed on the following slides Example XML Schema file <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cosmos.ucc.ie" elementFormDefault="qualified“ > ... ... </xs:schema>

Attributes of the <schema> element Example open-tag for <schema> element <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cosmos.ucc.ie" elementFormDefault="qualified“ > The xmlns:xs attribute is needed to specify the URI for the xs prefix which is used with the schema tag name

Attributes of the <schema> element (contd.) Example open-tag for <schema> element <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cosmos.ucc.ie" elementFormDefault="qualified“ > The targetNamespace attribute specifies that this schema is defining the tags and attributes for the namespace whose URI is http://cosmos.ucc.ie

Attributes of the <schema> element (contd.) Example open-tag for <schema> element <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cosmos.ucc.ie" elementFormDefault="qualified“ > The elementFormDefault attribute specifies that XML documents which use this schema must be namespace-qualified

Contents of a <schema> element You will remember that a DTD file contains <!ELEMENT> and <!ATTLIST> declarations Similarly, a XML schema element contains <element> and <attribute> children elements

The <element> element In the XML Schema view of things, there are two types of elements Simple Complex A simple element Can only contain text content – it cannot contain any other elements Also, it cannot have any attributes. A complex element Can contain different kinds of content Can have attributes

Simple elements

Types of simple element As said before, a simple element can only contain text HOWEVER, one advantage of XML Schema over DTD is that we can specify restrictions on the type of text which a simple element can contain The most common types of text are: string decimal integer boolean date time

Defining a simple element Syntax: <xs:element name="xxx" type="yyy"/> Examples extracted from earlier schema <xs:element name="to" type="xs:string"/> <xs:element name=“from" type="xs:string"/> <xs:element name=“heading" type="xs:string"/> <xs:element name=“body" type="xs:string"/> Other examples <xs:element name=“age" type="xs:integer"/> <xs:element name=“dateofBirth" type="xs:date"/>

Revisiting our 2nd example XML document This failed because it included a date Location: http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo2.xml Contents: <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo.xsd"> <to>Fred</to> <from>Bill</from> <date>May 2, 2008</date> <heading>Meeting tomorrow</heading> <body>It will be in Room 209</body> </memo>

Extended schema which includes a date Location: http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/extendedMemo.xsd Contents: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cosmos.ucc.ie" elementFormDefault="qualified"> <xs:element name="memo"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name=“date" type="xs:date"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

Using this new schema Location: http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo2a.xml Contents: <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/extendedMemo.xsd"> <to>Fred</to> <from>Bill</from> <date>May 2, 2008</date> <heading>Meeting tomorrow</heading> <body>It will be in Room 209</body> </memo>

Checking this document: still fails

Online description of XML Schema For more information: http://www.w3.org/XML/Schema

Using the date data type correctly An xs:date: must be specified in one of the forms: yyyy-mm-dd yyyy-mm-ddZ, where Z means GMT yyyy-mm-dd-hh:mm yyyy-mm-dd+hh:mm

Using the date data type correctly Location: http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/memo2b.xml Contents: <?xml version="1.0" ?> <memo xmlns="http://cosmos.ucc.ie" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://cosmos.ucc.ie http://cosmos.ucc.ie/cs1064/jabowen/IPSC/cs4408/xml/schema/extendedMemo.xsd"> <to>Fred</to> <from>Bill</from> <date>2008-05-02</date> <heading>Meeting tomorrow</heading> <body>It will be in Room 209</body> </memo>

Now the document is valid

The time date type A start time could be defined in a schema as follows <xs:element name="start" type="xs:time"/> An xs:time: must be specified in one of the forms: hh:mm:ss hh-mm-ssZ, where Z means GMT hh-mm-ss-hh:mm hh-mm-ss+hh:mm Valid instances would include <start>09:10:10</start> <start>09:30:10.5</start> <start>09:10:10Z</start> <start>09:30:10-06:00</start>

The dateTime date type A start date and time could be defined in a schema as follows <xs:element name="start" type="xs:dateTime"/> An xs:dateTime: must be specified in one of the forms: yyyy-mm-ddThh:mm:ss yyyy-mm-ddThh:mm:ssZ, where Z means GMT yyyy-mm-ddThh:mm:ss-hh:mm yyyy-mm-ddThh:mm:ss+hh:mm Valid instances would include <start>2010-12-24T09:10:10</start> <start>2010-12-24T09:30:10.5</start> <start>2010-12-24T09:10:10Z</start> <start>2010-12-24T09:30:10-06:00</start>

Other time and date data types There are other time and date data types But we will not consider them here

The decimal date type A sum of money could be defined in a schema as follows <xs:element name="salary" type="xs:decimal"/> An xs:decimal: must be specified in one of the forms: ddddddd.dddddd -ddddddd.dddddd +ddddddd.dddddd dddddddd Valid instances would include <accountBalance>3599.57</accountBalance> <accountBalance>+1500.67</accountBalance> <accountBalance>-124.50</accountBalance> <accountBalance>990</accountBalance> <accountBalance>0</accountBalance>

The integer date type A counter could be defined in a schema as follows <xs:element name=“numChildren" type="xs:integer"/> An xs:decimal: must be specified in one of the forms: ddddddd -ddddddd +ddddddd There are other numeric data types but we will not consider them here.

Default and Fixed Values The specification of a simple element type may include a default value OR a fixed value A default value is automatically assigned to an instance of the element type when no other value is specified. <xs:element name="colour" type="xs:string" default="red"/> A fixed value is always automatically assigned to an instance of the element type and no other value can be specified <xs:element name="colour" type="xs:string" fixed="red"/>

Complex elements

A complex element is one that either has attributes or Complex elements A complex element is one that either has attributes or contains other elements, or both Example complex elements <employee id="1345"/> <name><fname>Bertie</fname><sname>Ahern</sname></name> <employee id="1345"/>Bertie Ahern</employee> <text>The capital of Ireland is <city>Dublin</city></text> A complex element can be empty, can have child elements, can contain only text, or can contain a mixture of text and child elements

Specifying complex elements A complex element type can be specified in two different ways, “private” and “public” Example use of “private” complexType specification <xs:element name=“lecturer">   <xs:complexType> …  </xs:complexType> </xs:element> Example use of “public” complexType specification <xs:complexType name="person">…</xs:complexType> <xs:element name=“lecturer" type="person"/> <xs:element name="student" type="person"/> Notice that, in the public specification, the complexType is given a name which can be referenced by several element types, whereas in the private specification, the complexType has no name and is hidden inside one element type specification

Specifying complex elements (contd.) A public complexType can also be used as a base for defining other public complexTypes Example “public” specification <xs:element name=“lecturer" type=“employee"/> <xs:element name="student" type="person"/> <xs:complexType name="person">…</xs:complexType> <xs:complexType name=“employee“> <xs:complexContent>     <xs:extension base="person“> … </xs:extension>   </xs:complexContent> </xs:complexType>

Specifying and extending a complex elements Specifying a complex type <xs:complexType name="person“> <xs:sequence>     <xs:element name="firstname" type="xs:string"/>     <xs:element name="lastname" type="xs:string"/>   </xs:sequence> </xs:complexType> Extending a complex type <xs:complexType name=“employee“> <xs:complexContent>     <xs:extension base="person“> <xs:sequence>         <xs:element name=“grade" type="xs:string"/>         <xs:element name=“salary" type="xs:decimal"/>         </xs:sequence> </xs:extension>   </xs:complexContent>

Specifying an empty complex element Suppose we want to have the following type of element in our XML documents: <model modelid=“999" /> We can specify this empty complex type as follows <xs:element name=“model"> <xs:complexType>     <xs:attribute name=“modelid“ type="xs:positiveInteger"/>   </xs:complexType> </xs:element>

Specifying a complex element with only text content Suppose we want to have the following type of element in our XML documents: <countryCode country=“Ireland“>353</countryCode> We can specify this empty complex type as follows <xs:element name=“countryCode">   <xs:complexType>     <xs:simpleContent>       <xs:extension base="xs:integer">         <xs:attribute name="country" type="xs:string" />       </xs:extension>     </xs:simpleContent>   </xs:complexType> </xs:element>

Specifying a complex element with mixed content Suppose we want to have the following type of element in our XML documents: <note>Dear<person>John></person> we will <operation>contact you soon</operation></note> We can specify this empty complex type as follows <xs:element name=“note">   <xs:complexType mixed="true">     <xs:sequence>       <xs:element name=“person" type="xs:string"/>       <xs:element name=“operation" type="xs:string"/>      </xs:sequence>   </xs:complexType> </xs:element>