XML Schema Laurea Magistrale in Informatica Chapter 04 Modulo del corso Thecnologies for Innovation.

Slides:



Advertisements
Similar presentations
SE 5145 – eXtensible Markup Language (XML ) XML Schema /Spring, Bahçeşehir University, Istanbul.
Advertisements

XML Schema Heewon Lee. Contents 1. Introduction 2. Concepts 3. Example 4. Conclusion.
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.
17 Apr 2002 XML Syntax: DTDs Andy Clark. Validation of XML Documents XML documents must be well-formed XML documents may be valid – Validation verifies.
XML: text format Dr Andy Evans. Text-based data formats As data space has become cheaper, people have moved away from binary data formats. Text easier.
Managing XML and Semistructured Data Lecture 12: XML Schema Prof. Dan Suciu Spring 2001.
4 XML Schema.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
XML 6.5 XML Schema (XSD) 6. What is XML Schema? The origin of schema  XML Schema documents are used to define and validate the content and structure.
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.
XML Schema Definition Language
2/9/00 EECS 684: Current Topics in Databases1 ( W3C Working Draft 17 December 1999 )
1 Week5 – Schema Why Schema? Schemas vs. DTDs Introduction – W3C vs. Microsoft XDR Schema, How To? Element Types – Simple vs. Complex Attributes Restrictions/Facets.
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.
Gli schema W3C Tipi semplici, tipi complessi, tipi anonimi.
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.
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.
IS432 Semi-Structured Data Lecture 3: XSchema Dr. Gamal Al-Shorbagy.
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 Enterprise IT [Πληροφοριακές Τεχνολογίες της Επιχείρησης] Lecture 6-9: XSD Overview Univ. of the Aegean Financial and Management Engineering Dpt Petros.
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 and friends Part 2 - XML Schema ELAG 2001 workshop 8 Jan Erik Kofoed © BIBSYS Library Automation.
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.
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.
1 Dr Alexiei Dingli XML Technologies X-Schema. 2 XML-based alternative to DTD Describes the structure of an XML document Also referred to as XML Schema.
Session IV Chapter 9 – XML Schemas
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer.
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 –
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.
Schemas 1www.tech.findforinfo.com. What is a Schema a schematic or preliminary plan Description of a structure, details... 2www.tech.findforinfo.com.
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,
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
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
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
Primer on XML Schema CSE 544 April, XML Schemas Generalizes DTDs Uses XML syntax Two parts: structure and datatypes Very complex –criticized –alternative.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
CSE 6331 © Leonidas Fegaras XML Schema 1 XML Schema Leonidas Fegaras.
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.
Deriving Complex Types In XML Schema By: Roy Navon.
XML Schema Lecture 3. Indicators There are seven indicators: Order indicators: All Choice Sequence Occurrence indicators: maxOccurs minOccurs Group indicators:
Lecture 0 W3C XML Schema. Topics Status Motivation Simple type vs. complex type.
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.
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 Laurea Magistrale in Informatica Chapter 04 Modulo del corso Thecnologies for Innovation

XML Schema2 Agenda Schema characteristics Element Declaration Simple Element Restrictions Complex Elements Indicator Namespaces Schema characteristics Element Declaration Simple Element Restrictions Complex Elements Indicator Namespaces

XML Schema3 Schema è un termine generale, dal vocabolario inglese: a structured framework or plan Quando si parla di XML Schema si intende usualmente il W3C XML Schema Language … e il suo acronimo XSD (Xml Schema Definitiom) DTD, XML Schema, e RELAX NG sono tutti linguaggi di schema XML

XML Schema4 Very Simple xml schema It starts with an XML declaration Lestensione è.xsd e lelemento root è Namespace declaration Element Declaration The declaration makes use of our Schema namespace, and it uses attributes to provide information about the element we are defining XML SCHEMA ARE WELL_FORMED XML DOCUMENTS

XML Schema5 Schema characteristics Because XML Schemas are written using XML, that allows Schemas to be adopted quickly and easily by applications already using XML. Because XML is text based, it is easily transferable via common Internet file transfer methods, such as FTP and HTTP. In fact, Schemas are "optimized for interoperability" in this way because they are recursive, self- describing documents. XML Schemas is for datatyping.Datatypes allow you to specify that a piece of information has to be in a specific data format. Datatypes are a very powerful mechanism for placing constraints on your XML documents.

XML Schema6 Element Declarations The declaration uses the element type, which has a number of attributes that manipulate properties of the element. In the preceding declaration, there is a name attribute, which is used to specify the name of the element type being declared. There is also a type attribute, which is how you specify the datatype associated with an element using XML Schema.

XML Schema7 Valid Attributes for tag The element declaration in an XML Schema takes the form of the tag. That tag forms the start of any element declaration in your schema. The declaration can accept a number of attributes, each one designed to manipulate one or more of the properties that make up an element declaration.

XML Schema8 Default and Fixed attribute

XML Schema9 MaxOccurs and MinOccurs attribute

XML Schema10 REF and Type attribute

XML Schema11 Content Models: Elementi semplici e complessi Un elemento semplice contiene solo testo Non ha attributi Non contiene altri elementi Non può essere vuoto Ci possono essere varie restrizioni applicate al contenuto Un elemento complesso Può avere attributi Può essere vuoto, contenere testo, altri elementi, o sia testo che altri elementi.

XML Schema12 Definire un elemento semplice Un elemento semplice è definito come: dove: name è il nome dellelemento Valori comuni per type sono xs:booleanxs:integer xs:datexs:string xs:decimalxs:time

XML Schema13 Definire un attributo Gli attributi sono dichiarati sempre come tipi semplici Definito come dove: name e type sono gli stessi che per xs:element Altri attributi che gli elementi semplici possono avere: default=" default value " se nessun valore è specificato fixed=" value nessun altro valore può essere specificato use="optional" non richiesto (default) use="required" richiesto

XML Schema14

XML Schema15 Restrizioni (facets) La forma generale delle restrizioni è: (o xs:attribute )... the restrictions... Ad esempio:

XML Schema16 Restrizioni su numeri minInclusive -- numero deve essere di value minExclusive -- numero deve essere > di value maxInclusive -- numero deve essere di value maxExclusive -- numero deve essere < di value totalDigits -- numero deve avere value cifre fractionDigits -- numero deve avere non più di value cifre dopo il punto decimale

XML Schema17 Restrizioni su stringhe length -- la stringa deve contenere value caratteri minLength -- la stringa deve contenere almeno value caratteri maxLength -- la stringa deve contenere non più di value caratteri pattern -- value è una espressione regolare da soddisfare whiteSpace -- dice come trattare gli spazi bianchi value="preserve" li mantiene value="replace" rinpiazza con spazi value="collapse" rimuove gli spazi iniziali, finali e rimpiazza le sequenze con uno spazio singolo

XML Schema18 Enumerazioni Restringe il range di possibili valori ad una loro enumerazione Esempio:

XML Schema19 ESEMPIO : writing tip on a pen if we wanted to create an attribute for the size of the writing tip on a pen, we might want the size to be able to be expressed as a name, such as "Extra Fine" or as a decimal, such as ".05". size by name size by value

XML Schema20 UNIONE per creare un attributo di nome SIZE Element that use new attribute Legal value for the size attribute

XML Schema21 Elementi Complessi Un elemento complesso è definito da:... information about the complex type... Esempio:

XML Schema22 Kinds of complex elements empty elements elements that contain only other elements elements that contain only text elements that contain both other elements and text Note: Each of these elements may contain attributes as well!

XML Schema23 Examples of Complex Elements A complex XML element, "product", which is empty: A complex XML element, "employee", which contains only other elements: John Smith A complex XML element, "food", which contains only text: Ice cream A complex XML element, "description", which contains both elements and text: It happened on

XML Schema24 Complex Element Definition: declared directly by naming the element If you use the method described above, only the "employee" element can use the specified complex type. Note that the child elements, "firstname" and "lastname", are surrounded by the indicator. This means that the child elements must appear in the same order as they are declared.

XML Schema25 Complex Element Definition: have a type attribute that refers to the name of the complex type to use If you use the method described above, several elements can refer to the same complex type

XML Schema26 Base a complex element on an existing complex element and add some elements

XML Schema27 Complex Empty Elements Product element declaration :

XML Schema28 Complex Type - Elements Only An "elements-only" complex type contains an element that contains only other elements. xs:element name="person" type="persontype"/> s

XML Schema29 Complex Text-Only Elements A complex text-only element can contain text and attributes..... OR.... Use the extension/restriction element to expand or to limit the base simple type for the element.

XML Schema30 Complex Types With Mixed Content A mixed complex type element can contain attributes, elements, and text Dear Mr. John Smith. Your order 1032 will be shipped on

XML Schema31 Indicator Order indicators: are used to define the order of the elements All Choice Sequence Occurrence indicators: are used to define the order of the elements maxOccurs minOccurs Group indicators: are used to define related sets of elements Group name attributeGroup name

XML Schema32 Order Indicator : ALL The indicator specifies that the child elements can appear in any order, and that each child element must occur only once Note: When using the indicator you can set the indicator to 0 or 1 and the indicator can only be set to 1

XML Schema33 Order Indicator : CHOICE The indicator specifies that either one child element or another can occur

XML Schema34 Order Indicator : SEQUENCE The indicator specifies that the child elements must appear in a specific order </xs:element

XML Schema35 Occurrence Indicator : maxOccurs The indicator specifies the maximum number of times an element can occur The example above indicates that the "child_name" element can occur a minimum of one time (the default value for minOccurs is 1) and a maximum of ten times in the "person" element.

XML Schema36 Occurrence Indicator : minOccurs The indicator specifies the minimum number of times an element can occur <xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/> The example above indicates that the "child_name" element can occur a minimum of zero times and a maximum of ten times in the "person" element. Tip: To allow an element to appear an unlimited number of times, use the maxOccurs="unbounded" statement:

XML Schema37 Working example <persons xmlns:xsi=" instance" xsi:noNamespaceSchemaLocation="family.xsd"> Hege Refsnes Cecilie Tove Refsnes Hege Stale Jim Borge Stale Refsnes <xs:schema xmlns:xs=" elementFormDefault="qualified"> <xs:element name="child_name" type="xs:string" minOccurs="0" maxOccurs="5"/> The XML file contains a root element named "persons". Inside this root element we have defined three "person" elements. Each "person" element must contain a "full_name" element and it can contain up to five "child_name" elements

XML Schema38 Group Indicator : Element/Attribute Group Element groups are defined with the group declaration, like this:... xs:group name="persongroup">

XML Schema39 The and elements are used to make EXTENSIBLE documents! They allow documents to contain additional elements that are not declared in the main XML schema. The following example is a fragment from an XML schema called "family.xsd". It shows a declaration for the "person" element. By using the element we can extend (after ) the content of "person" with any element:

XML Schema40 Perchè XML Schema? DTD fornisce specifiche deboli Nessuna restrizione sul contenuto del testo Poco controllo sui contenuti misti (mixed content, text + elements) Poco controllo sullordinamento degli elementi DTD è scritto in un formato non-XML Parser separati per DTD e XML XML Schema Definition Language risolve questi problemi Più controllo su strutture e contenuti XSD è scritto in XML

XML Schema41 Riferirsi ad uno schema Per la DTD il riferimento va prima del root element:... Per lXML Schema il riferimento va nel root element: (dove trovare lo Schema definition voluto)...

XML Schema42 Specifing Namespaces Are specified using the xmlns attribute to declare the Namespace with an element. The attribute takes the general form the element is the element for which we are declaring the Namespace The prefix is the prefix we will use with our element names the Namespace URI is the identifier of the Namespace itself. The prefix is actually optionalif it is left out, the Namespace declaration is considered the default Namespace, and all the elements in the document will be treated as members of that Namespace unless they are marked otherwise.

XML Schema43 Namespace URI Generally, this takes the form of a URL, which serves as a good unique identifier, because it includes the domain name, and is easily understood by Web-enabled software. The most common misconception resulting from the use of a URL here is that the URL necessarily points to something, when,in fact, it does not. The URL is simply used as a string to identify the Namespace it does not necessarily point to any specific document (although it can if you want it to) and there is no syntax or standard for creating a Namespace document to live on your server.

XML Schema44 Single Default Namespace

XML Schema45 Multiple Prefixed Namespaces To make all the Namespaces in the document require a prefix, we use the same basic structure as declaring a default Namespace, only we add the : prefix to the xmlns attribute

XML Schema46 The advantage of this method is that now both Namespaces are declared globally. That is because they are declared in the root element, and the default Namespace applies to any element without a prefix in the document. Because the second Namespace is also declared globally, any element in the document can be made part of that Namespace by appending the prefix. Default and Prefixed Namespaces

XML Schema47 default Namespace globally, and the secondNamespace declared locally

XML Schema48 list of the Namespaces for some of the technologies discussed