XML Schemas Microsoft XML Schemas W3C XML Schemas.

Slides:



Advertisements
Similar presentations
CSCI N241: Fundamentals of Web Design Copyright ©2004 Department of Computer & Information Science Introducing XHTML: Module B: HTML to XHTML.
Advertisements

Defining XML The Document Type Definition. Document Type Definition text syntax for defining –elements of XML –attributes (and possibly default values)
What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
 Fundamentals of Web Design.  Describe the history and theory of XHTML  Understand the rules for creating valid XHTML documents  Apply a DTD to an.
© De Montfort University, XML – a meta language Howell Istance and Peter Norris School of Computing De Montfort University.
XML 6.3 DTD 6. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:  Elements.
1 XML DTD & XML Schema Monica Farrow G30
Tutorial 9 Working with XHTML
XML Study-Session: Part II Validating XML Documents.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 – Schemas Outline 7.1Introduction 7.2Schemas vs. DTDs 7.3Microsoft XML Schema: Describing Elements.
XHTML1 Building Document Structure. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML) documents.
Document Type Definitions
2/9/00 EECS 684: Current Topics in Databases1 ( W3C Working Draft 17 December 1999 )
 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
XML Verification Well-formed XML document  conforms to basic XML syntax  contains only built-in character entities Validated XML document  conforms.
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Introducing XHTML: Module B: HTML to XHTML. Goals Understand how XHTML evolved as a language for Web delivery Understand the importance of DTDs Understand.
Unit 4 – XML Schema XML - Level I Basic.
Introduction to XML This material is based heavily on the tutorial by the same name at
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.
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.
XML eXtensible Markup Language by Darrell Payne. Experience Logicon / Sterling Federal C, C++, JavaScript/Jscript, Shell Script, Perl XML Training XML.
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.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
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.
1/14 ITApplications XML Module Session 2: Using and Creating XML Documents.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 – Schemas Outline 7.1Introduction 7.2Schemas vs. DTDs 7.3Microsoft XML Schema: Describing Elements.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
Introduction to XML. What is XML? Extensible Markup Language XML Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a.
XHTML1 Building Document Structure Chapter 2. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML)
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
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.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
XML TUTORIAL Portions from w3 schools By Dr. John Abraham.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 6 – Document Type Definition (DTD) Outline 6.1Introduction 6.2Parsers, Well-formed and Valid XML.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
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 –
XML - DTD Week 4 Anthony Borquez. What can XML do? provides an application independent way of sharing data. independent groups of people can agree to.
New Perspectives on XML, 2nd Edition
An OO schema language for XML SOX W3C Note 30 July 1999.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
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.
An Introduction to XML Sandeep Bhattaram
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
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
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.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Schema Lecture 3. Indicators There are seven indicators: Order indicators: All Choice Sequence Occurrence indicators: maxOccurs minOccurs Group indicators:
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
DTD Document Type Definition. Agenda Introduction to DTD DTD Building Blocks DTD Elements DTD Attributes DTD Entities DTD Exercises DTD Q&A.
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
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.
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.
Presentation transcript:

XML Schemas Microsoft XML Schemas W3C XML Schemas

Objectives of Schemas To understand what a schema is. To understand the basic differences between DTDs and schema. To be able to create Microsoft XML Schema. To become familiar with both Microsoft XML Schema and W3C XML Schema. To use schema to describe elements and attributes. To use schema data types.

In Chapter 5 (XML Step by Step), we studied Document Type Definitions (DTDs). These describe an XML document's structure. DTDs are inherited from SGML. Many developers in the XML community feel DTDs are not flexible enough to meet today's programming needs.

For example, DTDs cannot be manipulated (e.g., searched, transformed into different representation such as HTML, etc.) in the same manner as XML documents can because DTDs are not XML documents.

From DTDs to Schemas We introduce an alternative to DTDs— called schemas—for validating XML documents. Like DTDs, schemas must be used with validating parsers. Schemas are expected to replace DTDs as the primary means of describing document structure.

Schema Models Two major schema models exist: W3C XML Schema and Microsoft XML Schema. Because W3C XML Schema technology is still in the early stages of development, we focus primarily on the well-developed Microsoft XML Schema. [Note: New schema models (e.g., RELAX— are beginning to emerge.]

Schemas vs. DTDs We highlight a few major differences between XML Schema and DTDs. A DTD describes an XML document's structure—not its element content. For example, 5 contains character data.

Element quantity can be validated to confirm that it does indeed contain content (e.g., PCDATA ), but its content cannot be validated to confirm that it is numeric; DTDs do not provide such a capability. So, unfortunately, markup such as hello is also considered valid.

With XML Schema, element quantity 's data can indeed be described as numeric. When the preceding markup examples are validated against an XML Schema that specifies element quantity 's data must be numeric, 5 conforms and hello fails.

An XML document that conforms to a schema document is schema valid and a document that does not conform is invalid.

Unlike DTDs, schema do not use the Extended Backus-Naur Form (EBNF) grammar. Instead, schema use XML syntax. Because schemas are XML documents, they can be manipulated (e.g., elements added, elements removed, etc.) like any other XML document. Later, we will discuss how to manipulate XML documents programmatically.

We begin our discussion of Microsoft XML Schema. We discuss several key schema elements and attributes, which are used in the examples. We also present our first Microsoft XML Schema document and use Microsoft's XML Validator to check it for validity. XML Validator also validates documents against DTDs as well as schema.

Microsoft XML Schema: Describing Elements To use Microsoft XML Schema, Microsoft's XML parser (msxml) is required; this parser is part of Internet Explorer 5.

Elements are the primary building blocks used to create XML documents. In Microsoft XML Schema, element ElementType defines an element. ElementType contains attributes that describe the element's content, data type, name, etc.

The application using the XML document containing this markup would need to test if quantity is numeric and take appropriate action if it is not.

The Fig. 7.1 presents a complete schema. This schema describes the structure for an XML document that marks up messages passed between users. We name the schema intro- schema.xml. In Fig 7.2, we show, in the browser Internet Explorer, a document that conforms to this schema.

<Schema xmlns = "urn:schemas-microsoft-com:xml- data"> 8 10 Text messages

Line 7 <Schema xmlns = "urn:schemas-microsoft- com:xml-data" > declares the Microsoft XML Schema root element. Element Schema is the root element for every Microsoft XML Schema document.

The xmlns attribute specifies the default namespace for the Schema element and the elements it contains. The attribute value urn:schemas- microsoft-com:xml-data specifies the URI for this namespace.

Microsoft Schema documents always use this URI because it is recognized by msxml. Microsoft's XML parser recognizes element Schema and this particular namespace URI and also it validates the schema.

Element Schema can contain only elements ElementType —for defining elements, AttributeType —for defining attributes and description —for describing the Schema element. We will discuss each of these elements momentarily.

Lines 8-11 Text messages define element message, which can contain only text, because attribute content is textOnly.

Attribute model has the value closed (line 9)—indicating that only elements declared in this schema are permitted in a conforming XML document. Any elements not defined in this schema would invalidate the document.

We will elaborate on this when we discuss an XML document that conforms to the schema ( Fig 7.2). Element description contains text that describe this schema. In this particular case (line 10), we indicate in the description element that the message element we define is intended to contain Text messages.

Lines 13-16

define element greeting. Because attribute content has the value mixed, this element can contain both elements and character data. The order attribute specifies the number and order of child elements a greeting element may contain.

The value many indicates that any number of message elements and text can be contained in the greeting element in any order. The element element on line 15 indicates message elements (defined on lines 8-11) may be included in a greeting element.

Lines 18 and 19

define element myMessage. The content attribute's value eltOnly specifies that the myMessage element can only contain elements. Attribute order has the value seq, indicating that myMessage child elements must occur in the sequence defined in the schema.

Lines 21-24

indicate that element myMessage contains child elements greeting and message. These elements are myMessage child elements, because the element elements that reference them are nested inside element myMessage. Because the element order in element myMessage is set as sequential, the greeting element (if used) must precede all message elements.

Attributes minOccurs and maxOccurs specify the minimum and maximum number of times the element may appear in the myMessage element, respectively. The value 1 for the minOccurs attribute (line 23) indicates that element myMessage must contain at least one message element.

The value * for the maxOccurs attribute (line 24) indicates that there is no limit on the maximum number of message elements that may appear in myMessage.

Figure 7.2 shows an XML document that conforms to the schema shown in Fig 7.1. We use Microsoft's XML Validator to check the document's conformity. It is available as a free download at

msdn.microsoft.com/dowloads/samples/ internet/xml/xml_validator/sample.asp

Welcome to XML Schema! 9 This is the first message This is the second message. 13

Line 6 references the schema ( Fig 7.1) through the namespace declaration. A document using a Microsoft XML Schema uses attribute xmlns to reference its schema through a URI which begins with x-schema followed by a colon ( : ) and the name of the schema document.

Mixed Content Lines 8-10 Welcome to XML Schema! This is the first message. use element greeting to mark up text and a message element. Recall that in Fig 7.1, element greeting (lines 13-16) may contain mixed content.

Line 12 This is the second message. marks up text in a message element. Line 8 in Fig 7.1 specifies that element message can contain only text.

In the discussion of Fig 7.1, we mentioned that a closed model allows an XML document to contain only those elements defined in its schema. For example, the markup Welcome to XML Schema! This is the first message. A new element.

uses element newElement, which is not defined in the schema. With a closed model, the document containing newElement is invalid. However, with an open model, the document is valid.

Figure 7.3 shows a well-formed document that fails to conform to the schema shown in Fig 7.1, because element message cannot contain child elements.

Figure 7.4 lists the available attributes for the ElementType element. Schema authors use these attributes to specify the properties of an element, such as its content, data type, name, etc. If the content attribute for an ElementType element has the value eltOnly or mixed content, the ElementType may only contain the elements listed in Fig 7.5

Attibute Description ElementType element

ElementType element attributes Content Describes the element's content. The valid values for this attribute are empty (an empty element), eltOnly (may contain only elements), textOnly (may contain only text) and mixed (may contain both elements and text). The default value for this attribute is mixed.

ElementType element attributes Name - The element's name. This is a required attribute. Model - Specifies whether elements not defined in the schema are permitted in the element. Valid values are open (the default, which permits the inclusion of elements defined outside the schema) and closed (only elements defined inside the schema are permitted). We use only closed model s.

ElementType element attributes dt:type - Defines the element's data type. Data types exist for real numbers, integers, booleans, etc. Namespace prefix dt qualifies data types. We discuss data types in detail in Section 7.5.

ElementType element attributes Order Specifies the order in which child elements must occur. The valid values for this attribute are one (exactly one child element is permitted), seq (child elements must appear in the order in which they are defined) and many (child elements can appear in any order, any number of times).

The default value is many if attribute content is mixed and is seq if attribute content has the value eltOnly.

ElementType's child elements description - Provides a description of the ElementType. datatype - Specifies the data type for the ElementType element. We will discuss data types. element - Specifies a child element by name.

group - Groups related element elements and defines their order and frequency. attributeType - Defines an attribute. attribute - Specifies an AttributeType for an element

The element element does not define an element, but rather refers to an element defined by an ElementType. This allows the schema author to define an element once and refer to it from many places inside the schema document. The attributes of the element element are listed in Fig 7.6.

As mentioned in Fig 7.5, element group creates groups of element elements. Groups define the order and frequency in which elements appear using the attributes listed in Fig 7.7.

Element element attributes type - A required attribute that specifies a child element's name (i.e., the name defined in the ElementType ).

Element element attributes minOccurs - Specifies the minimum number of occurrences an element can have. The valid values are 0 (the element is optional) and 1 (the element must occur one or more times). The default value is 1.

Element element attributes maxOccurs Specifies the maximum number of occurrences an element can have. The valid values are 1 (the element occurs at most once) and *... * (the element can occur any number of times). The default value is 1 unless the ElementType 's content attribute is mixed

Element group 's attributes Order Specifies the order in which the element s occur. The valid values are one (contains exactly one child element from the group ), seq (all child elements must appear in the sequential order in which they are listed) and many (the child elements can appear in any order, any number of times).

Element group 's attributes minOccurs Specifies the minimum number of occurrences an element can have. The valid values are 0 (the element is optional) and 1 (the element must occur at least once). The default value is 1.

Element group 's attributes maxOccurs Specifies the maximum number of occurrences an element can have. The valid values are 1 (the element occurs at most once) and * (the element can occur any number of times). The default value is 1 unless the ElementType 's content attribute is mixed.

7.4 Microsoft XML Schema: Describing Attributes

XML elements can contain attributes that describe elements. In Microsoft XML Schema, element AttributeType defines attributes. Figure 7.8 lists AttributeType element attributes.

Like element ElementType element, element AttributeType may contain description elements and datatype elements.

To indicate that an element has an AttributeType, element attribute is used. The attributes of the attribute element are shown in Fig 7.9.