1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.

Slides:



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

Tutorial 6 Creating a Web Form
Tutorial 9 Working with XHTML
XML Schemas Microsoft XML Schemas W3C XML Schemas.
XML Schema Definition Language
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.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Unit 4 – XML Schema XML - Level I Basic.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
17 Apr 2002 XML Schema Andy Clark. What is it? A grammar definition language – Like DTDs but better Uses XML syntax – Defined by W3C Primary features.
Working with Namespaces Combining XML Vocabularies in a Compound Document.
WORKING WITH NAMESPACES
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
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.
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.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
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.
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
Session IV Chapter 9 – XML Schemas
XML TUTORIAL Portions from w3 schools By Dr. John Abraham.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
XP 1 TUTORIAL 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and.
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.
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.
An OO schema language for XML SOX W3C Note 30 July 1999.
XP New Perspectives on XML, 2nd Edition Tutorial 2 1 TUTORIAL 2 WORKING WITH NAMESPACES.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
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.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
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.
Tutorial 13 Validating Documents with Schemas
1 Tutorial 12 Working with Namespaces Combining XML Vocabularies in a Compound Document.
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
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.
XML Validation II Schemas Robin Burke ECT 360. Outline Namespaces Documents  Data types XML Schemas Elements Attributes Derived data types RELAX NG.
XML Module 1 Creating an XML Document. XP Objectives Session 1.1 – Describe the history of XML and the uses of XML documents – Understand XML vocabularies.
1 Compound Documents: Combining XML Vocabularies.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XP Tutorial 9New Perspectives on HTML and XHTML, Comprehensive 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
XML Schema Lecture 3. Indicators There are seven indicators: Order indicators: All Choice Sequence Occurrence indicators: maxOccurs minOccurs Group indicators:
XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
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.
XML SCHEMA 1 CH 20. Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving.
Web Services: Principles & Technology Slide 3.1 Chapter 3 Brief Overview of XML COMP 4302/6302.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
1 XML and XML in DLESE Katy Ginger November 2003.
Tutorial 9 Working with XHTML
WORKING WITH NAMESPACES
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Session III Chapter 6 – Creating DTDs
Working with Namespaces and Schemas
Session II Chapter 6 – Creating DTDs
New Perspectives on XML
Presentation transcript:

1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Introducing XML Schemas A schema is an XML document that contains validation rules for an XML vocabulary. The XML document containing the content is called the instance document.

Comparing Schemas and DTDs New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 3

4 Schema Vocabularies There is no single schema form. Several schema “vocabularies” have been developed in the XML language. Support for a particular schema depends on the XML parser being used for validation.

Schema Vocabularies New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 5

6 Starting a Schema File A schema is always placed in a separate XML document that is referenced by the instance document. The root element in any XML Schema document is the schema element. content

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 7 Understanding Simple and Complex Types XML Schema recognize two categories of element types: simple and complex. A simple type contains a single value. A complex type contains two or more values or elements placed within a defined structure.

Understanding Simple and Complex Types New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 8

Simple and Complex Types in the patients.xml Document New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 9

10 Defining a Simple Type Element Use the following syntax to declare a simple type element in XML Schema: Here, name is the name of the element in the instance document and type is the data type of the element. If a namespace prefix is used with the XML Schema namespace, any XML Schema tags must be qualified with the namespace prefix.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 11 Understanding Data Types XML Schema supports two data types: built-in and user- derived. A built-in data type is part of the XML Schema specifications and is available to all XML Schema authors. A user-derived data type is created by the XML Schema author for specific data values in the instance document.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 12 Defining an Attribute An attribute is another example of a simple type. The syntax to define an attribute is Where name is the name of the attribute, type is the data type, default is the attribute’s default value, and fixed is a fixed value for the attribute.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 13 Defining a Complex Type Element The basic structure for defining a complex type element with XML Schema is declarations where name is the name of the element and declarations are declarations that declare the type of content contained within the element.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 14 Defining a Complex Type Element Four complex type elements that usually appear in an instance document are the following: –The element is an empty element and contains only attributes. –The element contains textual content and attributes but no child elements. –The element contains child elements but no attributes. –The element contains both child elements and attributes.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 15 Defining an Element Containing Only Attributes The code to declare the attributes of an empty element is attributes where name is the name of the element in the instance document and attributes is the set of simple type elements that define the attributes associated with the element

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 16 Defining an Element Containing Attributes and Basic Text If an element is not empty and contains textual content (but no child elements), the structure of the complex type element is slightly different. attributes

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 17 Referencing an Element or Attribute Definition XML Schema allows for a great deal of flexibility in designing complex types. Rather than nesting the attribute declaration within the element, you can create a reference to it. The code to create a reference to an element or attribute declaration is Where elemName is the name used in an element declaration and attName is the name used in an attribute declaration

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 18 Defining an Element with Nested Children Another kind of complex type element contains nested child elements, but no attributes. To define these child elements, use the code structure elements where name is the name of the element, compositor defines how the child elements are organized, and elements is a list of the nested child elements

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 19 Defining an Element with Nested Children XML Schema supports the following compositors: –sequence defines a specific order for the child elements –choice allows any one of the child elements to appear in the instance document –all allows any of the child elements to appear in any order in the instance document; however, they must appear either only once or not all.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 20 Defining an Element Containing Nested Elements and Attributes The code for a complex type element that contains both child elements and attributes is elements attributes

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 21 Specifying Mixed Content When the mixed attribute is set to the value “true,” XML Schema assumes that the element contains both text and child elements. The structure of the child elements can then be defined with the conventional method. For example, the XML content Patient Cynthia Davis was enrolled in the Tamoxifen Study on 8/15/2003. can be declared in the schema file using the following complex type:

Indicating Required Attributes An attribute may or may not be required with a particular element element content where name is the name of the element containing the attribute, element content is XML Schema code that defines the content and structure of the element, properties is XML Schema code that defines the data type and properties of the attribute, and use has one of the following three values (required, optional, or prohibited) New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 22

Specifying the Number of Child Elements To specify the number of times an element appears in the instance document, you can apply the minOccurs and maxOccurs attributes to the element definition where the minOccurs value defines the minimum times the element can occur and the maxOccurs value defines the maximum number of times the element can occur New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 23

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 24 Applying a Schema to an Instance Document To attach a schema to the document, you must do the following: –Declare a namespace for XML Schema in the instance document. –Indicate the location of the schema file. To declare the XML Schema namespace in the instance document, you add the following attribute to the document’s root element: xmlns:xsi="

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 25 Applying a Schema to an Instance Document If there is no namespace for the contents of the instance document, add the following attribute to the root element: xsi:noNamespaceSchemaLocation="schema"

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 26 Validating with Built-in Data Types A primitive data type, also called a base type, is one of 19 fundamental data types not defined in terms of other types. A derived data type is a data type that is developed from one of these base types.

Validating with Built-in Data Types New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 27

String Data Types New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 28

Numeric Data Types New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 29

Date and Time Data Types New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 30

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 31 Deriving Customized Data Types Three components are involved in deriving new data types: –Value space: the set of values that correspond to the data type. –Lexical space: the set of textual representations of the value space. –Facets: the properties of the data type that distinguish one data type from another.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 32 Deriving Customized Data Types New data types fall into three categories: –List: a list of values where each list is derived from a base type. –Union: the combination of two or more data types. –Restriction: a limit placed on the facet of a base type.

Constraining Facets New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 33

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 34 Deriving Data Types Using Regular Expressions A regular expression is a text string that defines a character pattern To apply a regular expression in a data type, you use the code Where regex is a regular expression pattern.

Regular Expression Quantifiers New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 35

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 36 Working with Named Types XML Schema also allows schema authors to create customized complex types. The advantage of creating a complex type is that the complex structure can be reused in the document. For example, the following code declares an element named client containing the complex content of two child elements named firstName and lastName:

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 37 Named Model Groups A named model group is a collection, or group, of elements. The syntax for creating a model group is elements where name is the name of the model group, and elements is a collection of element declarations

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 38 Named Attribute Groups Attributes can be grouped into collections called named attribute groups. This is particularly useful for attributes that you want to use with several different elements in a schema. The syntax for a named attribute group is attributes where name is the name of the attribute group and attributes is a collection of attributes assigned to the group.

Designing a Schema One schema design is a Flat Catalog Design. In this design, all element declarations are made globally. The structure of the instance document is created by referencing the global element declarations. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 39

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 40 Flat Catalog Design

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 41 Russian Doll Design Schemas can be structured in a number of ways. One structure is called a Russian doll design. This design involves sets of nested declarations. While this design makes it easy to associate the schema with the instance document, it can be confusing and difficult to maintain.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 42 Russian Doll Design

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 43 Venetian Blind Design A Venetian blind design is similar to a flat catalog, except that instead of declaring elements and attributes globally, it creates named types and references those types within a single global element In this layout, the only globally declared element is the patients element; all other elements and attributes are placed within element or attribute groups or, in the case of the performance element, within a named complex type

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 44 Venetian Blind Design

Comparison of Schema Designs New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 45

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 46 Associating a Schema with a Namespace To associate a schema with a namespace, you first declare the namespace and then make that namespace the target of the schema. To do this, you add the following attributes to the schema’s root element: <xs:schema xmlns:xs=" xmlns="prefix:uri" targetNamespace="uri">... where prefix is the prefix of the namespace and uri is the URI of the namespace

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 47 Validating a Combined Document

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 48 Including and Importing Schemas To include a schema from the same namespace, add the following element as a child of the schema element: Where schema is the name and location of the schema file. To import a schema from a different namespace, use the syntax Where uri is the URI of the imported schema’s namespace and schema is the name and location of the schema file.

New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 49 Referencing Objects from Other Schemas Once a schema is imported, any objects it contains with global scope can be referenced To reference an object from an imported schema, you must declare the namespace of the imported schema in the schema element You can then reference the object using the ref attribute or the type attribute for customized simple and complex types