XML Schema Basics SD2520 Databases using XML and Jquery Chapter 12

Slides:



Advertisements
Similar presentations
XML Schema Heewon Lee. Contents 1. Introduction 2. Concepts 3. Example 4. Conclusion.
Advertisements

1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
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
SDPL 2003Notes 2: Document Instances and Grammars1 2.5 XML Schemas n A quick introduction to XML Schema –W3C Recommendation, May 2, 2001: »XML Schema Part.
XHTML1 Building Document Structure. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML) documents.
XML Schemas Microsoft XML Schemas W3C XML Schemas.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
Lecture 14 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
DECO 3002 Advanced Technology Integrated Design Computing Studio Tutorial 6 – XML Schema School of Architecture, Design Science and Planning Faculty of.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Unit 4 – XML Schema XML - Level I Basic.
Introduction to XML This material is based heavily on the tutorial by the same name at
Introducing HTML & XHTML:. Goals  Understand hyperlinking  Understand how tags are formed and used.  Understand HTML as a markup language  Understand.
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
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
Lecture 15 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
SDPL 2002Notes 2: Document Instances and Grammars1 2.5 XML Schemas n A quick introduction to XML Schema –W3C Recommendation, May 2, 2001: »XML Schema Part.
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.
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.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
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.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
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.
Session IV Chapter 9 – XML Schemas
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
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 2nd EDITION Tutorial 1 Creating An Xml Document.
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
XP 1 Creating an XML Document Developing an XML Document for the Jazz Warehouse XML Tutorial.
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.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Understanding How XML Works Ellen Pearlman Eileen Mullin Programming 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
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.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
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.
XML blocks XML STRUCTURE The most basic building blocks of an XML file are elements, attributes and comments. Compiled based on Tutorial PhUSE 2008 XML.
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.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
SDPL : 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.
1 XML and XML in DLESE Katy Ginger November 2003.
XML Schemas Dr. Awad Khalil Computer Science Department AUC.
XML QUESTIONS AND ANSWERS
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
New Perspectives on XML
New Perspectives on XML
Presentation transcript:

XML Schema Basics SD2520 Databases using XML and Jquery Chapter 12 http://www.distance-education.itt- tech.edu/itt/clikslogin

XML Schema The specifications for XML include the syntax for a schema language: A way to define what a valid XML document could contain. This language, known as a DTD (Document Type Definition). It enables users to define elements, attributes, and their relationships for any application of XML needed.

new schema language In 2001, the W3C developed a new schema language to address many of the shortcomings of DTD. This schema language was named XML Schema, which is admittedly confusing because DTDs are a type of XML schema (lower case “s”). Even still, it’s most often called XML Schema, though it is occasionally called XML Schema Definition (XSD). Version 1.1 of the language is known as XML Schema Definition Language (XSDL). For this book, we use the name XML Schema, which is still the most widely recognized name of them all.

XML Schema XML Schema, written in XML itself, is deeper and more powerful than a DTD. A few examples of its strength include its system of data types that let you specify when an element should contain one of these: an integer or a period of time or a string. It also lets you define both local and global elements, allowing two elements to have different definitions, sharing the same name. XML Schema gives you much more control over the contents of an XML document, and will likely supplant DTDs as the most widely accepted schema language in the near future.

WORKING WITH XML SCHEMA An XML Schema specifies the structure of valid XML documents (Figure 12-1) by defining: a set of elements their relationships to each other the attributes that they can contain. In a DTD, all XML elements are defined using one element type. In XML Schema, an XML element can be defined as either a simple type or a complex type. A simple type is an XML element that only contains text A complex type is an XML element that contains child elements and/or attributes.

FIGURE 12-1 Here is one of the first XML documents used in the book. FIGURE 12-2 These elements are defined using XML Schema’s built-in simple data types. The name and location elements must be strings, and the height element must be an integer.

Simple vs. complex types Where simple type elements describe the text of an XML document, complex type elements describe its structure.

Simple vs. complex types There are four kinds of complex type elements: those that contain child elements; those that contain both child elements and text; those that contain only text; those that are empty.

Remember One of the benefits of XML Schema is that it uses XML syntax, which you probably already know by now Because an XML Schema is an XML document, it must: begin with an XML declaration have one root element be well-formed, just like all other XML documents

Note The W3C is working towards the completion of XML Schema Version 1.1. It is being developed to fix bugs and make improvements where possible, while maintaining the same basic scope as (and remaining mostly compatible with) version 1.0. You can find up-to-date information at the W3C’s XML Schema Working Group site at: www.w3.org/XML/Schema.

Beginning a Schema – page 209 An XML Schema is a text-only document, and begins with a standard XML declaration. It is customarily saved with an .xsd extension, and its root element must be schema. To begin an XML Schema: At the top of your document, type <?xml version=”1.0”?>. Type <xs:schema to define the root element. The xs: is a namespace prefix (see Tip on namespaces below). Then, type mlns:xs=”http://www.3.org/2001/XMLSchema” to declare the XML Schema namespace (xmlns). This also declares that the elements and data types that are part of this namespace should be prefixed with xs: as you saw in Step 2 above. Type > to complete the root element’s tag. Leave a few empty lines for your XML Schema’s rules. Finally, type </xs:schema> to complete the root element, and the XML Schema document itself (Figure 12-5).

An XML Schema FIGURE 12-5 An XML Schema is an XML document itself. The root element must be schema, and its namespace is declared to be the W3C’s XML Schema namespace.

Tips A namespace is a “space” in which names reside. Names that are part of one namespace are not the same as names that are part of another namespace (even if they are spelled the exact same way). The W3C created a namespace which contains all XML Schema elements and data types. This namespace is declared in Step 3 above. Once declared, in order to indicate that a particular element or data type should be considered part of the W3C’s XML Schema namespace, it must start with the xs: namespace prefix (Figure 12- 6).

ASSOCIATING AN XML SCHEMA WITH AN XML DOCUMENT To validate an XML document against an XML Schema, you must specify the location of the XML Schema in the XML document itself. To declare the XML Schema and its location: Inside the definition of the root element of your XML document, type xmlns:xsi=“http://www.w3.org/2001/ XMLSchema”. This allows you to define the location of your XML Schema in the next two steps. Type xsi:noNamespaceSchemaLocation= Finally, type “xsd.uri”, where xsd.uri is the location of the XML Schema file against which you want to validate your XML file (Figure 12-7).

location of the XML Schema file Most XML parsers can validate XML documents against a declared XML Schema (Figure 12-8). If the XML parser you are using cannot, there are validators available online that can. The W3C has a validator at: www.w3.org/2001/03/webdata/xsv. There are other validators listed at: www.w3.org/XML/Schema. The “xsd.uri” in Step 3 above can refer to a file on the Internet, local area network, or your local computer. Step 1 above declares the XML Schema Instance namespace which includes the xsi:noNamespaceSchemaLocation attribute used in Step 2, along with a few other namespace attributes. FIGURE 12-7 In order to associate an XML Schema with an XML document, you must declare the XML Schema document location within the root element of the XML document

XML Schema association FIGURE 12-8 Here, I’ve added the XML Schema association to the XML document from Figure 12-1. Then, when checked, this XML document is valid against the XML Schema in Figure 12-6.

ANNOTATING SCHEMAS Since an XML Schema is an XML document, you can include standard XML comments in your XML Schema documents (see page 16 ). In addition to these standard comments, XML Schema offers the ability to add more structured comments to your document. XML comments are readable by people, they are ignored by parsers, and often not passed through during XML transformations. XML Schema comments (annotations, as they are called), can be parsed and processed, because they are elements themselves (Figure 12-9).

To annotate XML Schemas: 1. Type <xs:annotation>. 2. Next, type <xs:documentation> to begin the comment. 3. Type the comment. 4. Type </xs:documentation> to complete the comment. 5. Finally, type </xs:annotation> to complete the annotation. FIGURE 12-9 An annotation helps you document the XML Schema. It can facilitate future revisions.

XSD (XML Schema Definition) XSD is a Recommendation of the World Wide Web Consortium (W3C), specifies how to formally describe the elements in an Extensible Markup Language (XML) document. It can be used by programmers to verify each piece of item content in a document. They can check it adheres to the description of the element it is placed in. http://en.wikipedia.org/wiki/XML_Schema_(W3C)

XSD: expressing a set of rules Like all XML schema languages, XSD can be used to express a set of rules to which an XML document must conform in order to be considered 'valid' according to that schema. However, unlike most other schema languages, XSD was also designed with the intent that determination of a document's validity would produce a collection of information adhering to specific data types. Such a post-validation infoset can be useful in the development of XML document processing software. The schema language's dependence on specific data types has provoked criticism http://en.wikipedia.org/wiki/XML_Schema_(W3C)

Schemas and Schema Documents A schema is an abstract collection of metadata, consisting of a set of schema components: chiefly element and attribute declarations and complex and simple type definitions. These components are usually created by processing a collection of schema documents, which contain the source language definitions of these components. In popular usage, however, a schema document is often referred to as a schema. http://en.wikipedia.org/wiki/XML_Schema_(W3C)

Schema Documents: namespace Schema documents are organized by namespace: all the named schema components belong to a target namespace, and the target namespace is a property of the schema document as a whole. A schema document may include other schema documents for the same namespace, and may import schema documents for a different namespace. http://en.wikipedia.org/wiki/XML_Schema_(W3C)

Assesment! When an instance document is validated against a schema (a process known as assessment) The schema to be used for validation can either be supplied as a parameter to the validation engine, or it can be referenced directly from the instance document using: Two special attributes: xsi:schemaLocation xsi:noNamespaceSchemaLocation. (The latter mechanism requires the client invoking validation to trust the document sufficiently to know that it is being validated against the correct schema. "xsi" is the conventional prefix for the namespace "http://www.w3.org/2001/XMLSchema-instance".) XML Schema Documents usually have the filename extension ".xsd". A unique Internet Media Type is not yet registered for XSDs, so "application/xml" or "text/xml" should be used, as per RFC 3023.

Main Schema components Element declarations, which define properties of elements. These include the element name and target namespace. Elements may have integrity constraints: uniqueness constraints determining that particular values must be unique within the subtree rooted at an element, and referential constraints determining that values must match the identifier of some other element. Element declarations may be global or local, allowing the same name to be used for unrelated elements in different parts of an instance document.

Main Schema components Attribute declarations, which define properties of attributes. The properties include the attribute name and target namespace. The attribute type constrains the values that the attribute may take. An attribute declaration may also include a default value or a fixed value (which is then the only value the attribute may take.)

Main Schema components Simple and complex types. These are described in the following section. Model group and attribute group definitions. These are essentially macros: named groups of elements and attributes that can be reused in many different type definitions. An attribute use represents the relationship of a complex type and an attribute declaration, and indicates whether the attribute is mandatory or optional when it is used in that type.

Main Schema components An element particle similarly represents the relationship of a complex type and an element declaration, and indicates the minimum and maximum number of times the element may appear in the content. As well as element particles, content models can include model group particles, which act like non-terminals in a grammar: they define the choice and repetition units within the sequence of permitted elements. The wildcard particles are allowed, which permit a set of different elements (perhaps any element provided it is in a certain namespace).

Main Schema Types - Complex Complex types describe the permitted content of an element, including its element and text children and its attributes. A complex type definition consists of a set of attribute uses and a content model. Varieties of content model include element-only content, in which no text may appear (other than whitespace, or text enclosed by a child element); simple content, in which text is allowed but child elements are not; empty content, in which neither text nor child elements are allowed; and mixed content, which permits both elements and text to appear. A complex type can be derived from another complex type by restriction (disallowing some elements, attributes, or values that the base type permits) or by extension (allowing additional attributes and elements to appear). In XSD 1.1, a complex type may be constrained by assertions —X-Path 2.0 expressions evaluated against the content that must evaluate to true.

Main Schema Types - Simple Simple types (also called data types) constrain the textual values that may appear in an element or attribute. This is one of the more significant ways in which XML Schema differs from DTDs. For example, an attribute might be constrained to hold only a valid date or a decimal number. XSD provides a set of 19 primitive data types (anyURI, base64Binary, boolean, date, dateTime, decimal, double, duration, float, hexBinary, gDay, gMonth, gMonthDay, gYear, gYearMonth, NOTATION, QName, string, and time). It allows new data types to be constructed from these primitives by three mechanisms: restriction (reducing the set of permitted values), list (allowing a sequence of values), and union (allowing a choice of values from several types).

Chapter 12 Tips Whether you use XML comments, XML Schema annotations (or both), commenting your XML Schema makes it much easier to work with your documents. You can create annotations anywhere in the XML Schema, after the root element. They can be placed: just after the xs:schema root element (to comment on the entire schema), or just after individual element definitions (to give more information about them), or both.