XML. Part II DTD (cont.) and XML Schema

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

XML Schema Element and Attribute Reference

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

Session [2] Information Modeling with XSD and DTD

Appendix H XML Quick Reference

Java EE 7: Back-end Server Application Development 4-2

XML. Part I XML Document and DTD

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

EMERGING TECHNOLOGIES. XML Documents and Schemas for XML documents

Tutorial 2: Validating Documents with DTDs

XML - Schema. Mario Arrigoni Neri

HTML vs. XML In the case of HTML, browsers have been taught how to ignore invalid HTML such as the <mymadeuptag> element and generally do their best

XML: Introduction. !important Declaration... 9:11 #FIXED... 7:5 #IMPLIED... 7:5 #REQUIRED... Directive... 9:11

XML DTDs and Namespaces. CS174 Chris Pollett Oct 3, 2007.

Introducing our First Schema

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

Chapter 11 XML Data Modeling. Recent Development for Data Models 2016 Stefan Deßloch

웹기술및응용. XML Schema 2018 년 2 학기. Instructor: Prof. Young-guk Ha Dept. of Computer Science & Engineering

XEP-0009: Jabber-RPC

Module 3. XML Schema

Solution Sheet 5 XML Data Models and XQuery

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

Sistemi ICT per il Business Networking

XEP-0104: HTTP Scheme for URL Data

Modelling XML Applications

Chapter 6: RELAX NG. Chapter 6 Objectives. blocks of RELAX NG schemas. higher-level components for reuse, as well

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

XEP-0298: Delivering Conference Information to Jingle Participants (Coin)

XML (4) Extensible Markup Language

Chapter 1: Getting Started. You will learn:

XEP-0033: Extended Stanza Addressing

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

DTD MIGRATION TO W3C SCHEMA

The concept of DTD. DTD(Document Type Definition) Why we need DTD

XML and Web Services

Introduction to Semistructured Data and XML. Overview. How the Web is Today. Based on slides by Dan Suciu University of Washington

Chapter 3 Brief Overview of XML

Big Data 9. Data Models

FROM XML SCHEMA TO OBJECT-RELATIONAL DATABASE AN XML SCHEMA-DRIVEN MAPPING ALGORITHM

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

Describing Document Types: The Schema Languages of XML Part 2

HR-XML Schema Extension Recommendation, 2003 February 26

CS561 Spring Mixed Content

Inside Information Platform Implementation Guide

Naming & Design Requirements (NDR)

Web Services Resource Metadata 1.0 (WS-ResourceMetadataDescriptor)

Loop Qualification Table of Contents

Information Systems. DTD and XML Schema. Nikolaj Popov

XEP-0171: Language Translation

Querying XML Data. Querying XML has two components. Selecting data. Construct output, or transform data

ADT 2005 Lecture 7 Chapter 10: XML

Grid Computing. What is XML. Tags, elements, and attributes. Valid and well formed XML. Grid Computing Fall 2006 Paul A.

XML. Semi-structured data (SSD) SSD Graphs. SSD Examples. Schemas for SSD. More flexible data model than the relational model.

XML. XML Namespaces, XML Schema, XSLT

XML and Content Management

Altova XMLSpy 2007 Tutorial

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 7 XML

Extensible Markup Language (XML) Hamid Zarrabi-Zadeh Web Programming Fall 2013

Big Data Exercises. Fall 2018 Week 8 ETH Zurich. XML validation

XML Information Set. Working Draft of May 17, 1999

extensible Markup Language

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?

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1

CSI 3140 WWW Structures, Techniques and Standards. Representing Web Data: XML

ETSI STANDARD Methods for Testing and Specification (MTS); The Testing and Test Control Notation version 3; Part 9: Using XML schema with TTCN-3

XML (Extensible Markup Language)

DOM Interface subset 1/ 2

XML Reference: Siebel Enterprise Application Integration. Siebel Innovation Pack 2014 November 2014

Creation of the adaptive graphic Web interfaces for input and editing data for the heterogeneous information systems on the bases of XML technology

7.1 Introduction. 7.1 Introduction (continued) - Problem with using SGML: - SGML is a meta-markup language

Restricting complextypes that have mixed content

XEP-0337: Event Logging over XMPP

Big Data for Engineers Spring Data Models

Complex type. This subset is enough to model the logical structure of all kinds of non-xml data.

SCA Model using XSD. Status: in progress. Version Date Author(s) Comments. v1.0 06/06/07 Damien Fournier, Philippe Merle (INRIA) Initial version

Big Data Fall Data Models

Jeff Offutt. SWE 642 Software Engineering for the World Wide Web

MANAGING INFORMATION (CSCU9T4) LECTURE 2: XML STRUCTURE

W3C XML Schemas For Publishing

Who s Afraid of XML Schema?

Altova XMLSpy 2013 Tutorial

Last week we saw how to use the DOM parser to read an XML document. The DOM parser can also be used to create and modify nodes.

XML Schema Profile Definition

XML Schema for Job Definition Format. Graham Mann Internet Printing Group, Adobe Systems Inc

XML Structures. Web Programming. Uta Priss ZELL, Ostfalia University. XML Introduction Syntax: well-formed Semantics: validity Issues

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

XML stands for Extensible Markup Language and is a text-based markup language derived from Standard Generalized Markup Language (SGML).

<account_number> A-101 </account_number># <branch_name> Downtown </branch_name># <balance> 500 </balance>#

UBL Naming and Design Rules Checklist

ETSI TS V9.2.0 ( )

* * DFDL Introduction For Beginners. Lesson 2: DFDL Language Basics. DFDL and XML Schema

UNIT I. A protocol is a precise set of rules defining how components communicate, the format of addresses, how data is split into packets

Notes. Any feedback/suggestions? IS 651: Distributed Systems

ST.96 - ANNEX I XML DESIGN RULES AND CONVENTIONS. Version 2.0

[MS-OXSHRMSG]: Sharing Message Attachment Schema. Intellectual Property Rights Notice for Open Specifications Documentation

extensible Markup Language

ETSI TS V8.1.0 ( )

CONVERTING CONCEPTUAL MODEL XUML TO XML SCHEMA

Framing how values are extracted from the data stream. Includes properties for alignment, length, and delimiters.

Introduction to XML. Chapter 133

Transcription:

XML Part II DTD (cont.) and XML Schema

Attribute Declarations Declare a list of allowable attributes for each element These lists are called ATTLIST declarations Consists of 3 basic parts The ATTLIST keyword The associated element s name The list of declares attributes Each attribute in list consists of 3 parts The attribute name The attribute type The attribute value declaration

Example 1 <!ATTLIST contacts source CDATA #IMPLIED> ATTLIST keyword Associated element List of declared attributes Attribute name Attribute type Attribute value

Attribute naming rules are similar to element naming rule Duplicate attribute names are not allow in attribute list Attribute types (next page)

ID, IDREF, IDREFS ID s value must follow the rules for XML names The value of ID must be unique with in the entire XML document Only one ID is allowed per element The attribute value declaration for ID must be #IMPLIED, #REQUIRED For the value of IDREF, the value must match the value of some ID within the XML document

ENTITY and ENTITIES References to unparsed entities Unparsed entities refers to reference to an external file that processor connot parse, e.g. image file ENTITY or ENTITIES must refer to an ENTITY that has been declared somewhere in the DTD Value of ENTITY must follow the rules for XML name

NMTOKEN and NMTOKENS Used to refer to a concept or single word Value can be any word as long as it follow XML naming rules ENUMERATED Allow ability to specify a list of allowable values Each value must be a valid XML name <!ATTLIST phone kind (Home Work Cell Fax) #IMPLIED>

Attribute Value Declarations Within each attribute declaration, how the value will appear in the document must be specified as one of the following: Has a default value Has a fixed value Is required Is implied ( is optional)

Default value Specifying default value is just include the value in after the attribute type <!ATTLIST phone kind (Home Work Cell Fax) "Home"> Fixed values Use the #FIXED keyword followed by fixed value <!ATTLIST contacts version CDATA #FIXED "1.0"> Required value Used to specify that the attribute must be included with in XML document <!ATTLIST phone kind (Home Work Cell Fax) #REQUIRED>

Implied values In most case the attribute declared won t be required <!ATTLIST knows contacts IDREFS #IMPLIED>

Declaring multiple attribute for an element <!ATTLIST contacts version CDATA #FIXED 1.0 source CDATA #IMPLIED> OR <!ATTLIST contacts version CDATA #FIXED 1.0 > <!ATTLIST contacts source CDATA #IMPLIED>

Entities Refer to character reference Refer to sections of replacement text, etc. Refer to external file 4 kinds of entities: Built-in entities Character entities General entities Parameter entities

Built-in entities Escape characters: &amp &lt &gt &apos &quot Character entities Use for characters that are difficult to type or for non-ascii characters &#yyy; &#xhhh;

General entities Unlike built-in and character entities, general entities must be declared with in DTD There are 2 ways to declare general entities Internal entity declaration External entity declaration <!ENTITY source-text "Beginning&apos; of List"> Keyword Entity name Value

References to general entities Reference to general entities Start with & Immediately follow the & is general entity s name End with semi-colon &general-reference;

Parameter entities Quite similar to general entities Unlike general entities, parameter entities can be used within DTD only Reference to parameter entities use % instead of & <!ENTITY % DefaultPhoneKind ""Home""> <!ATTLIST phone kind (Home Work Cell Fax) %DefaultPhoneKind;>

DTD Limitation DTD syntax and XML syntax are different Poor support for XML namespaces Poor data typing Limited content model description

XML Schemas A schema is any type of model document that defines the structure of something XML Schema refers to the specific W3C XML Schema technology XML Schema technology use for describing the structure of XML document XML Schema definitions = XSDs

Benefits of XML Schemas Using basic XML Fully support the Namespace Recommendation Enable validating text element based on built-in and user-defined data-types Enable concept such as object inheritance Creation of complex and reusable content model is easy

<?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/xmlschema" xmlns:target="http://www.example.com/name" targetnamespace="http://www.example.com/name" elementformdefault="qualified"> <element name="name"> <complextype> <sequence> <element name="first" type="string"/> <element name="middle" type="string"/> <element name="last" type="string"/> </sequence> <attribute name="title" type="string"/> </complextype> </element> </schema>

<?xml version="1.0"?> <name xmlns="http://www.example.com/name" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.example.com/name name5.xsd" title="mr."> <first>john</first> <middle>fitzgerald Johansen</middle> <last>doe</last> </name>

<schema> declaration Root element of XML Schema Default namespace and version attribute can be declared in this element <schema xmlns="http://www.w3.org/2001/xmlschema"> or <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> or <xsd:schema xmlns:xsd="http://www.w3.org/2001/xmlschema">

Target namespace Use for referring to declarations within the XML Schema <schema xmlns="http://www.w3.org/2001/xmlschema" targetnamespace="http://www.example.com/name" xmlns:target="http://www.example.com/name"> or <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" targetnamespace="http://www.example.com/name" xmlns="http://www.example.com/name">

Element and Attribute Qualification The element or attribute is qualify if there is an associates to it <n:name xmlns:n="http://www.example.com/name"> <n:first>john</n:first> <n:middle>fitzgerald</n:middle> <n:last>doe</n:last> </n:name> <n:name xmlns:n="http://www.example.com/name"> <first>john</first> <middle>fitzgerald</middle> <last>doe</last> </n:name>

Within <schema>, the attributes use to modify the default specifying how elements should be qualified: elementformdefault attributeformdefault Default value of both attributes are unqualified <element> declarations <element name="name of the element" type="global type" ref="global element declaration" form="qualified or unqualified" minoccurs="non negative number" maxoccurs="non negative number or unbounded " default="default value" fixed="fixed value">

2 types of elements Local,Global Local Type Example <element name="name"> <complextype> <sequence> <element name="first" type="string"/> <element name="middle" type="string"/> <element name="last" type="string"/> </sequence> <attribute name="title" type="string"/> </complextype> </element>

Local Type Example <element name= name > <simpletype> <restriction base= string > <enumeration value= Home /> <enumeration value= Work /> <enumeration value= Cell /> <enumeration value= Fax /> </restriction> </simpletype> </element>

Global Type Examples <schema xmlns= http://www.w3.org/2001/xmlschema xmlns:target= http://www.example.com/name targetnamespace= http://www.example.com/name elementformdefault= qualified > <complextype name= NameType > <sequence> <element name= first type= string /> <element name= middle type= string /> <element name= last type= string /> </sequence> <attribute name= title type= string /> </complextype> <element name= name type= target:nametype /> </schema>

Global Type Examples <xs:schema xmlns:xs= http://www.w3.org/2001/xmlschema xmlns= http://www.example.com/name targetnamespace= http://www.example.com/name elementformdefault= qualified > <xs:complextype name= NameType > <xs:sequence> <xs:element name= first type= xs:string /> <xs:element name= middle type= xs:string /> <xs:element name= last type= xs:string /> </xs:sequence> <xs:attribute name= title type= xs:string /> </xs:complextype> <xs:element name= name type= NameType /> </xs:schema>

<?xml version= 1.0?> <schema xmlns= http://www.w3.org/2001/xmlschema xmlns:target= http://www.example.com/name targetnamespace= http://www.example.com/name elementformdefault= qualified > <element name= first type= string /> <element name= middle type= string /> <element name= last type= string /> <complextype name= NameType > <sequence> <element ref= target:first /> <element ref= target:middle /> <element ref= target:last /> </sequence> <attribute name= title type= string /> </complextype> <element name= name type= target:nametype /> </schema>

Cardinality Represent number of occurrences of specific element within content model minoccurs and maxoccurs are attributes that used to modify an element s cardinality <element name= first type= string minoccurs= 2 maxoccurs= 2 /> <element ref= target:first maxoccurs= 10 /> <element name= location minoccurs= 0 maxoccurs= unbounded />

Default and Fixed values Default values <element name= last type= string default= Doe /> In XML document <last></last>or<last/> equivalent to <last>doe</last>

fixed values <element name= ver type= string fixed= 1.0 /> In XML document <ver></ver> or <ver/> or <ver>1.0</ver> are legal <ver></ver> or <ver/> are equivalent to <ver>1.0</ver> <ver>2.0</ver> is not legal

Element wildcards <any minoccurs= non negative number maxoccurs= non negative number or unbounded namespace= allowable namespaces processcontents= lax or skip or strict > Parameter of namespace attribute

<complextype name= NameType > <sequence> <element ref= target:first /> <element ref= target:middle /> <element ref= target:last /> <!-- allow any element from any namespace --> <any namespace= ##any processcontents= lax minoccurs= 0 maxoccurs= unbounded /> </sequence> <attribute name= title type= string /> </complextype>

<complextype> Declarations <complextype mixed= true or false name= Name of complextype > Local <complextype> definitions are never named, they are called anonymous complex types Global <complextype> definitions are always named mixed attribute allows the creation of element that include both text and element within content model

<element name= description > <complextype mixed= true > <choice minoccurs= 0 maxoccurs= unbounded > <element name= em type= string /> <element name= strong type= string /> <element name= br type= string /> </choice> </complextype> </element> XML document example <description>jeff is a developer & author for Beginning XML <em>4th edition</em> 2006 Wiley Publishing.<br/>Jeff <strong>loves</strong>xml! </description>

Empty content model <element name= knows > <complextype> </complextype> </element> <element name= knows > <complextype/> </element> <knows/> or <knows></knows>

<complextype> definitions can contain <attribute> declaration <element name= knows > <complextype> <attribute name= contacts type= IDREFS /> </complextype> </element>

<group> Declarations XML Schemas allow defining reusable groups of elements <group name= name of global group>

<?xml version= 1.0?> <schema xmlns= http://www.w3.org/2001/xmlschema xmlns:target= http://www.example.com/name targetnamespace= http://www.example.com/name elementformdefault= qualified > <group name= NameGroup > <sequence> <element name= first type= string minoccurs= 1 maxoccurs= unbounded /> <element name= middle type= string minoccurs= 0 maxoccurs= 1 /> <element name= last type= string /> </sequence> </group> <complextype name= NameType > <group ref= target:namegroup /> <attribute name= title type= string /> </complextype> <element name= name type= target:nametype /> </schema>

Content Models In XML Schemas, an element s content model can be specified using the following: A <sequence> declaration A <choice> declaration A reference to a global <group> declaration An <all> declaration Each of the above declarations may contain: Inner content models Element declarations Element wildcards

<sequence> Declarations The attributes minoccurs and maxoccurs are allowed minoccurs and maxoccurs used to specified how many time this sequence of elements occurs <sequence minoccurs= non negative number maxoccurs= non negative number or unbounded >

Example <sequence> <element name= first type= string minoccurs= 1 maxoccurs= unbounded /> <element name= middle type= string minoccurs= 0 maxoccurs= 1 /> <element name= last type= string /> </sequence> <first>john</first> <middle>fitzgerald Johansen</middle> <last>doe</last> <last>doe</last> <middle>fitzgerald</middle> <first>john</first>

<choice> Declarations minoccurs and maxoccurs are allowed for modification of cardinality of <choice> Multiple child declarations are declared within <choice> but only one declaration may be used <choice minoccurs= non negative number maxoccurs= non negative number or unbounded > <choice> <element name= first type= string minoccurs= 1 maxoccurs= unbounded /> <element name= middle type= string minoccurs= 0 maxoccurs= 1 /> <element name= last type= string /> </choice>

<group> reference Allows reference to global element groups within content model <group ref= global group definition minoccurs= non negative number maxoccurs= non negative number or unbounded > <group name= NameGroup > <sequence> <element name= first type= string minoccurs= 1 maxoccurs= unbounded /> <element name= middle type= string minoccurs= 0 maxoccurs= 1 /> <element name= last type= string /> </sequence> </group> <element name= name > <complextype> <group ref= target:namegroup /> <attribute name= title type= string /> </complextype> </element>

<all> Declarations Allow the elements in content model to appear in any order There are several rules for using <all> The <all> declaration must be the only content model that appear as a child of a <complextype> The <all> declaration is not permitted to contain <sequence>, <choice>, or <group> declarations The <all> declaration s children may appear once each

Example <element name= name > <complextype> <all> <element name= first type= string /> <element name= middle type= string /> <element name= last type= string /> </all> <attribute name= title type= string /> </complextype> </element>

<first>john</first> <middle>fitzgerald</middle> <last>doe</last> Or <first>john</first> <last>doe</last> <middle>fitzgerald</middle>

<attribute> Declarations Attribute declarations are similar to element declarations There are 2 primary method for declaring attributes Local type Global type Unlike element declarations, attribute declarations are restricted to simple type

<attribute> declaration format <attribute name= name of the attribute type= global type ref= global attribute declaration form= qualified or unqualified use= optional or prohibited or required default= default value fixed= fixed value >

Creating a local type <attribute name= title > <simpletype> <!-- type information --> </simpletype> </element>

Creating a global type <schema xmlns= http://www.w3.org/2001/xmlschema xmlns:contacts= http://www.example.com/contacts targetnamespace= http://www.example.com/contacts elementformdefault= qualified > <simpletype name= KindType > <!-- type information --> </simpletype> <element name= phone > <complextype> <!-- content model information --> <attribute name= kind type= contacts:kindtype /> </complextype> </element> </schema>

<schema xmlns= http://www.w3.org/2001/xmlschema xmlns:contacts= http://www.example.com/contacts targetnamespace= http://www.example.com/contacts elementformdefault= qualified > <attribute name= test type= string /> <element name= phone > <complextype> <!-- content model information --> <attribute ref= contacts:test /> </complextype> </element> </schema>

Attribute use Use to specify that an attribute is required or optional or prohibited Default and fixed Allow declaring default and fixed value Example <attribute name= kind type= contacts:kindtype default= Home /> <attribute name= version type= string fixed= 1.0 />

<attributegroup> Declarations Define reusable groups of attributes <attributegroup name= ContactAttributes > <attribute name= version type= string fixed= 1.0 /> <attribute name= source type= string /> </attributegroup> <element name= contacts > <complextype> <sequence> <element name= contact minoccurs= 0 maxoccurs= unbounded > <complextype> <sequence> <element name= name type= contacts:nametype /> <element name= location type= contacts:locationtype /> </sequence> </complextype> </element> </sequence> <attributegroup ref= contacts:contactattributes /> </complextype> </element>

<element name= latitude type= float /> <element name= longitude type= float /> <attributegroup name= ContactAttributes > <attribute name= version type= decimal fixed= 1.0 /> <attribute name= source type= string /> </attributegroup>

<simpletype> Declaration User-defined datatypes Every <simpletype> definition is derived from another datatype <simpletype> definitions are often called derived types There are 3 primary derived types: Restriction types List types Union types

<restriction> Declaration <attribute name= kind > <simpletype> <restriction base= string > <enumeration value= Home /> <enumeration value= Work /> <enumeration value= Cell /> <enumeration value= Fax /> </restriction> </simpletype> </attribute>

<list> Declaration <simpletype name= ContactTagsType > <restriction base= string > <enumeration value= author /> <enumeration value= xml /> <enumeration value= poetry /> <enumeration value= consultant /> <enumeration value= CGI /> <enumeration value= semantics /> <enumeration value= animals /> </restriction> </simpletype> <simpletype name= ContactTagsListType > <list itemtype= contacts:contacttagstype /> </simpletype>

<union> Declarations <simpletype name= UnknownString > <restriction base= string > <enumeration value= Unknown /> </restriction> </simpletype> <simpletype name= UnknownOrFloatType > <union membertypes= float contacts:unknownstring /> </simpletype>

<element name= latitude type= contacts:unknownstringorfloattype /> <element name= longitude type= contacts:unknownstringorfloattype /> <latitude>43.847156</latitude> <longitude>unknown</longitude> <latitude>unknown</latitude> <longitude>43.847156 Unknown</longitude>