MSc in Communication Sciences 2010-2011 Program in Technologies for Human Communication Davide Eynard Facoltà di scienze della comunicazione Università.

Slides:



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

XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
An Introduction to XML Based on the W3C XML Recommendations.
XML Document Type Definitions ( DTD ). 1.Introduction to DTD An XML document may have an optional DTD, which defines the document’s grammar. Since the.
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.
CSE 636 Data Integration XML Schema. 2 XML Schemas W3C Recommendation: Generalizes DTDs Uses XML syntax Two documents: structure.
XML Schemas Microsoft XML Schemas W3C XML Schemas.
More XML namespaces, DTDs CS 431 – February 16, 2005 Carl Lagoze – Cornell University.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
1 Print your own copy If you bring it along, hand in with your exam script Do not write anything extra or you will be penalized Student Name: Student Number:
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
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Lecture 15 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.
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.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
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.
Chapter 4: Document Type Definitions. Chapter 4 Objectives Learn to create DTDs Validate an XML document against a DTD Use DTDs to create XML documents.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Dr. Azeddine Chikh IS446: Internet Software Development.
Neminath Simmachandran
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.
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.
FIGIS’ML Hands-on training - © FAO/FIGIS An introduction to XML Objectives : –what is XML? –XML and HTML –XML documents structure well-formedness.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
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.
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
An OO schema language for XML SOX W3C Note 30 July 1999.
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
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,
CSE3201 Information Retrieval Systems DTD Document Type Definition.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
COS 381 Day 14. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard
XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References.
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
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
XML Schema (W3C) Thanks to Jussi Pohjolainen TAMK University of Applied Sciences.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
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 Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
Lecture 0 W3C XML Schema. Topics Status Motivation Simple type vs. complex type.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
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.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
XML BASICS and more…. What is XML? In common:  XML is a standard, simple, self-describing way of encoding both text and data so that content can be processed.
XML QUESTIONS AND ANSWERS
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
ece 720 intelligent web: ontology and beyond
New Perspectives on XML
Presentation transcript:

MSc in Communication Sciences Program in Technologies for Human Communication Davide Eynard Facoltà di scienze della comunicazione Università della Svizzera italiana 04 – XML Schemas Software Technology 2

I Facoltà di scienze della comunicazione Università della Svizzera italiana XML: recap and evaluation During last lesson we saw the basics of XML... Tree structure Elements and attributes Content vs presentation... And the basics of XML evaluation Well-formedness (just syntax) Validity wrt a schema 2

I Facoltà di scienze della comunicazione Università della Svizzera italiana Why do we need a schema? XML can be used to describe different data and is totally unaware of what you are speaking about You can check if the syntax is right but you cannot constrain its usage in any way! Example: John Doe SSN should be unique, but a simple check on syntax would not find errors in this code 3

I Facoltà di scienze della comunicazione Università della Svizzera italiana What does a schema do? A schema allows you to define all the elements and attributes that can be used inside an XML document Moreover, you can add constraints specifying: Which are the children of a particular element In which order they appear How many children an element can have If the element is empty or contains text Datatypes for elements and attributes Default values for elements and attributes Given this information, an XML document conforming to a given schema can be validated The document is valid if it is well-formed and it follows the structure given inside the schema Validation can be done automatically by any tool which “understands” the schema language. 4

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD vs XML Schema There are many ways of defining the structure of an XML document i.e. DTD, XML Schema, RELAX NG, Schematron,... DTD and XML Schema are the most used ones, but XML Schema is having more success (W3C recommendation, 2001) because: it is written with XML syntax it supports datatypes it supports namespaces it supports inheritance and data type extension 5

I Facoltà di scienze della comunicazione Università della Svizzera italiana Using a DTD Writing a DTD is just as easy as writing another text file, but how can we use a DTD? How can we say a file should follow a schema? How can we use this information to validate the file? To match a document with a DTD, we should add the following to the xml prolog: To test it, we can use online validators or validating editors Example:... 6

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD Elements – 1 An element can be declared in the following way: or Category = EMPTY Elements containing only a sequence of characters Elements containing any mixture of text and other elements Elements containing one or more children elements Follows the specified order! 7

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD Elements – 2 Example: Hi there! 8

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD Elements – 3 Disjunction: We can use disjunction to specify subelements in generic order:... What if we have 10 subelements? Cardinality: ?zero times or once *zero or more times +one or more times 9

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD Attributes – 1 Attributes are defined in a DTD with an attribute list: For each attribute you have to define: The name of the element it is related to Its name Its type Its value type 10

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD Attributes – 2 Example: Hi there! <!ATTLIST text-message fromCDATA #REQUIRED> 11

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD Attributes – 3 Attribute types: CDATA, a string ID, a name that is unique across the XML document IDREF, a reference to another element with the ID attribute IDREFS, a sequence of IDREF (v1|...|vn), an enumeration of all possible values i.e. weekday (monday|tuesday|...|sunday) Limitations No dates No numbers No booleans 12

I Facoltà di scienze della comunicazione Università della Svizzera italiana DTD Attributes – 4 Attribute value types: #REQUIRED (attribute must appear in every occurrence of the element type in the XML document) #IMPLIED (the appearance of the attribute is optional) #FIXED “value” (every element must have this attribute with this value) “value” (specifies the default value for the attribute) 13

I Facoltà di scienze della comunicazione Università della Svizzera italiana From DTD to XML Schema Main differences between XML DTD and XML Schema: XML Schema's syntax is based on XML itself (you can use the same tools for XML documents and schemas!) It allows the reuse of existing schemas (inheritance) and their refinement (extension) It supports more specific datatypes It supports namespaces Note: XML Schema is also called XML Schema Definition (XSD) 14

I Facoltà di scienze della comunicazione Università della Svizzera italiana Namespaces Elements in XML files can be defined by the developers What if two developers use the same name for different kinds of elements? Example: Apples Bananas African Coffee Table

I Facoltà di scienze della comunicazione Università della Svizzera italiana Namespaces definition We need a way to specify that element names come from two different contexts we put a prefix before element names we specify what namespace that prefix represents Apples Bananas African Coffee Table

I Facoltà di scienze della comunicazione Università della Svizzera italiana Root and default namespaces You can also define all the namespaces you are going to use in the root element of your XML document: <root xmlns:h = " xmlns:f = " If the xmlns attribute is not followed by a prefix, then the specified namespace is considered as the default one 17

I Facoltà di scienze della comunicazione Università della Svizzera italiana Documents using XML Schema How is the prolog of XML documents using an XML Schema? <messages xmlns = " xmlns:xsi = " xsi:schemaLocation = " 18

I Facoltà di scienze della comunicazione Università della Svizzera italiana XML Schema opening tag An XML schema is an XML document whose root element is called schema and is defined like follows: <xs:schema xmlns:xs = " targetNamespace = " xmlns = " elementFormDefault = "qualified"> Source, target, and default ns Notes: the xs:schema element is the root of every XML schema qualified = “Associated with a namespace, either by the use of a declared prefix or via a default namespace declaration”. More details herehere 19

I Facoltà di scienze della comunicazione Università della Svizzera italiana The four constructs of XML Schema XML Schema is built on four constructs: A simple type definition defines a family of text strings (Unicode) A complex type definition defines a collection of requirements for attributes, sub-elements, and char data An element declaration associates an element name with either a simple type or a complex type An attribute declaration associates an attribute name with a simple type (attributes always contain unstructured text) 20

I Facoltà di scienze della comunicazione Università della Svizzera italiana XML Schema Elements and Types To declare an element (equivalent to in a DTD) you have to use the “element” tag: The most important (optional) attribute is type, as it defines the element's content type: 21

I Facoltà di scienze della comunicazione Università della Svizzera italiana Cardinality and default values To change cardinality, you can use the (optional) attributes minoccurs and maxoccurs: Note: minoccurs=”x”, where x is an integer >=0 maxoccurs=”x”, where x is an integer >0 or “unbounded” The default is “1” in both cases Also, default or fixed values can be specified: 22

I Facoltà di scienze della comunicazione Università della Svizzera italiana XML Schema Attributes and Types To declare an attribute use the “attribute” tag (very similar to the “element” one): Similarly to element, attributes can have types, default, and fixed values: Attributes are optional by default. You can use the use attribute to make them required: 23 Note: Attributes can be defined only within a complex element type (see later)

I Facoltà di scienze della comunicazione Università della Svizzera italiana XML Schema built-in data types 24

I Facoltà di scienze della comunicazione Università della Svizzera italiana Simple derived types Derived datatypes (such as integer), are built from the original ones using Restrictions Lists Unions 25

I Facoltà di scienze della comunicazione Università della Svizzera italiana Complex types Complex types are used to define elements which contain attributes, text, other elements, or any combination of these They are built using the following operators Element references, such as Concatenation, using the sequence element Union, using a choice element The all element (like sequence but unordered) The any construct The group element (to allow references to item groups) MinOccurs and maxOccurs attributes to define cardinalities The mixed (boolean) attribute to allow mixed content 26

I Facoltà di scienze della comunicazione Università della Svizzera italiana An example 27 <xsd:element name=“firstname” type=“xsd:string” minOccurs=“0” maxOccurs=“unbounded”/> <xsd:attribute name=“title” type=“xsd:string” use=“optional” /> Davide Eynard

I Facoltà di scienze della comunicazione Università della Svizzera italiana Schema extension Modularization is allowed by the following three constructs:... Inheritance and extensions Restrictions 28

I Facoltà di scienze della comunicazione Università della Svizzera italiana Limitations of XML Schema XML Schema is much more powerful and expressive than DTDs, however it still has some limitations: Too difficult for non-experts (problem: non-experts need to read the schema to write valid XML documents!) Element and attribute declarations are context insensitive Although XML Schema is built with XML, it still does not have a complete XML Schema Technical limitations When describing mixed content, the character data cannot be constrained in any way A schema cannot enforce a particular root element Element defaults cannot contain markup, but only character data... and many others 29

I Facoltà di scienze della comunicazione Università della Svizzera italiana References Some Web references: G. Antoniou and F. van Harmelen “A Semantic Web Primer”, The MIT Press Chapter 2 slides: M.C. Daconta, L.J. Obrst, and K.T. Smith. “The Semantic Web”, Wiley, Chapter 3 online: W3 School website, in particular and Anders Møller and Michael I. Schwartzbach. “An Introduction to XML and Web Technologies”, Addison-Wesley, Chapter 4 (Schema Languages) online: Examples from Elizabeth Castro, “XML for the World Wide Web: Visual Quickstart Guide”, Peachpit Press, Tools: XML Validation Services: XML Copy Editor, a free (as in freedom), multiplatform editor which supports validation: Validator, a free (as in freedom), multiplatform, drag and drop XML validator which works on Windows, Linux, and Mac OS X: