Restricting complextypes that have mixed content

Similar documents
XML Schema. Mario Alviano A.Y. 2017/2018. University of Calabria, Italy 1 / 28

Markup Languages. Lecture 4. XML Schema

<xs:element name="record" type="recordtype" maxoccurs="unbounded" /> </xs:sequence> </xs:complextype>

Messages are securely encrypted using HTTPS. HTTPS is the most commonly used secure method of exchanging data among web browsers.

ՕՐԻՆԱԿ. <xs:schema targetnamespace=" xmlns:tax="

Document erratum applies to QosDevice:1. List other Erratum s or Documents that this change may apply to or have associated changes with

/// Rapport. / Testdocumentatie nieuwe versie Register producten en dienstverlening (IPDC)

So far, we've discussed the use of XML in creating web services. How does this work? What other things can we do with it?

Oracle B2B 11g Technical Note. Technical Note: 11g_005 Attachments. Table of Contents

Introducing our First Schema

[MS-OXWSXPROP]: Extended Properties Structure. Intellectual Property Rights Notice for Open Specifications Documentation

Trustmark Framework Technical Specification

QosPolicyHolder:1 Erratum

Schema schema-for-json.xsd

2006 Martin v. Löwis. Data-centric XML. XML Schema (Part 1)

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

Test Assertions Part 2 - Test Assertion Markup Language Version 1.0

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

CSC503 Exam 2. Assume that the following functional dependencies beyond that of the primary key are valid:

XML Schema Element and Attribute Reference

Semantic Web. XML and XML Schema. Morteza Amini. Sharif University of Technology Fall 94-95

What Kind Of Thing Is It?

XML extensible Markup Language

Software Engineering Methods, XML extensible Markup Language. Tutorial Outline. An Example File: Note.xml XML 1

MWTM NBAPI WSDL and XSD Definitions

Approaches to using NEMSIS V3 Custom Elements

MWTM 6.1 NBAPI WSDL and XSD Definitions

Cisco Prime Central 1.0 API Guide

Configuring a WMS Feature Source

X3D Unit Specification Updates Myeong Won Lee The University of Suwon

PESC Compliant JSON Version /19/2018. A publication of the Technical Advisory Board Postsecondary Electronic Standards Council

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:types=" xmlns:xs="

General Service Subscription Management Technical Specification

Pattern/Object Markup Language (POML): A Simple XML Schema for Object Oriented Code Description

Allegato: AgibilitaRequest_V.1.1.xsd

3GPP TS V8.2.0 ( )

! "# # $ % & ' ( ' )* ) & %*+ *

Test Assertions Part 2 - Test Assertion Markup Language Version 1.0

file://c:\michael\prog\mast\docs\tmp0000.xsd

Positioning Additional Constraints

Project Members: Aniket Prabhune Reenal Mahajan Mudita Singhal

Big Data 9. Data Models

Apache UIMA Regular Expression Annotator Documentation

Cisco Unity Connection Notification Interface (CUNI) API

TC57 Use of XML Schema. Scott Neumann. October 3, 2005

<xs:element name="relationshipdata" type="rr:relationshipdatatype"/> <xs:element name="header" type="rr:rrheadertype"> </xs:element>

CONVERTING CONCEPTUAL MODEL XUML TO XML SCHEMA

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

Web Service Provider Example - Enabling Visible Business

Author: Irena Holubová Lecturer: Martin Svoboda

G16-02SE-A02.1-NUE112_SchedaContatto-Rev5 <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="

Schema XACML v0.11c.xsd

Fall, 2005 CIS 550. Database and Information Systems Homework 5 Solutions

XSD Reference For EXPRESS XML language

[MS-QDEFF]: Query Definition File Format. Intellectual Property Rights Notice for Open Specifications Documentation

[MS-OXWSGTZ]: Get Server Time Zone Web Service Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

ETSI TS V8.1.0 ( ) Technical Specification

SDMX self-learning package No. 6 Student book. XML Based Technologies Used in SDMX

Data Bus Client Interface Manager Interface Control Document

[MS-QDEFF]: Query Definition File Format. Intellectual Property Rights Notice for Open Specifications Documentation

Custom Data Access with MapObjects Java Edition

IODEF Data Model Status (progress from 03) <draft-ietf-inch-iodef-03>

XML Technologies. Doc. RNDr. Irena Holubova, Ph.D. Web pages:

Level of Assurance Authentication Context Profiles for SAML 2.0

[MS-OXWSMSHR]: Folder Sharing Web Service Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

PESC Compliant JSON Version /04/2019

Syntax XML Schema XML Techniques for E-Commerce, Budapest 2004

Specifications for SHORT System Document Submission Service

Introduction to XML Schema. The XML Schema language is also referred to as XML Schema Definition (XSD).

Distribution List Creation and Usage Web Service Protocol

Using Inventory Export Guide

Testing of Service Oriented Architectures A practical approach / APPENDIX V1.0

extensible Markup Language

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

[MS-SSDL]: Store Schema Definition Language File Format. Intellectual Property Rights Notice for Open Specifications Documentation

Big Data for Engineers Spring Data Models

Mailtips Extensions to Web Service Protocol Specification

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

Work/Studies History. Programming XML / XSD. Database

EVALUATION COPY. Contents

MCS-274 Final Exam Serial #:

AlwaysUp Web Service API Version 11.0

[MS-OXWSSYNC]: Mailbox Contents Synchronization Web Service Protocol Specification

extensible Markup Language

UPDATES TO THE LRIT SYSTEM. Report of the Drafting Group

COMP60411 Modelling Data on the Web XPath, XML Schema, and XQuery. Week 3

Test Assertions Part 2 - Test Assertion Markup Language Version 1.0

Test Assertions Part 2 - Test Assertion Markup Language Version 1.0

XML-Schema Quick Start * Draft

[MS-MSL]: Mapping Specification Language File Format. Intellectual Property Rights Notice for Open Specifications Documentation

Big Data Fall Data Models

Infor Enterprise Server User Guide for Triggering

Oracle Enterprise Data Quality

Oracle Hospitality OPERA Web Self- Service Brochure Web Service Specification Version 5.1. September 2017

XML. Document Type Definitions XML Schema. Database Systems and Concepts, CSCI 3030U, UOIT, Course Instructor: Jarek Szlichta

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

[MS-OXWSBTRF]: Bulk Transfer Web Service Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

An XML Description Language for Web-based Network Simulation

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

Extensible Markup Language Processing

Transcription:

Restricting complextypes that have mixed content Roger L. Costello October 2012 complextype with mixed content (no attributes) Here is a complextype with mixed content: <xs:complextype name="c1" mixed="true"> [Notice: the child element a1 is optional.] Here is an element declared to be of that type: <xs:element name="e1" type="c1" /> The content of element E1 can be any of these: 1. Pure text (xs:string) 2. Child element a1 3. Text and child element a1 (i.e., mixed content) Here are examples to illustrate the possible content of E1: 1. E1 has pure text: <E1>Hello World</E1> 2. E1 has a child element a1: <E1> </E1> 3. E1 has text surrounding the child element a1: <E1>This is some text

that surrounds the element </E1> Restricting a complextype with mixed content Recall that derive-by-restriction allows us to create a complextype with content that is a subset of a base type. Let C1 be the base type. It has two pieces of content that can be restricted away (i.e., removed): (a) the optional child element a1 (i.e., the markup) (b) the text that surrounds the child element Let s implement each of these restrictions. (a) This complextype removes C1 s markup: <xs:complextype name="c1-sans-child-element"> <xs:restriction base="c1"> <xs:restriction base="xs:string"/> [Notice: since its content is text, use simplecontent.] Here I declare an element of that type: <xs:element name="e1-sans-child-element" type="c1-sans-child-element" /> Its only legal content is string data: <E1-sans-child-element>Hello World</E1-sans-child-element> [Important: the string data is unconstrained it can be of any length and can contain any characters (Chinese, Arabic, Cyrillic, etc.)] [Important: C1 s markup can be restricted away only if its markup is optional. The element a1 has minoccurs= 0 and therefore can be removed.]

We can constrain the string data as shown here: <xs:complextype name="c1-sans-child-element-constrained"> <xs:restriction base="c1"> <xs:restriction base="xs:string"> <xs:maxlength value="10"/> <xs:pattern value="[a-za-z0-9 ]*" /> The string data is now constrained to just 10 or less lower- and upper-case letters, digits and spaces. (b) This complextype removes the text that can surround C1 s child element: <xs:complextype name="c1-sans-text"> <xs:complexcontent> <xs:restriction base="c1"> [Notice: since its content is an element, use complexcontent.] Here I declare an element: <xs:element name="e1-sans-text" type="c1-sans-text" /> Its only legal content is the child element a1: <E1-sans-text> </E1-sans-text>

Equivalent Types The content of C1-sans-child-element is just a string. So these two types are equivalent in terms of schema-valid data: <xs:complextype name="c1-sans-child-element"> <xs:restriction base="c1"> <xs:restriction base="xs:string"/> <xs:simpletype name="c1-sans-child-element-equivalent"> <xs:restriction base="xs:string" /> The content of C1-sans-text is just markup. So these two types are equivalent in terms of schema-valid data: <xs:complextype name="c1-sans-text"> <xs:complexcontent> <xs:restriction base="c1"> <xs:complextype name="c1-sans-text-equivalent"> complextype with mixed content and an attribute Here is a complextype with mixed content and an optional attribute: <xs:complextype name="c2" mixed="true"> <xs:attribute name="a" type="xs:string" />

[Notice: the attribute declaration does not have a use attribute. Recall that an attribute declaration without a use attribute defaults to use="optional".] Here is an element declared to be of that type: <xs:element name="e2" type="c2" /> The content of element E2 can be any of these: 1. Pure text (xs:string) 2. Child element a1 3. Child element a1 plus text that surrounds a1 4. Pure text and attribute A 5. Child element a1 and attribute A 6. Child element a1, text that surrounds a1, and attribute A Here are examples of the latter three. 4. E2 has pure text and attribute A: <E2 A="foo">Hello World</E2> 5. E2 has a child a1 element and attribute A: <E2 A="foo"> </E2> 6. E2 has child element a1, text that surrounds a1, and attribute A: <E2 A="foo">This is some text that surrounds the element </E2>

Restricting a complextype with mixed content and an attribute Let C2 be the base type. It has three pieces of content that can be restricted away (i.e., removed): (a) the optional child element, a1 (b) the text that surrounds the child element (c) the optional attribute, A Let s implement each of these restrictions. (a) This complextype removes C2 s markup: <xs:complextype name="c2-sans-child-element"> <xs:restriction base="xs:string"/> [Notice: the type does not declare the attribute. Nonetheless, it contains the attribute.] [Notice: since its content is text, use simplecontent.] Here I declare an element: <xs:element name="e2-sans-child-element" type="c2-sans-child-element" /> Its only legal content is xs:string data and attribute A: <E2-sans-child-element A="foo">Hello World</E2-sans-child-element> [Important: the string data is unconstrained it can be of any length and can contain any characters (Chinese, Arabic, Cyrillic, etc.)] [Important: C2 s markup can be restricted away only if the markup is optional. The child element a1 has minoccurs= 0 and therefore can be removed.]

We can constrain the string data as shown here: <xs:complextype name="c2-sans-child-element-constrained"> <xs:restriction base="xs:string"> <xs:maxlength value="10"/> <xs:pattern value="[a-za-z0-9 ]*" /> The string data is now constrained to just 10 or less lower- and upper-case letters, digits and spaces. (b) This complextype removes the text that can surround C2 s child element: <xs:complextype name="c2-sans-text"> <xs:complexcontent> [Notice: it does not declare the attribute. Nonetheless, it has the attribute.] [Notice: since its content is an element, use complexcontent.] Here I declare an element: <xs:element name="e2-sans-text" type="c2-sans-text" /> Its only legal content is the child element a1 and the attribute A: <E2-sans-text A="foo"> </E2-sans-text> (c) This complextype removes C2 s attribute: <xs:complextype name="c2-sans-attribute" mixed="true"> <xs:complexcontent>

<xs:attribute name="a" use="prohibited" type="xs:string" /> [Notice: here s how to remove the attribute: use= prohibited.] Here I declare an element: <xs:element name="e2-sans-attribute" type="c2-sans-attribute" /> Its only legal content is mixed content: <E2-sans-attribute>This is some text that surrounds the element </E2-sans-attribute> Equivalent Types The content of C2-sans-child-element is text plus attribute. So these two types are equivalent in terms of schema-valid data: <xs:complextype name="c2-sans-child-element"> <xs:restriction base="xs:string"/> <xs:complextype name="c2-sans-child-element-equivalent"> <xs:extension base="xs:string"> <xs:attribute name="a" type="xs:string" /> </xs:extension> A bit different strategy is needed if the string data is constrained: the simpletype must be extracted, given a name, and made global. The equivalent of this: <xs:complextype name="c2-sans-child-element-constrained">

<xs:restriction base="xs:string"> <xs:maxlength value="10"/> <xs:pattern value="[a-za-z0-9 ]*" /> is this pair: <xs:simpletype name="abc"> <!-- Give the simpletype a unique name --> <xs:restriction base="xs:string"> <xs:maxlength value="10"/> <xs:pattern value="[a-za-z0-9 ]*" /> <xs:complextype name="c2-sans-child-element-constrained-equivalent"> <xs:extension base="abc"> <xs:attribute name="a" type="xs:string" /> </xs:extension> [Note: XML Schema is not consistent with regard to constraining a simpletype in a complextype with simplecontent. A simpletype can occur within complextype/simplecontent/restriction but not within complextype/simplecontent/extension.] The content of C2-sans-text is just the child element a1 plus the attribute. So these two types are equivalent in terms of schema-valid data: <xs:complextype name="c2-sans-text"> <xs:complexcontent> <xs:complextype name="c2-sans-text-equivalent">

<xs:attribute name="a" type="xs:string" />

The content of C2-sans-attribute is mixed content. So these two types are equivalent in terms of schema-valid data: <xs:complextype name="c2-sans-attribute" mixed="true"> <xs:complexcontent> <xs:attribute name="a" use="prohibited" type="xs:string" /> <xs:complextype name="c2-sans-attribute-equivalent" mixed="true"> Real-world example of restricting a complextype with mixed content This is a fabulous example from the XML Schema specification. A complextype is created for representing various kinds of messages such as XML messages, base64 messages, and messages that just contain a string. A base type is created that is a complextype with mixed content and an attribute. Then several complextypes are created which restrict the base type: - A complextype for XML messages: restrict the base type by removing the ability to surround the child element. - A complextype for base64 messages: restrict the base type by removing the child element and subtyping xs:string with xs:base64binary. - A complextype for string messages: restrict the base type by removing the child element. Here is a graphic to illustrate the type hierarchy:

Here is the base type: <xs:complextype name="messagetype" mixed="true"> <xs:any processcontents="skip" minoccurs="0" maxoccurs="unbounded"/> <xs:attribute name="kind"> <xs:union> <xs:restriction base="xs:string"> <xs:enumeration value="string"/> <xs:enumeration value="base64"/> <xs:enumeration value="binary"/> <xs:enumeration value="xml"/> <xs:enumeration value="xml"/> <xs:restriction base="xs:string"/> </xs:union> </xs:attribute> <xs:anyattribute processcontents="skip"/> Here is a message type specifically for XML messages: <xs:complextype name="messagetypexml"> <xs:complexcontent> <xs:restriction base="messagetype"> <xs:any processcontents="strict"/> Here is a message type specifically for base64 messages: <xs:complextype name="messagetypebase64"> <xs:restriction base="messagetype"> <xs:restriction base="xs:base64binary"/>

Here is a message type specifically for string messages: <xs:complextype name="messagetypestring"> <xs:restriction base="messagetype"> <xs:restriction base="xs:string"/> My XML Schema for complextypes shown at the top Below is my XML Schema for the complextypes shown at the beginning of this document <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <!-- **************************** --> <!-- Mixed content --> <!-- **************************** --> <xs:complextype name="c1" mixed="true"> <!-- Remove C1's child element a1 to leave just the text --> <xs:complextype name="c1-sans-child-element"> <xs:restriction base="c1"> <xs:restriction base="xs:string"/> <!-- Remove C1's text to leave just the child element a1 --> <xs:complextype name="c1-sans-text">

<xs:complexcontent> <xs:restriction base="c1"> <!-- This is equivalent to C1-sans-child-element: it has just text --> <xs:simpletype name="c1-sans-child-element-equivalent"> <xs:restriction base="xs:string" /> <!-- This is equivalent to C1-sans-text: it just has child element a1 --> <xs:complextype name="c1-sans-text-equivalent"> <!-- **************************** --> <!-- Mixed content plus attribute --> <!-- **************************** --> <xs:complextype name="c2" mixed="true"> <xs:attribute name="a" type="xs:string" /> <!-- Remove C2's child element a1 to leave text plus attribute --> <xs:complextype name="c2-sans-child-element"> <xs:restriction base="xs:string"/>

<!-- Remove the text that surrounds C2's child element to leave element plus attribute --> <xs:complextype name="c2-sans-text"> <xs:complexcontent> <!-- Remove C2's attribute to leave mixed content --> <xs:complextype name="c2-sans-attribute" mixed="true"> <xs:complexcontent> <xs:attribute name="a" use="prohibited" type="xs:string" /> <!-- This is equivalent to C2-sans-child-element: it has text plus attribute --> <xs:complextype name="c2-sans-child-element-equivalent"> <xs:extension base="xs:string"> <xs:attribute name="a" type="xs:string" /> </xs:extension> <!-- This is equivalent to C2-sans-text: it has element plus attribute --> <xs:complextype name="c2-sans-text-equivalent"> <xs:attribute name="a" type="xs:string" /> <!-- This is equivalent to C2-sans-attribute: it has mixed content (no attribute) -->

<xs:complextype name="c2-sans-attribute-equivalent" mixed="true"> <xs:element name="test"> <xs:complextype> <xs:element name="e1" type="c1" maxoccurs="unbounded" /> <xs:element name="e1-sans-child-element" type="c1-sans-child-element" /> <xs:element name="e1-sans-text" type="c1-sans-text" /> <xs:element name="e1-sans-child-element-equivalent" type="c1-sans-child-element-equivalent" /> <xs:element name="e1-sans-text-equivalent" type="c1-sans-text-equivalent" /> <xs:element name="e2" type="c2" maxoccurs="unbounded" /> <xs:element name="e2-sans-child-element" type="c2-sans-child-element" /> <xs:element name="e2-sans-text" type="c2-sans-text" /> <xs:element name="e2-sans-attribute" type="c2-sans-attribute" /> <xs:element name="e2-sans-child-element-equivalent" type="c2-sans-child-element-equivalent" /> <xs:element name="e2-sans-text-equivalent" type="c2-sans-text-equivalent" /> <xs:element name="e2-sans-attribute-equivalent" type="c2-sans-attribute-equivalent" /> </xs:element> </xs:schema> Here is a sample instance document: <?xml version="1.0" encoding="utf-8"?> <Test xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="a.xsd"> <E1>This is some text that surrounds the element </E1> <E1-sans-child-element>Hello World</E1-sans-child-element> <E1-sans-text> </E1-sans-text> <E1-sans-child-element-equivalent>Hello World</E1-sans-child-element-equivalent>

<E1-sans-text-equivalent> </E1-sans-text-equivalent> <E2 A="foo">This is some text that surrounds the element </E2> <E2-sans-child-element A="foo">Hello World</E2-sans-child-element> <E2-sans-text A="foo"> </E2-sans-text> <E2-sans-attribute>This is some text that surrounds the element </E2-sans-attribute> <E2-sans-child-element-equivalent A="foo">Hello World</E2-sans-child-element-equivalent> <E2-sans-text-equivalent A="foo"> </E2-sans-text-equivalent> <E2-sans-attribute-equivalent>This is some text that surrounds the element </E2-sans-attribute-equivalent> </Test>