XML Technologies Instructors: Geoffrey Fox and Bryan Carpenter

Slides:



Advertisements
Similar presentations
Managing XML and Semistructured Data Lecture 12: XML Schema Prof. Dan Suciu Spring 2001.
Advertisements

4 XML Schema.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
XML 6.5 XML Schema (XSD) 6. What is XML Schema? The origin of schema  XML Schema documents are used to define and validate the content and structure.
CSE 636 Data Integration XML Schema. 2 XML Schemas W3C Recommendation: Generalizes DTDs Uses XML syntax Two documents: structure.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
XML Simple Types CSPP51038 shortcourse. Simple Types Recall that simple types are composed of text-only values. All attributes are of simple type Elements.
XML Schema Matthias Hauswirth. Agenda 4 W3C Process 4 XML Schema Requirements 4 The Specifications 4 Schema Tools.
1 XML Schemas Marco Mesiti This Presentation has been extracted from Roger L. Costello (XML Technologies Course)
XML Schemas and Namespaces Lecture 11, 07/10/02. BookStore.dtd.
Software Engineering Recitation 2 Suhit Gupta. Today we will be covering… XML II Sockets, Server – Client relationships, Servers capable of handling multiple.
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 Notes Lecture 13, 07/16/02. (see example05)
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,
Introduction to XML This material is based heavily on the tutorial by the same name at
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
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.
IS432 Semi-Structured Data Lecture 3: XSchema Dr. Gamal Al-Shorbagy.
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.
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.
Creating Data Schemas Presentation by Chad Borer 2/6/2006.
XML Syntax - Writing XML and Designing DTD's
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.
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
Management of XML and Semistructured Data Lecture 11: Schemas Wednesday, May 2nd, 2001.
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
Primer on XML Schema CSE 544 April, XML Schemas Generalizes DTDs Uses XML syntax Two parts: structure and datatypes Very complex –criticized –alternative.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
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.
Lecture 0 W3C XML Schema. Topics Status Motivation Simple type vs. complex type.
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.
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.
Extensible Markup Language (XML) Pat Morin COMP 2405.
eXtensible Markup Language
G52IWS: Extensible Markup Language (XML)
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Introduction to XML Schema DoD Users Group Tutorial on XML and Science
.opennet Technologies XML Schema
Jagdish Gangolly State University of New York at Albany
THE DATATYPES OF XML SCHEMA A Practical Introduction
XML Technologies and Applications
X-Informatics: I-400 and I-590 XML Schema
X-Informatics: I-400 and I-590 XML Schema
XML Schema Primer Seong Jong Choi Multimedia Lab.
Document Type Definition (DTD)
New Perspectives on XML
Presentation transcript:

XML Technologies Instructors: Geoffrey Fox and Bryan Carpenter Dept. of Computer Science School of Computational Science and Information Technology 400 Dirac Science Library Florida State University Tallahassee Florida 32306-4120 http://www.csit.fsu.edu Nancy McCracken, Ozgur Balsoy http://aspen.csit.fsu.edu/webtech/xml/ 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Outline XML Schema based on http://www.w3.org/TR/xmlschema-0/ We cover all the topics in this primer Basic Schema Groups Namespaces Include Derived types import 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

XML Schema PO Example po.xml I <?xml version="1.0"?> <purchaseOrder orderDate="1999-10-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <billTo country="US"> <name>Robert Smith</name> <street>8 Oak Avenue</street> <city>Old Town</city> <state>PA</state> <zip>95819</zip> </billTo> Need to add mechanism to associate schema with this XML instance 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

XML Schema PO Example po.xml II <comment>Hurry, my lawn is going wild!</comment> <items> <item partNum="872-AA"> <productName>Lawnmower</productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum="926-AA"> <productName>Baby Monitor</productName> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </items> </purchaseOrder> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

The Purchase Order Schema, po.xsd I <xsd:schema xmlns:xsd="http://www.w3.org/2000/08/XMLSchema"> <xsd:annotation> <xsd:documentation> 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> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

The Purchase Order Schema, po.xsd II <xsd:complexType name="USAddress"> <xsd:sequence> <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:sequence> <xsd:attribute name="country" type="xsd:NMTOKEN" use="fixed" value="US"/> </xsd:complexType> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

The Purchase Order Schema, po.xsd III <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"/> </xsd:complexType> Anonymous type quantity Specify item 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

The Purchase Order Schema, po.xsd IV </xsd:element> <!– End item specification  </xsd:sequence> <!– End sequence for items specification  </xsd:complexType> <!– End items specification  <!-- 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> </xsd:schema> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Comments on po.xsd The prefix xsd: is Namespace specified by xmlns:xsd=http://www.w3.org/2000/08/XMLSchema The label xsd is conventional; you could use a different one Schema does two types of things: Defines new types of elements or attributes e.g. PurchaseOrderType with xsd:complexType or xsd:simpleType Defines internal elements and attributes for tags e.g. PurchaseOrder using xsd:element and xsd:attribute So an element like shipTo in po.xml has at most one attribute country which if it appears must have value US. The elements name, street, city, state, zip must appear in this order and the first four are strings; zip is a xsd:decimal 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

xsd:complexType Example Anything of PurchaseOrderType is allowed one attribute (orderDate) of type xsd:date. Further it must consists of 4 elements shipTo, billTo, comment and items in that order comment can be absent as minOccurs = 0 Note that comment is a global element defined in the schema. It is accessed by ref= rather than type= One can define global elements or attributes which cannot themselves use ref (global elements are particularly important if one imports this schema into other schema as only global components can be re-used) minOccurs and maxOccurs have default values of 1 and so shipTo, billTo and items must appear once and once only 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Specifying xsd:element and xsd:attribute Any xsd:element tag can have attribute minOccurs, maxOccurs, fixed and default Any xsd:attribute can have attribute use and value Note attributes can NEVER appear more than once - means not present 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Simple Types Attributes must be Simple Types; Elements can be complex or simple types Simple types cannot themselves have attributes or contain other elements The xsd:restriction tag allows you to build new simple types by adding constraints to existing simple types. These constraints are specified by a set of “constraining facets” xsd:minInclusive and xsd:maxInclusive restrict 10000 <= myInteger <= 99999 xsd:pattern restricts using a regular expression to 3 single digits followed by two capital letters 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Constraining Facets These are defined in http://www.w3.org/TR/2000/CR-xmlschema-2-20001024/ and are length, minLength, maxLength, pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minExclusive, minInclusive, precision, scale, encoding, duration, period Tables tell you which constraining facets can be used with which simple type enumeration can be used with all simple types except boolean. In example below, you could define a USState simple type which could take any of conventional abbreviations of the US States 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Simple Types Built In to XML Schema I Simple Type Examples (delimited by commas) string Confirm this is electric CDATA Confirm this is electric token Confirm this is electric byte -1, 126 unsignedByte 0, 126 binary 62696E617279 integer -126789, -1, 0, 1, 126789 positiveInteger 1, 126789 negativeInteger -126789, -1 nonNegativeInteger 0, 1, 126789 nonPositiveInteger -126789, -1, 0 int -1, 126789675 unsignedInt 0, 1267896754 long -1, 12678967543233 unsignedLong 0, 12678967543233 short -1, 12678 unsignedShort 0, 12678 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Simple Types Built In to XML Schema II decimal -1.23, 0, 123.4, 1000.00 float -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN double -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN boolean true, false time 13:20:00.000, 13:20:00.000-05:00 timeInstant 1999-05-31T13:20:00.000-05:00 [May 31st 1999 at 1.20pm Eastern Standard Time which is 5 hours behind Coordinated Universal Time] timePeriod 1999-05-31T13:20 timeDuration P1Y2M3DT10H30M12.3S [1 year, 2 months, 3 days, 10 hours, 30 minutes, 12.3 seconds] date 1999-05-31 month 1999-05 [May 1999] year 1999 [1999] century 19 [the 1900's] recurringDay ----31 [every 31st day] recurringDate --05-31 [every May 31st] recurringDuration --05-31T13:20:00 [May 31st every year at 1.20pm Coordinated Universal Time, format similar to timeInstant] Red is Note 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Simple Types Built In to XML Schema III Simple Type Examples (delimited by commas) Notes in [] Name shipTo [XML 1.0 Name type] QName po:USAddress [XML Namespace QName] NCName USAddress [XML Namespace NCName, i.e. a QName without the prefix and colon] uriReference http://www.example.com/, http://www.example.com/doc.html#ID5 language en-GB, en-US, fr [valid values for xml:lang as defined in XML 1.0] ID [XML 1.0 ID attribute type] IDREF [XML 1.0 IDREF attribute type] IDREFS [XML 1.0 IDREFS attribute type] ENTITY [XML 1.0 ENTITY attribute type] ENTITIES [XML 1.0 ENTITIES attribute type] NOTATION [XML 1.0 NOTATION attribute type] NMTOKEN US, Brésil [XML 1.0 NMTOKEN attribute type] NMTOKENS US UK, Brésil Canada Mexique [XML 1.0 NMTOKENS attribute type, i.e. a whitespace separated list of NMTOKEN's] 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 List Types List types are gotten from Simple types as white space separated atomic types NMTOKENS IDREFS and ENTITIES are built-in list types <listofMyInt>20003 15038 95976 95942</listofMyInt> Length, minLength, maxLength and enumeration are good facets of list types <sixStates>PA NY CA FL LA AK</sixStates> is an example 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Anonymous and Union types Union types define elements or attributes whose value can fall in union of one or more atomic types Anonymous types are declared as for item and quantity in our earlier example without a type attribute (page 7) Examples: <zips>CA</zips> <zips>32308 32306</zips> Use <xsd:complexType> Or <xsd:simpleType> after an xsd:element tag without a type= attribute 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Adding Attributes to Simple Types We used <xsd:element name="USPrice" type="xsd:decimal"/> in po.xsd. Suppose we wish to give this an attribute to specify currency. This is done by deriving a new complex type from the simple type decimal internationalPrice is defined as an anonymous type by With example <internationalPrice currency=“EUR” >123.4 </internationalPrice> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Mixed Content The mixed=“true” attribute in xsd:complexType allows one to specify an XML elelement that meaningfully mixes character data with elements as in example This schema defines two mixed contents elements salutation and letterbody. Note order must be correct and is checked on validation 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Just Attributes. Empty Content <internationalPrice currency=“EUR” value=“123.4” /> can be defined in two ways Note use of xsd:anyType in full form as we are defining an element with no content – therefore type irrelevant. By definition anyType puts no constraints on the content model This is equivalent to top form 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Annotations Here <xsd:annotation> with sub element <xsd:documentation> is used to explain schema of internationalPrice Can also use xsd:appInfo element as a child of xsd:annotation to provide information to tools and stylesheets <xsd:annotation> can appear in most Schema xsd: elements 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Generalized Groups <xsd:sequence> is rather strict as it requires order of elements declared within sequence. Some flexibility is allowed from minOccurs and maxOccurs <xsd:choice> with <xsd:group> and <xsd:all> allow more general structures This allows either a single address <singleUSAddress> or separate shipTo and billTo addresses This is the shipAndBill group referenced with ref= above 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

The <xsd:all> Group <xsd:all> MUST appear at top-level of any content model and the the elements in the all group must have minOccurs and maxOccurs as 0 or 1 Elements in all group can appear in any order Top of Content Model for PurchaseOrderType Here <xsd:all> is NOT at top 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Attribute Groups Often one wishes to use the same attributes in several elements This is done using parameter entities in DTD syntax. Rather than “crude” macro substitution, Schema allows groups to be defined and referenced New Attributes 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Use of Attribute Groups Note Attribute declarations and attributeGroup references must appear at end of a complexType definition Reference attributeGroup Define attributeGroup 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Null Values As well as setting explicit values for an element, one may wish to indicate that element has NO set value Taking example of shipDate (which was absent for the Lawnmower in po.xml), one indicates this that is allowed in Schema definition by <xsd:element name="shipDate" type="xsd:date" nullable="true"/> And to explicitly represent that shipDate has a null value in the instance document, we set the null attribute (from the XML Schema namespace for instances) to true: <shipDate xsi:null="true"></shipDate> This assumes one has set xmlns:xsi = http://www.w3.org/1999/XMLSchema-instance Such null values MUST not values set in <shipDate ..></shipDate> but can have any allowed attributes 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Schema and Namespaces I Schema do a better job than DTD in making it clear who how Namespaces can be used effectively Here we define http://www.example.com/PO1 as the targetNamespace for this schema We also define po: as the same URL and the default Namespace to be W3C Schema central Then we do NOT need xsd: as in original po.xml as we have default Schema central to be default In name=‘..’, we do NOT need to specify a Namespace but in type=“..” or ref=“..” we do not as these could reference another Namespace No Namespace as string type define in Schema Central 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Schema and Namespaces II We must distinguish global and local elements The attribute definitions in po1.xml elementFormDefault="unqualified" attributeFormDefault="unqualified“ Imply that all local elements are assumed to come from targetNamespace and MUST not be qualified purchaseOrder and comment are global; remainder local apo: must be used with global elements but not with other ones 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 elementFormDefault I We can require local elements to be qualified by setting elementFormDefault as “qualified” Attributes need not be qualified as we left attributeFormDefault as “unqualified” Schema Example of this Schema 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

elementFormDefault II If we make po1.xml the default Namespace, then whatever setting of elementFormDefault we need no prefixes at all. 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Selective Qualification One can set defaults and then override defaults for selected attributes or elements This is illustrated for attribute publicKey here Qualification and its default is to be designed to ensure no ambiguities and mistakes when there are multiple Namespaces 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Global Elements in Schema We can make schema where all elements and attributes are global as in this po.xsd This is just the DTD version and all element names must be unique and all must be qualified unless po.xml is declared the default Namespace 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 xsd:include Tag Here we include another schema file which itself is a valid schema definition. The net result is a single Namespace referenced through original file One can any number of include statements and arbitrary nesting but there will always be a single Namespace <include schemaLocation= "http://www.example.com/schemas/address.xsd"/> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Xsd:Include Here is the File to be included The parser will find all the files and construct the total Schema 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Deriving Types by Extension Derived Derived Equivalent to Standalone Here the types USAddress and UKAddress are gotten by adding elements and attribute (for UKAddress) to complex type Address ipo is defined as Namespace where UKPostcode and USAddress are defined There is an equivalent standalone way of doing this which is shorter perhaps but as we see on next foil is less powerful in the long run 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Using Extended types One can use derived types in an instance of a Schema where Schema specified only the parent To do this you must set the xsi:type attribute for the derived element to be ipo:derived type Here xsi is W3C central XML Schema Instance namespace. ipo is Namespace for this particular schema 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Restriction of Complex Types Here we are taking a given complex or simple type and restricting it to a subset of its previous capabilities. In example, we take Items and derive a new type ConfirmedItems which only has one change minOccurs=“1” not “0” for the item subelement Note you must repeat all the unchanged parts of items and item 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Examples of Restrictions Valid restrictions must decrease allowed range so that if in original (minOccurs,maxOccurs) = (1,1) one cannot further restrict it The first three examples are in common between attributes ( where one needs to specify use and value) and elements 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 <xsd:redefine Tag Here you do not create new elements but rather change an existing element preserving its name Here we change Address This change holds for all derived types based on this changed element So UKAddress also gets a country element 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Substitution Groups Consider any global element, such as comment in po.xml. We can define alternative labels for this tag with the substitutionGroup attribute in <xsd:element One can use the new labels to improve readability of an XML instance We define alternatives customerComment and shipComment 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Abstract Element and Type If we declare comment as abstract by <element name="comment" type="string" abstract="true"/> Then we cannot use comment but we can use any element defined in a substitutionGroup such as customerComment and shipComment Vehicle is described as an abstract type. One can use conventionally any types like Car or Plane derived from it. Element transport is defined with a type Vehicle that is abstract. Using an element with an abstract type requires setting xsi:type=“XXX” where XXX is a non abstract type derived from original one 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Restricting what can be changed I One can control how much freedom there is in extending or restricting simple and complex types by use of the final attribute in the <xsd:element <xsd:complexType or <xsd:simpleType Schema elements This stops derivation of this type later in Schema final=“restriction” prevents new types gotten by restricting original type final=“extension” prevents new types gotten by extending original type final=“#all” prevents restriction and extension In xsd:schema the attribute finalDefault can be used with these same three values to preset values of final in element and type definitions In example, the derivation of USAddress and UKAddress would not be allowed 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Restricting what can be changed II We also described how one can use in instance documents, derivations such as USAddress and UKAddress as in shipTo and billTo elements which are defined in the schema to have type Address This capability can be controlled using the block attribute block can take values restriction, extension or substitution (to forbid use of substitution groups) or #all to reflect all of these three capabilities As with final, one can specify blockDefault in the <xsd:schema element to apply a default to block in every type and element definition 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Changing Facets in Simple Types One can use the fixed attribute to control restriction of simple types as in this Postcode example [A-Z]{2}\d\s\d[A-Z]{2} is an allowed derived type as length still 7 However changing length or specifying a pattern that is not 7 in length is illegal 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Constrained Data This example shows a report where there are some implicit constraints Each Zip code occurs only once Each part can occur in different zip codes but any part occurring in any zip code must occur once and only once in <parts> section These are constraints between different element and attribute values With facets, we constrained individual entries. 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Report Schema report.xsd I The <xsd:unique tag with name dummy1 specifies a set of elements – those in regions/zip defined on next page. The <xsd:field tag tells you what has to be unique in this set of elements Namely the code attribute We will do xpath later 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Report Schema report.xsd II Here we illustrate a more powerful concept which generalizes ID and IDREF in basic XML to any attribute or element The <xsd:key tag identifies the number part element in parts as a key (generalized ID) to be referenced by pNumKey ( a generalized IDREF) As it is a key, the number attribute in parts/part must be unique as is ID in XML specification The <xsd:keyref tag specifies the number attribute in zip/part has properties of IDREF It is not necessarily unique but must reference a “pNumKey” with its value 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Report Schema report.xsd III This is rest of report.xsd We can specify two fields in dummy1 to ensure that pair (zip,part) is unique i.e. for each zip, each part occurs 0 or 1 times 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Import directive I In report.xsd we started schema specification <schema targetNamespace="http://www.example.com/Report" xmlns="http://www.w3.org/2000/08/XMLSchema" xmlns:r="http://www.example.com/Report" xmlns:xipo="http://www.example.com/IPO" elementFormDefault="qualified“ > <import namespace="http://www.example.com/IPO"/> include (as used in ipo.xsd to include address.xsd) incorporates external schema components into same target namespace as base schema. import allows us to set up “libraries” and use predefined components from different target namespaces 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Import directive II Here we see <xsd:include used earlier in ipo.xsd Given we have imported all of ipo.xsd, we can reference any globally defined component Thus we can write in report.xsd <element ref="xipo:comment"/> Note however, that we cannot reuse the shipTo element from po.xsd as only global components can be used. Thus one canNOT write <element ref="xipo:shipTo"/> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Import directive III One can import complex types as long as they are globally defined USAddress can be used from ipo.xsd and in example we extend it to Analyst type which is used to define in obvious way (not shown) an analyst element used as shown When schema components are imported from multiple namespaces, each namespace must be identified with a separate import element, which must appear as the first children of the schema element. One must also associate each namespace with a prefix, using a standard xmlns:prefix namespace declaration. This prefix is used in any references to components in the imported namespace 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

it2xmltech01 http://aspen.csit.fsu.edu/it2spring01 Type Library Here we define a type library and access it to form a new element as shown in this Schema fragment <schema targetNamespace= "http://www.example.com/Money" xmlns="http://www.w3.org/2000/08/XMLSchema" xmlns:m=“ http://www.example.com/MoneyTypes" > <import namespace=“ http://www.example.com/MoneyTypes"/> <element name="convertFrom" type="m:Currency" > … </schema> In an instance we would use: <convertFrom name="AFA"/>199.37</convertFrom> 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

Use of any Element in Schema Here we introduce a new element <xsd:any with two special attributes namespace and processContents In this example a single element <htmlexample is allowed but it is allowed to have any tags from the XHTML Namespace http://www.w3.org/1999/xhtml processContents is set to skip so that the XHTML must be well formed but is not validated processContents can also be strict to require validation of XHTML fragment or processContents can also be lax when XML parser does its best 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

any Schema Element - Example This is an example with inserted XHTML. Note use of default Namespace in <table tag so we can avoid any prefixes 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

any Schema Attribute or Element The namespace attribute in <xsd:any can take several values with ##any ##local ##other and ##targetNamespace having special meaning One can also define <xsd:anyAttribute with the example allowing href to appear in <htmlExample tag 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01

schemaLocation and xsi:schemaLocation One can use in <xsd:schema the attribute xsi:schemaLocation to specify helpful information to parser. The syntax is xsi:schemaLocation=“Namespace1 Hint1 Namespace2 Hint2” The parser is allowed to ignore the hints. For a document without a target namespace use xsi:noNamespaceSchemaLocation In import and include, the schemaLocation attribute (no xsi: prefix) specifies URI for imported/included Schema Example of use of xsi:schemaLocation 9/22/2018 it2xmltech01 http://aspen.csit.fsu.edu/it2spring01