XML Schema Primer Seong Jong Choi Multimedia Lab.

Slides:



Advertisements
Similar presentations
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
Advertisements

A Simple Schema Design. First Schema Design Being a Dog Is a Full-Time Job Charles M. Schulz Snoopy Peppermint Patty extroverted beagle Peppermint.
2/9/00 EECS 684: Current Topics in Databases1 ( W3C Working Draft 17 December 1999 )
XML Schemas and Namespaces Lecture 11, 07/10/02. BookStore.dtd.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Introduction to XML Schema Winter Sources XML Schema Part 1: Structures W3C Recommendation 2 May 2001,
1 Print your own copy If you bring it along, hand in with your exam script Do not write anything extra or you will be penalized Student Name: Student Number:
Unit 4 – XML Schema XML - Level I Basic.
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
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.
XML for E-commerce II Helena Ahonen-Myka. XML processing model n XML processor is used to read XML documents and provide access to their content and structure.
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.
Copyright © [2001]. Roger L. Costello. All Rights Reserved. 1 XML Schemas (Primer)
Neminath Simmachandran
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
XML and friends Part 2 - XML Schema ELAG 2001 workshop 8 Jan Erik Kofoed © BIBSYS Library Automation.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer.
IVOA Registry videocon 2004/05/13-14 Gerard Lemson1 Model based schema.
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.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Identity Constraints.
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.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
COS 381 Day 14. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard
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
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
XML Schema (W3C) Thanks to Jussi Pohjolainen TAMK University of Applied Sciences.
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.
Deriving Complex Types In XML Schema By: Roy Navon.
XML Schema Lecture 3. Indicators There are seven indicators: Order indicators: All Choice Sequence Occurrence indicators: maxOccurs minOccurs Group indicators:
Lecture 0 W3C XML Schema. Topics Status Motivation Simple type vs. complex type.
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.
MSc in Communication Sciences Program in Technologies for Human Communication Davide Eynard Facoltà di scienze della comunicazione Università.
eXtensible Markup Language
Querying XML: XQuery, XPath, and SQL/XML in Context
XML Schema Integration
Web servisai III (XML Schemos ir DTD)
G52IWS: Extensible Markup Language (XML)
DLR issues during implementation of CSS SM
Roger L. Costello XML Technologies Course
CMP 051 XML Introduction Session IV
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
XML Technologies Instructors: Geoffrey Fox and Bryan Carpenter
Electrical & Computer Engineering: An Overview
Introduction to XML Schema DoD Users Group Tutorial on XML and Science
Introduction to XML Extensible Markup Language
Many-to-many relationship
.opennet Technologies XML Schema
Jagdish Gangolly State University of New York at Albany
XML Technologies and Applications
DTD and XML Schema.
(with material by Suhit Gupta)
X-Informatics: I-400 and I-590 XML Schema
X-Informatics: I-400 and I-590 XML Schema
Extensible Markup Language
CH 20 XML Schema.
Comparing RDMS to XML Understanding the Differences David Plotkin
XML Schema Diyar A. Abdulqder
Presentation transcript:

XML Schema Primer Seong Jong Choi chois@mmlab.net Multimedia Lab. Dept. of Electrical and Computer Eng. University of Seoul Seoul, Korea

po.xsd 2019-04-19 Seong Jong Choi <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:annotation> <xsd:documentation xml:lang="en"> Purchase order schema for Example.com. Copyright 2000 Example.com. All rights reserved. </xsd:documentation> </xsd:annotation> <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> <xsd:element name="comment" type="xsd:string"/> <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> <xsd:complexType name="USAddress"> <xsd:element name="name" type="xsd:string"/> <xsd:element name="street" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"/> <xsd:element name="zip" type="xsd:decimal"/> <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/> <xsd:complexType name="Items"> <xsd:sequence> <xsd:element name="item" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:element name="productName" type="xsd:string"/> <xsd:element name="quantity"> <xsd:simpleType> <xsd:restriction base="xsd:positiveInteger"> <xsd:maxExclusive value="100"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="USPrice" type="xsd:decimal"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/> </xsd:sequence> <xsd:attribute name="partNum" type="SKU" use="required"/> </xsd:complexType> <!-- Stock Keeping Unit, a code for identifying products --> <xsd:simpleType name="SKU"> <xsd:restriction base="xsd:string"> <xsd:pattern value="\d{3}-[A-Z]{2}"/> </xsd:schema> 2019-04-19 Seong Jong Choi

Schema Element <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> … </xsd:schema> <xsd:schema> … </xsd:schema> XML schema element xmlns:xsd=“http://www.w3.org/2001/XMLSchema” Declaration for XML Schema namespace. The prefix xsd: is used by convention to denote the XML Schema namespace, although any prefix can be used. 2019-04-19 Seong Jong Choi

Declaration vs. Definition Declarations enable elements and attributes with specific names and types (both simple and complex) to appear in document instances. <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> <xsd:element name="comment" type="xsd:string"/> Definitions create new types (both simple and complex) <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> 2019-04-19 Seong Jong Choi

Complex Type vs Simple Type complex types which allow elements in their content and may carry attributes, and simple types which cannot have element content and cannot carry attributes. 2019-04-19 Seong Jong Choi

Declaration <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> <xsd:element name="comment" type="xsd:string"/> The valid XML instance should have elements of “purchaceOrder” and “comment” whose types are “PurchaseOrderType” and “xsd:string.” 2019-04-19 Seong Jong Choi

Definition – complex type <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> Define the complex type “purchaseOrderType” Allow elements & attributes contain a set of element declarations, element references, and attribute declarations. element declarations element reference attribute declaration 2019-04-19 Seong Jong Choi

Definition – complex type <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> all attribute declarations must reference simple types because, unlike element declarations, attributes cannot contain other elements or other attributes. attribute declaration 2019-04-19 Seong Jong Choi

Complex Type Definition - Sequence <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> xsd:sequence the elements must appear in the same sequence (order) in which they are declared. 2019-04-19 Seong Jong Choi

Element Reference <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> This declaration references an existing element, comment, that was declared elsewhere in the purchase order schema. In general, the value of the ref attribute must reference a global element, i.e. one that has been declared under schema rather than as part of a complex type definition. element reference 2019-04-19 Seong Jong Choi

Definition – simple type <!-- Stock Keeping Unit, a code for identifying products --> <xsd:simpleType name="SKU"> <xsd:restriction base="xsd:string"> <xsd:pattern value="\d{3}-[A-Z]{2}"/> </xsd:restriction> </xsd:simpleType> Define the simple type “SKU” Allow no element & no attribute 2019-04-19 Seong Jong Choi

Occurrence Constraints <xsd:element ref="comment" minOccurs="0"/> maxOccurs The maximum number of times an element may appear is determined by the value of a maxOccurs attribute in its declaration. Use “unbounded” to indicate there is no maximum number of occurrences The default value for both the minOccurs and the maxOccurs is 1 if you specify a value for only the minOccurs attribute, it is 0 or 1 if you specify a value for only the maxOccurs attribute, it must be 1 or more. If both attributes are omitted, the element must appear exactly once. Attributes may appear once or not at all Example: Table 1 2019-04-19 Seong Jong Choi

Defining myInteger, Range 10000-99999 Simple Type Examples: Table 2 We use the restriction element to indicate the existing (base) type, and to identify the "facets" that constrain the range of values Defining myInteger, Range 10000-99999 <xsd:simpleType name="myInteger"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="10000"/> <xsd:maxInclusive value="99999"/> </xsd:restriction> </xsd:simpleType> 2019-04-19 Seong Jong Choi

Using the Enumeration Facet Simple Type Using the Enumeration Facet <xsd:simpleType name="USState"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="AK"/> <xsd:enumeration value="AL"/> <xsd:enumeration value="AR"/> <!-- and so on ... --> </xsd:restriction> </xsd:simpleType> 2019-04-19 Seong Jong Choi

Simple Type - List Example Schema <xsd:simpleType name="listOfMyIntType"> <xsd:list itemType="myInteger"/> </xsd:simpleType> An instance <listOfMyInt>20003 15037 95977 95945</listOfMyInt> XML Schema has three built-in list types, they are NMTOKENS, IDREFS, and ENTITIES 2019-04-19 Seong Jong Choi

Simple Type - Union Schema Example An instance <xsd:simpleType name="zipUnion"> <xsd:union memberTypes="USState listOfMyIntType"/> </xsd:simpleType> An instance <zips>CA</zips> <zips>95630 95977 95945</zips> <zips>AK</zips> 2019-04-19 Seong Jong Choi

Anonymous Type Two Anonymous Type Definitions <xsd:complexType name="Items"> <xsd:sequence> <xsd:element name="item" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:element name="productName" type="xsd:string"/> <xsd:element name="quantity"> <xsd:simpleType> <xsd:restriction base="xsd:positiveInteger"> <xsd:maxExclusive value="100"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="USPrice" type="xsd:decimal"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/> </xsd:sequence> <xsd:attribute name="partNum" type="SKU" use="required"/> </xsd:complexType> 2019-04-19 Seong Jong Choi