ISSGC’05 XML Schemas (XSD)

Slides:



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

XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
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
SDPL 2003Notes 2: Document Instances and Grammars1 2.5 XML Schemas n A quick introduction to XML Schema –W3C Recommendation, May 2, 2001: »XML Schema Part.
Enabling Grids for E-sciencE ISSGC’05 XML documents Richard Hopkins, National e-Science Centre, Edinburgh June 2005.
XML Schema Definition Language
Enabling Grids for E-sciencE ISSGC’05 XML Schemas (XSD) Richard Hopkins, National e-Science Centre, Edinburgh June 2005.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
1 XML Schema Information Retrieval Systems Maria Indrawan 2003.
Unit 4 – XML Schema XML - Level I Basic.
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.
Enabling Grids for E-sciencE Schemas Richard Hopkins National e-Science Centre, Edinburgh February 23 /
SDPL 2002Notes 2: Document Instances and Grammars1 2.5 XML Schemas n A quick introduction to XML Schema –W3C Recommendation, May 2, 2001: »XML Schema Part.
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.
XML and friends Part 2 - XML Schema ELAG 2001 workshop 8 Jan Erik Kofoed © BIBSYS Library Automation.
Session IV Chapter 9 – XML Schemas
Enabling Grids for E-sciencE PPARC Summer School, May 2005 Schemas (and XML) Richard Hopkins, National e-Science Centre, Edinburgh.
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.
SDPL 2005Notes 2.5: XML Schemas1 2.5 XML Schemas n Short introduction to XML Schema –W3C Recommendation, 1 st Ed. May, 2001; 2 nd Ed. Oct, 2004: »XML Schema.
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.
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.
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.
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
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.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
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.
Using XML Schema to define NETCONF Content Sharon Chisholm Alex Clemm TJ Tjong
CSE3201 Information Retrieval Systems XML Schema – Part 2.
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.
SDPL : XML Schemas1 2.5 XML Schemas n Short introduction to XML Schema –W3C Recommendation, 1 st Ed. May, 2001; 2 nd Ed. Oct, 2004: »XML Schema.
XML Schemas Dr. Awad Khalil Computer Science Department AUC.
Practical II – Modifying WSDL (30+ mins)
XML Schema.
ACG 4401 XML Schemas XML Namespaces XLink.
AIXM 5.1 XML Developers' Seminar #2 – Dec 2009
ACG 4401 XML Schemas XML Namespaces XLink.
CMP 051 XML Introduction Session IV
Lecture 9 XML & its applications
Schemas Richard Hopkins National e-Science Centre, Edinburgh
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Discussion on XSD open issues
XML Validation III Schemas
Design and Implementation of Software for the Web
CMP 051 XML Introduction Session IV Chapter 10 – Defining Simple Types
ece 720 intelligent web: ontology and beyond
CMP 051 XML Introduction Session III
XML Technologies X-Schema.
Optimising XML Schema for IODEF Data model
Lecture 9 XML & its applications
New Applications Modeled
XML Schema Diyar A. Abdulqder
New Perspectives on XML
Presentation transcript:

ISSGC’05 XML Schemas (XSD) XML AND SCHEMAS ISSGC’05 XML Schemas (XSD) Richard Hopkins, National e-Science Centre, Edinburgh June 2005

Overview Goals – General appreciation of XML and Schemas Sufficient detail to understand WSDLs Structure Schemas (XSD) General Elements, types and attributes Inter-schema structures Reality check Schemas

Introduction to SCHEMAS XML AND SCHEMAS Introduction to SCHEMAS A Schema defines the syntax for an XML language An XML document can have an associated Schema It is valid if it meets the syntax rules of that schema This can import syntax for (parts of) other languages Much like programming language type declarations, But some peculiarities Has declaration of attributes - needed to define XML documents Three ways to define the “type” of a value Giving the sub-structure directly – anonymous type Referring to a Type definition Referring to an Element definition Allows extension points Quite a complex structure – Is itself an XML document Easier to read than to write Example – Purchase Order document – http://www.gs.unina.it/repository/tuesday-12 Schemas

Validation / Generation XML AND SCHEMAS Validation / Generation Validates Matches <xs:schema …. > …. </> <PO> …. </> Is Validated By Matches Schema – XML document Instance – XML document Schema is a type – defines a range of possible instances The set of all instances which are “validated by the schema” “instance is validated by the schema” – it satisfies the schema definition Alternative terminology – “schema matches the instance” “instance matches the schema” Schemas

ELEMENTS etc. Structure Schemas (XSD) General XML AND SCHEMAS ELEMENTS etc. Structure Schemas (XSD) General Elements, types and attributes Inter-schema structures Reality check Schemas

Main Structure <xs:schema …. XML AND SCHEMAS Main Structure <xs:schema …. xmlns:xs="http://www.w3.org/2001/XMLSchema"> …. <xs:simpleType name="accNoT"> … </> <xs:complexType name="entryT"> … </> <xs:element name="PO"> <xs:complexType> <xs:sequence> <xs:element name="date"> … </> <xs:element name="accNo" type="accNoT"/> <xs:element name="customer"> <xs:complexType> …. </> <xs:element ref="note" minOccurs="0" maxOccurs="3"/> <xs:element name="entry" type="entryT" maxOccurs="unbounded"/> <xs:element name="note"> … </> <PO> <date> <USdate> 10/24/04 </></> <accNo> Z135-ACE</> <customer> <bill> <addr>…</> <terms>7-day</></> <deliver> <addr>…</> </> </> <note> …. </> <note> … </> <entry> … </> </> 1. schema “envelope” - “xs” = schema namespace. Or “xsd” 2. PO - global complex element - a sequence of child elements - Date, accno, customer, note, Entry. An anonymous type 3. Date – see later 4. AccNo – element of global type 5. customer info – Nested complex element 6. note – reference to a global element – same name and type Repeated 0 – 3 times 7. entry – element of global type Repeated 1 or more times Schemas

PRINT VISIBLE COMMENTS OF PREVIOUS SLIDE XML AND SCHEMAS PRINT VISIBLE COMMENTS OF PREVIOUS SLIDE 1. schema “envelope” - “xs” = schema namespace. Or “xsd” 2. PO - global complex element - a sequence of child elements - Date, accno, customer, note, Entry. An anonymous type 3. Date – see later 4. AccNo – element of global type 5. customer info – Nested complex element 6. note – reference to a global element – same name and type Repeated 0 – 3 times 7. entry – element of global type Repeated 1 or more times Schemas

Global Items <xs:schema …> Annotations – … XML AND SCHEMAS Global Items <xs:schema …> … <xs:annotation> <xs:documentation> Here is a Schema</> <xs:simpleType name="accNoT"> … </> <xs:complexType name="entryT"> … </> <xs:element name="PO"> … </> <xs:element name="note"> … </> Annotations – Documentation (also appinfo) Can also go deeper in to annotate parts of structures Global (named) Types – Simple or complex – Use in giving type of element Elements - two roles The instance document can have an instance of this as its root element PO or Note – not what’s intended ! Can be referenced from elsewhere as another way of giving “type” – but must use same name Other things e.g. attributes, groups Order of global items is not significant Schemas

Features of Complex Elements XML AND SCHEMAS Features of Complex Elements <xs:element name="PO"> <xs:complexType> <xs:sequence> … <xs:element name="customer“ nillable=“1”> <xs:complexType> …. </> <xs:element ref="note" minOccurs="0" maxOccurs="3"/> <xs:element name="entry" type="entryT" maxOccurs="unbounded"/> <PO> <date> <USdate> 10/24/04 </></> <accNo> Z135-ACE</> <customer xsi:nil=“true”> </> <note> …. </> <note> … </> <entry> … </> Nillable – can match element with attribute xsi:nil = “true”, and no content Occurrences – minOccurs , maxOccurs. Default is 1..1. max can be “unbounded” This schema item can match N occurrences of the element, Min<=N<=Max Model (feature of type)– Sequence – each component matched in this order But each component may actually match no elements or multiple elements If there are any notes – after customer and before first entry Schemas

Complex Types – Models All – each component matched in any order XML AND SCHEMAS Complex Types – Models <xs:element name="date"> <xs:complexType> <xs:choice> <xs:element name="USdate"> … </> <xs:element name="UKdate“ … /> <PO> <date> <USdate> 10/24/04 </></> …</> <PO> <date> <UKdate> 24/10/04 </></> …</> Model – Sequence – each component matched in this order Choice – one and only one component is matched But each component may actually match no elements or multiple elements All – each component matched in any order Each component must match one or zero elements – maxOccurs=“1” Schemas

Complex Elements – Models XML AND SCHEMAS Complex Elements – Models <PO> … <customer> <bill> <addr>…</> <terms> … </></> <deliver> <addr>…</> </> </> …</> <xs:element name=“customer“ …> <xs:complexType> <xs:all> <xs:element name=“deliver"> … </> <xs:element name=“bill“ … /> <PO> … <customer> <deliver> <addr>…</> </> </> <bill> <addr>…</> <terms> … </></> …</> Model – Sequence – each component matched in this order Choice – one and only one component is matched But each component may actually match no elements or multiple elements All – each component matched in any order – use for “Struct” Each component must match one or zero elements – maxOccurs=“1” Schemas

Complex Types - Extension XML AND SCHEMAS Complex Types - Extension <xs:complexType name=“entryT”> <xs:sequence> <xs:element ref=“note” …/> <xs:element name=“prodCode” …/> <xs:element name=“quant”> …</></> …. <xs:complexType name="XEntryT"> <xs:complexContent> <xs:extension base="entryT"> <xs:element name="notify" type="xs:string"/> <xs:element name="urgency" type="xs:string"/> </></></></> <entry> … <note>….</> <prodCode> …</> <quant>… </></> <Xentry> … <note>….</> <prodCode> …</> <quant>… </> <notify>caretaker</> <urgency>very</></> XentryT inherits the components of entryT - extend the sequence Schemas

Complex Types - Extension XML AND SCHEMAS Complex Types - Extension <xs:complexType name=“entryT”> <xs:sequence> <xs:element ref=“note” …/> <xs:element name=“prodCode” …/> <xs:element name=“quant”> …</></> …. <xs:complexType name=“UrgentEntryT"> <xs:complexContent> <xs:extension base="entryT"> <xs:sequence> </></></></> Extension which adds no content – used to denote a special case Schemas

Simple Elements/Types XML AND SCHEMAS Simple Elements/Types <PO> …. <accNo> Z135-ACE</> … <note> to collect </> ….. </> <xs:simpleType name="accNoT"> <xs:restriction base="xs:string"> … optional restrictions ….</> <xs:element name="PO"> <xs:complexType> <xs:sequence> …. <xs:element name="accNo“ type="accNoT"/> …. <xs:element ref="note" minOccurs="0" maxOccurs="3"/> …. <xs:element name="note"> <xs:simpleType> … optional restrictions …. </> </> Element features Occurrences (local element) Default / Fixed values Nillable Type features Derivation as Restriction Base simple type ultimately a primitive xsd:type Restrictions patterns, enumerations, … Derivation as Union Derivation as List Schemas

Attributes Can associate attributes with a type By in-line definition XML AND SCHEMAS Attributes <PO> ….. <entry collect=“true” > <prodCode>15-75-87</> …. </> <xs:complexType name="entryT"> <xs:sequence> … <xs:element name="prodCode" type="prodCodeT"/> … </> <xs:attribute name="collect" type="xs:boolean" use="optional" default="false"/> </> Can associate attributes with a type By in-line definition By naming a globally declared attribute - see later Attribute has features – Some simple type Default/fixed Use – optional (default), prohibited, required If it has an attribute, it must be a complex type For a naturally complex type, just add it in at the first level For an actually simple type - Schemas

Adding attributes to simple types XML AND SCHEMAS Adding attributes to simple types <xs:attribute name="units" default="metric"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="imperial"/> <xs:enumeration value="metric"/></></></> …… <xs:complexType entryT > <xs:sequence> … <xs:element name="quant“ type=“xs:decimal”/> </></> <PO> ….. <entry collect=“true”> <prodCode>15-75-87</> <quant units=“metric”>17.3</> </> <xs:element name="quant"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:decimal"> <xs:attribute name="units" use="required"/> </> </> … </> Has attribute - is complex type But it is simple content Extends a simple type with an attribute - could be several Schemas

INTER-SCHEMA STRUCTURES XML AND SCHEMAS INTER-SCHEMA STRUCTURES Structure Schemas (XSD) General Elements, types and attributes Inter-schema structures Reality check Schemas

Target Namespace <xs:schema … XML AND SCHEMAS Target Namespace <xs:schema … targetNameSpace= “http://company.org/forms/namespace”> <xs:element name=“PO”> … </> http://company.org/forms/namespace The name of the language for which this schema defines the syntax This schema will only match an instance if its namespace matches - <?xml version="1.0" encoding="UTF-8"?> <it:PO xmlns:it= http://company.org/forms/namespace it.att1=“…”> … </> If schema has no targetNameSpace – it can only match un-qualified names Schemas

Include …www… /Forms/PO.xsd …www… /Forms/main.xsd XML AND SCHEMAS Include …www… /Forms/PO.xsd …www… /Forms/main.xsd <schema targetNameSpace= “…www. …/forms/ns”> <include schemaLocation= “…www…/Forms/Types.xsd"/> <element name=“PO“> ….</></> <schema targetNameSpace= “…www. …/forms/ns”> <include schemaLocation= “…www…/Forms/PO.xsd"/> “…www…/Forms/Inv.xsd"/> …www… /Forms/Types.xsd <schema targetNameSpace= “…www. …/forms/ns”> <simpleType name= “AccNoT“> ….</> ….other types ….</> All must be same target namespace Forms one logical schema as the combination of physically distinct schemas I.e. referencing main as the schema allows document to be an PO or an SE (stock enquiry) Allows individual document definitions to share type definitions …www… /Forms/Inv.xsd <schema targetNameSpace= “…www. …/forms/ns”> <include schemaLocation= “…www…/Forms/Types.xsd"/> <element name=“Inv“> ….</></> Schemas

XML AND SCHEMAS Import Include is to distribute the definition of this namespace (language) over multiple Schema definitions Import is to allow use of other namespaces (languages) in the definition for this language. …www… /Standards.xsd …www… /Forms/PO.xsd <schema targetNameSpace= “…www. …/Standards/ns” > <simpleType name= “USdateT“> ….</> ….other types ….</> <schema targetNameSpace= “…www. …/forms/ns” xmlns:st =“…www…/Standards/ns” > <import namespace= “…www…/Standards/ns” schemaLocation= “…www… /Standards.xsd” > <element name=“PO“> …. <name=“USdate” type=“st:USdateT”\>…</> </></> Must have namespace definition for import’s namespace Schemas

Extension points Web Services needs to accommodate extensibility XML AND SCHEMAS Extension points <xs:complexType name="entryT"> <xs:sequence> <xs:element ref="note" minOccurs="0"/> <xs:element name="prodCode" …/> <xs:element name="quant"> … </> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/></></> <PO xmlns:user=“www. …” > … <entry> <note> …. </> <prodCode> ..</> <quant>….</> <user:chargeto> … </> … </> Web Services needs to accommodate extensibility A PO can be “extended” with client’s own information about an order item – e.g. how the user allocates the cost -This is just reflected back in the Invoice This element will be from the client’s namespace – unknown when writing the schema Covered by an Any element (“wildcard”) The Any element can define the allowed namespaces Extensibility covers two kinds of language enhancement – Specialisation – namespace=“##other” anything but this names space – could view user-PO as a specialisation of PO Versioning – namespace=“##local” this namespace Schemas

REALITY CHECK Structure XML Philosophy Detailed XML Format Namespaces XML AND SCHEMAS REALITY CHECK Structure XML Philosophy Detailed XML Format Namespaces Schemas (XSD) General Elements, types and attributes Inter-schema structures Reality check Schemas

Schema Generality Lowest common denominator – WS-I XML AND SCHEMAS Schema Generality Schemas are a moderately sophisticated type language choice; all; any union; pattern; … More sophisticated than e.g. Java type language Usage of the Schema generality depends on inter-operability issues Low interoperability A configuration table for your particular application Schema only for human consumption User does not write programs that use the table Could use full generality of schema definition language High Interoperability WSDL for your web service Schema used to define the structure of SOAP messages Schema must be usable by any web services toolkit Type structure must be translatable into any programming language type scheme Lowest common denominator – WS-I Schemas

Schemas within WSDLs Complex Elements Simple Elements Excludes Any XML AND SCHEMAS Schemas within WSDLs Complex Elements Sequence for distinctly-named component fields Standard type for Array Simple Elements A collection of standard types Excludes Any Extensions Choice All Repitition / optionality (maxoccurrs, minoccurrs) Mixed content ….. Schemas