Session [2] Information Modeling with XSD and DTD

Similar documents
HTML vs. XML In the case of HTML, browsers have been taught how to ignore invalid HTML such as the <mymadeuptag> element and generally do their best

XML: Introduction. !important Declaration... 9:11 #FIXED... 7:5 #IMPLIED... 7:5 #REQUIRED... Directive... 9:11

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

XML DTDs and Namespaces. CS174 Chris Pollett Oct 3, 2007.

Week 2: Lecture Notes. DTDs and XML Schemas

Chapter 1: Getting Started. You will learn:

Information Systems. DTD and XML Schema. Nikolaj Popov

The concept of DTD. DTD(Document Type Definition) Why we need DTD

EMERGING TECHNOLOGIES. XML Documents and Schemas for XML documents

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 7 XML

XML. Part II DTD (cont.) and XML Schema

CountryData Technologies for Data Exchange. Introduction to XML

Overview. Introduction to XML Schemas. Tutorial XML Europe , Berlin. 1 Introduction. 2 Concepts. 3 Schema Languages.

XML. XML Namespaces, XML Schema, XSLT

7.1 Introduction. 7.1 Introduction (continued) - Problem with using SGML: - SGML is a meta-markup language

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

Tutorial 2: Validating Documents with DTDs

DTD MIGRATION TO W3C SCHEMA

Part 2: XML and Data Management Chapter 6: Overview of XML

XML. Objectives. Duration. Audience. Pre-Requisites

Introduction to Semistructured Data and XML. Overview. How the Web is Today. Based on slides by Dan Suciu University of Washington

Delivery Options: Attend face-to-face in the classroom or via remote-live attendance.

Java EE 7: Back-end Server Application Development 4-2

Querying XML Data. Querying XML has two components. Selecting data. Construct output, or transform data

Data Presentation and Markup Languages

SDPL : XML Basics 2. SDPL : XML Basics 1. SDPL : XML Basics 4. SDPL : XML Basics 3. SDPL : XML Basics 5

Introduction to XML Zdeněk Žabokrtský, Rudolf Rosa

- XML. - DTDs - XML Schema - XSLT. Web Services. - Well-formedness is a REQUIRED check on XML documents

Delivery Options: Attend face-to-face in the classroom or remote-live attendance.

Author: Irena Holubová Lecturer: Martin Svoboda

CSI 3140 WWW Structures, Techniques and Standards. Representing Web Data: XML

Overview. Introduction. Introduction XML XML. Lecture 16 Introduction to XML. Boriana Koleva Room: C54

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1

Introduction to XML. XML: basic elements

XML. extensible Markup Language. Overview. Overview. Overview XML Components Document Type Definition (DTD) Attributes and Tags An XML schema

XML. COSC Dr. Ramon Lawrence. An attribute is a name-value pair declared inside an element. Comments. Page 3. COSC Dr.

Outline. XML vs. HTML and Well Formed vs. Valid. XML Overview. CSC309 Tutorial --XML 4. Edward Xia

XML. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior

The main problem of DTD s...

XML - Schema. Mario Arrigoni Neri

CHAPTER 8. XML Schemas

IBM. XML and Related Technologies Dumps Braindumps Real Questions Practice Test dumps free

Semistructured data, XML, DTDs

Chapter 3 Brief Overview of XML

Fundamentals of Web Programming a

EXAM IN SEMI-STRUCTURED DATA Study Code Student Id Family Name First Name

Introduction. " Documents have tags giving extra information about sections of the document

A namespace prefix is defined with a xmlns attribute using the syntax xmlns:prefix="uri".

Structured documents

Extensible Markup Language (XML) Hamid Zarrabi-Zadeh Web Programming Fall 2013

HR-XML Schema Extension Recommendation, 2003 February 26

XML Structures. Web Programming. Uta Priss ZELL, Ostfalia University. XML Introduction Syntax: well-formed Semantics: validity Issues

Introduction. " Documents have tags giving extra information about sections of the document

More XML Schemas, XSLT, Intro to PHP. CS174 Chris Pollett Oct 15, 2007.


(One) Layer Model of the Semantic Web. Semantic Web - XML XML. Extensible Markup Language. Prof. Dr. Steffen Staab Dipl.-Inf. Med.

UNIT I. A protocol is a precise set of rules defining how components communicate, the format of addresses, how data is split into packets

XML and Content Management

Knowledge Engineering pt. School of Industrial and Information Engineering. Test 2 24 th July Part II. Family name.

WHITE PAPER. Query XML Data Directly from SQL Server Abstract. DilMad Enterprises, Inc. Whitepaper Page 1 of 32

CS561 Spring Mixed Content

Introduction to XML. An Example XML Document. The following is a very simple XML document.

Oracle Fusion Middleware

Search Page Basic Search Advanced Search Exploring search results Showing Properties Showing Details...

EXAM IN SEMI-STRUCTURED DATA Study Code Student Id Family Name First Name

CSI 3140 WWW Structures, Techniques and Standards. Markup Languages: XHTML 1.0

XML Extensible Markup Language

XML module 2. Creating XML. Hans C. Arents. senior IT market analyst. I.T. Works. Guiding the IT Professional

Introduction to XML DTD

Introduction to XML. Chapter 133

XML for Java Developers G Session 3 - Main Theme XML Information Modeling (Part I) Dr. Jean-Claude Franchitti

XML Applications. Prof. Andrea Omicini DEIS, Ingegneria Due Alma Mater Studiorum, Università di Bologna a Cesena

DBMaker. XML Tool User's Guide

XML for Java Developers G Session 3 - Main Theme XML Information Modeling (Part I) Dr. Jean-Claude Franchitti

EXAM IN SEMI-STRUCTURED DATA Study Code Student Id Family Name First Name

COMP9321 Web Application Engineering. Extensible Markup Language (XML)

CSC Web Technologies, Spring Web Data Exchange Formats

XML. Jonathan Geisler. April 18, 2008

웹기술및응용. XML Schema 2018 년 2 학기. Instructor: Prof. Young-guk Ha Dept. of Computer Science & Engineering

COPYRIGHTED MATERIAL. Introduction to XML

Outline. XML DOCTYPE External - SYSTEM. XML DOCTYPE Internal DTD &6&7XWRULDO ;0/ (GZDUG;LD

Constructing a Document Type Definition (DTD) for XML

Markup Languages SGML, HTML, XML, XHTML. CS 431 February 13, 2006 Carl Lagoze Cornell University

XML. Document Type Definitions XML Schema. Database Systems and Concepts, CSCI 3030U, UOIT, Course Instructor: Jarek Szlichta

Cisco IOS XML-PI Command Reference

XML Information Set. Working Draft of May 17, 1999

MANAGING INFORMATION (CSCU9T4) LECTURE 2: XML STRUCTURE

Fundamentals of Web Programming a

extensible Markup Language

COMP9321 Web Application Engineering

UBL Naming and Design Rules Checklist

Appendix H XML Quick Reference

XML: Extensible Markup Language

CHAPTER 2 MARKUP LANGUAGES: XHTML 1.0

Intro to XML. An Introduction to extensible Markup Language

What is XML? XML is designed to transport and store data.

Oracle Application Server 10g Oracle XML Developer s Kit Frequently Asked Questions September, 2005

Chapter 11 XML Data Modeling. Recent Development for Data Models 2016 Stefan Deßloch

XML in Databases. Albrecht Schmidt. al. Albrecht Schmidt, Aalborg University 1

ETSI STANDARD Methods for Testing and Specification (MTS); The Testing and Test Control Notation version 3; Part 9: Using XML schema with TTCN-3

Transcription:

Session [2] Information Modeling with XSD and DTD September 12, 2000 Horst Rechner

Q&A from Session [1] HTML without XML See Code HDBMS vs. RDBMS What does XDR mean? XML-Data Reduced Utilized in Biztalk

Modeling Inform. models XSD DTD XML Namespaces XSL(T) WWW WWW XHTML XML APIs SAX DOM APP/DB

Modeling a <a> b x Enforce Structure <b> </b> <x> </x> <y> </y> y </a> DTD XSD XML

XML - Well-Formed and Valid Well-Formed: Syntax is correct i.e. no nested tags, tags match case A document has to be well formed before it becomes an XML document and can be used any further. Valid: Semantic is correct i.e. when compared against a information model that says: Name must be a child of address!, Message can have a language attribute May be valid against one information model document and not valid against another one! <> and </>? </a> before </b>? a c c c

What can you do with Information models? Define Elements Approved names and types Ordering and nesting Multiplicity Attributes Approved names and types Optional standard values

What advantage do you get out of it? Data control Data is always in a expected order Which allows: Processing Programmers can write standardized processing code Authoring XML tools can help in creating and validating documents

What disadvantage does that have? Extra processor time to perform check Inconsistent support for schema definitions

The two XML information models DTD - document type definition XSD - XML Schema definition

DTD - How does it look? Uses separate syntax from XML Address_Book_dtd.xml <?xml version= 1.0?> <!DOCTYPE Address_Book SYSTEM Address_Book.dtd > <Address_Book> <Address> </Address> <Name>Steve</Name> <Phone>123</Phone> Adress_Book.dtd <?xml version= 1.0 encoding= UTF-8?> <!ELEMENT Address_Book (Address*)> <!ELEMENT Address (Name, Phone)> <!ELEMENT Name (#PCDATA)> <!ELEMENT Phone (#PCDATA)> <Address>

DTD - Internal and external definition Internal definition overrides external! Address_Book_Internal.xml <?xml version= 1.0?> <!DOCTYPE Address_Book [ <!ELEMENT Address_Book(Address*)> <!ELEMENT Address (Name, Phone)> <!ELEMENT Name (#PCDATA)> <!ELEMENT Phone (#PCDATA)> ]> <Address_Book> <Address>

DTD - declarable Components Header (document Type) Elements Attributes Entities Notations Ignore (not covered here) Include (not covered here) What do we need? <?xml version= 1.0?> <emailmessage> <To>Samuel</To> <From>Adam</From> <Subject>Party at 5:00</Subject> <Message lang= EN > Wanna go? </Message> <Attachment/> <!-- No comment--> <?MyPrinter R=128; G=0; B=128?> <![CDATA[This is not parsed!]]> </emailmessage>

DTD - document Type <!DOCTYPE DTDName Identifier Location> DTDName: Name of document element i.e. Address_Book Identifier: SYSTEM or PUBLIC (not implemented) Location: relative or absolute Path or URL Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Elements <!ELEMENT ElementName (Child)> (x) - child must appear once and once only (x?) - zero one one times (x+) - one or more times (x*) - zero or more times (x y) - x or y must appear (#PCDATA x)* - mixed content is allowed (this is the minimal syntax for mixed content!) (#PCDATA) - parsed text All combinations of the above are possible (#CDATA) NO! Corresponding XML: <ElementName> Text <x>data</x> Text Text <x>data</x> </ElementName> Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Element weaknesses No data typing This will be resolved in XSD Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Attribute types <!ATTLIST ElementName AttributeName AttrType AttrQualifier defvalue> String: CDATA Tokenized: ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS (see next slide) Enumerated: (x y z) Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Tokenized Attributes ID - unique element IDREF, IDREFS - reference to ID, that was defined before its reference ENTITY, ENTITIES - reference to an parsed or unparsed object (see one of next slides) NMTOKEN, NMTOKENS - Single word, or list of single words stripped of white spaces Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Attribute qualifier <!ATTLIST ElementName AttributeName AttrType AttrQualifier defvalue> #FIXED: Default value is fixed #IMPLIED: No default value, no one has to be provided #REQUIRED: Attribute is required and no default Enumerated: (x y z) Multiples attributes can be specified Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Attribute weaknesses No data typing This will be resolved in XSD Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Entities Parsed Markup characters: < > & &apos; " User defined strings: <!ENTITY SW Semantic Web > External ressources: <!ENTITY resourcename Identifier nameandlocation> Parameter Entities: <!ENTITY % entityname parametername> Usage (not in.xml, but in.dtd): <!ELEMENT name %entityname;> Unparsed External ressources: data in non-xml format (i.e. images) Advantages of using external resources: Modular design! Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Parsed external resource entity Address_Entity.xml <?xml version= 1.0?> <!DOCTYPE Address_Entity [ <!ENTITY AOne SYSTEM Address_EntityOne.xml > <!ENTITY ATwo SYSTEM Address_EntityTwo.xml > ]> <Address_Entity> &AOne; &ATwo; </Address_Entity> Address_EntityOne.xml <Address> <Name>Steve</Name> <Phone>123</Phone> </Address> Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Unparsed external resource entity Address_EntityGraphic.xml <?xml version="1.0"?> <!DOCTYPE Address_Entity [ <!ELEMENT Address_Entity (Address*)> <!ELEMENT Address (Name, Phone, GraphicTag)> <!ELEMENT Name (#PCDATA)> <!ELEMENT Phone (#PCDATA)> ]> <!NOTATION GIF SYSTEM "CompuServer Graphics Interchange Format 87a"> <!ENTITY GraphicFile SYSTEM "Address_GraphicOne.gif"> <!ELEMENT GraphicTag EMPTY> <!ATTLIST GraphicTag FileName ENTITY #REQUIRED> Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Unparsed external resource entity Address_EntityGraphic.xml <Address_Entity> <Address> <Name>Steve</Name> <Phone>123</Phone> <GraphicTag FileName="GraphicFile"/> </Address> </Address_Entity> Header (document Type) / Elements / Attributes / Entities / Notations / Ignore / Include

DTD - Weaknesses No data typing Elements can not appear in any order Uses separate syntax from XML

Elements versus Attributes Attributes: Easier to check by processor (see DOM) No tag overhead Default value General: Describe content Elements: Provide more structure General: Define content <?xml version= 1.0 encoding= UTF-16?> <emailmessage> <To>Samuel</To> <From>Adam</From> <Subject>Party at 5:00</Subject> <Message lang= EN > Wanna go? </Message> <Attachment/> <!-- No comment--> <?MyPrinter R=128; G=0; B=128?> <![CDATA[This is not parsed!]]> </emailmessage>

Exercises How do I setup the parser? Why do we use XERCES and not IE? XERCES is a validator. IE is only used for rendering. How can I validate my code? See readmefirst.txt

So We need something better XML Schema

XSD - Highlights Data typing 41+ datatypes Create your own Written in XML Any order for elements possible Supports namespaces (will be covered later) Object-oriented approach Derive new types from old ones

Q&A from Session 2 Part 1 Can I reference an ID in an attribute before I defined it? Yes, see Code Can I change a HTML DTD? Not in the browser. They are hardcoded. But in an SGML parser. http://www.jclark.com/sp/index.htm http://web3.w3.org/tr/html401/sgml/dtd.html

Interesting sites The basics at www.xml101.com

XSD - How does it look? Address_Book_xsd.xml <?xml version= 1.0?> <ab:address_book xmlns:xsi="http://www.w3.org/1999/xmlschema-instance" xsi:schemalocation="addressns Address_Book.xsd" xmlns:ab="addressns"> <Address> <Name>Steve</Name> <Phone>123</Phone> </Address> <Address> <Name>Carol</Name> <Phone>321</Phone> </Address> </ab:address_book> This version does only validate with XERCES! Change Namespace to validate with XMLSpy

XSD - How does it look? Address_Book.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema </xsd:schema> xmlns:xsd="http://www.w3.org/1999/xmlschema" targetnamespace="addressns" xmlns:ab="addressns"> <xsd:element name="address_book" type="ab:address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="ab:addresstype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name="addresstype"> <xsd:element name="name" type="ab:nametype"/> <xsd:element name="phone" type="ab:phonetype"/> </xsd:complextype> <xsd:simpletype name="nametype" base="xsd:string"/> <xsd:simpletype name="phonetype" base="xsd:string"/>

XSD - What can you do? Only 3 things: Declare elements and attributes Define types that are used by elements/attributes Declare namespaces but in a very powerful and flexible way

Namespaces in DTD Used to define where certain elements belong Address_Book.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema" targetnamespace="addressns" xmlns:ab="addressns"> <xsd:element name="address_book" type="ab:address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="ab:addresstype maxoccurs="unbounded"/> </xsd:complextype>

Namespaces in XML Used to define where certain elements belong Address_Book_xsd_spy.xml <?xml version= 1.0?> <ab:address_book xmlns:xsi="http://www.w3.org/1999/xmlschema-instance" xsi:schemalocation="addressns Address_Book.xsd" xmlns:ab="addressns"> <ab:address> <ab:name>steve</ab:name> <ab:phone>123</ab:phone> </ab:address> This version does only validate with XMLSpy! Change Namespace to validate with XERCES

If you only have one namespace Make it easy for yourself in XSD Address_Book_noNamespace.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema > <xsd:element name="address_book" type="address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="addresstype maxoccurs="unbounded"/> </xsd:complextype> This version validates in both parsers.

If you only have one namespace And make it easy in XML Address_Book_noNamepace.xml <?xml version= 1.0?> <Address_Book xmlns:xsi="http://www.w3.org/1999/xmlschema-instance" xsi:nonamespaceschemalocation= Address_Book.xsd"> <Address> <Name>Steve</Name> <Phone>123</Phone> </Address> This version validates in both parsers.

XSD - Elements Simple types No children and no attriutes Anonymous types Used within one element only i.e. string, integer Complex types Children and attributes allowed Cannot be referenced Named types Can be referenced (All combinations are possible i.e. complex anonymous types)

XSD - Named types Address_Book.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema </xsd:schema> xmlns:xsd="http://www.w3.org/1999/xmlschema" targetnamespace="addressns" xmlns:ab="addressns"> <xsd:element name="address_book" type="ab:address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="ab:addresstype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name="addresstype"> <xsd:element name="name" type="ab:nametype"/> <xsd:element name="phone" type="ab:phonetype"/> </xsd:complextype> <xsd:simpletype name="nametype" base="xsd:string"/> <xsd:simpletype name="phonetype" base="xsd:string"/>

XSD - Anonymous types Address_Book_Anonymous.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema targetnamespace="addressns xmlns:ab="addressns"> <xsd:element name="address_book"> </xsd:element> </xsd:schema> <xsd:complextype> <xsd:element name="address" maxoccurs="unbounded"> </xsd:element> </xsd:complextype> <xsd:complextype> <xsd:element name="name" type="xsd:string"/> <xsd:element name="phone" type="xsd:string"/> </xsd:complextype>

XSD - Type references Used to reference a defined type <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema targetnamespace="addressns xmlns:ab="addressns"> <xsd:element name="address_book"> </xsd:element> <xsd:complextype> </xsd:complextype> <xsd:element ref= Address /> <xsd:element name="address" maxoccurs="unbounded"> <xsd:complextype> <xsd:element name="name" type="xsd:string"/> <xsd:element name="phone" type="xsd:string"/> </xsd:complextype> </xsd:element> </xsd:schema> Does neither work with XERCES nor XMLSpy!

XSD - Data typing All DTD types (i.e. ID, NMTOKEN) are included in XSD Users can build their own simple and complex types

XSD - Build in types (excerpt) String Boolean Float / double Integer, long, short timeinstant timeduration recurringdate Binary Uri DTD attribute types Semantic Web true, false, 0, 1 1.34 (single, double precision) 10000 2000-02-25T13:20:00.000-05:00 (in this case EST) P1Y2M3DT10H30M12.3S --05-31 (every 31. May) 010101 http://www.semantic.web ID, IDREF, ENTITY, For a complete list see: http://www.w3.org/tr/xmlschema-0/#creatdt

XSD - Creating your own types We can derive new types from every existing base type (build in type) Additional characteristics are called facets Facets are (not all facets go with each type) Pattern Enumeration Length Precison / scale mininclusive/exclusive maxinclusive/exclusive min/maxlength For a complete facet list see: http://www.w3.org/tr/xmlschema-0/#simpletypefacets

XSD - Creating your own types <simpletype name= name base= source > <facet value= value /> <facet value= value /> </simpletype> <simpletype name= Tel base= string > <length value= 8 /> <pattern value= \d{3}-\d{4} /> </simpletype> Regular Expressions Parser: http://www.xfront.org/xml-schema/

XSD - Creating your own types <simpletype name= States base= string > <enumeration value= AK /> <enumeration value= ME /> </simpletype>

XSD - Creating your own type minoccurs and maxoccurs in elements Default value of minoccurs is one (means required) If maxoccurs is unbounded, there is no maximum If there is no maxoccurs then maxoccurs = minoccurs If there is no min/maxoccurs, then the element must occur exactly once

XSD - only Attributes Address_Book_attributes.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema > </xsd:schema> <xsd:element name="address_book" type="address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="addresstype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name="addresstype content= empty > <xsd:attribute name= name type= NameType /> <xsd:attribute name= phone" type="phonetype"/> </xsd:complextype> <xsd:simpletype name= NameType base= xsd:string /> <xsd:simpletype name="phonetype" base="xsd:string"/>

XSD - only Attributes to link a image <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema > </xsd:schema> <xsd:element name= Gallery" type= GalleryType"/> <xsd:complextype name= GalleryType"> <xsd:element name= img type= imagetype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name= imagetype content= empty > <xsd:attribute name= href type= urireference use= required /> </xsd:complextype> In the XML file: <img href= http://www.image.com/myimage.gif />

XSD - Attribute qualifier You can use the keyword use as a additional parameter in an attribute declaration to specify: Required attribute Optional attribute Fixed attribute Prohibited attribute i.e. <attribute name= abc type= abctype use= fixed value= myvalue >

XSD - Attributes with text in the Element Address_Book_attributesWText.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema > </xsd:schema> <xsd:element name="address_book" type="address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="addresstype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name="addresstype derivedby= extension base= string > <xsd:attribute name= name type= NameType /> <xsd:attribute name= phone" type="phonetype"/> </xsd:complextype> <xsd:simpletype name= NameType base= xsd:string /> <xsd:simpletype name="phonetype" base="xsd:string"/>

XSD - Derived types (OO-Concept) We can form subclasses of types Simple data types can be restricted i.e. a more restricted range of values You also should be able to restrict complex data types, but Complex data types can be extended

XSD - Restricting simple types We have already done that on a previous slide: XSD - Creating your own types <simpletype name= name base= source > <facet value= value /> <facet value= value /> </simpletype> <simpletype name= Tel base= string > <length value= 8 /> <pattern value= \d{3}-\d{4} /> </simpletype> Regular Expressions Parser: http://www.xfront.org/xml-schema/

XSD - Extending complex types See code: Address_Book_deriving.xml/xsd Extension and restriction can be blocked, by using the attribute block in the xsd file (not yet supported)

XSD - Additional concepts Mixed content Null content Groups (won t be covered here) Alternatives with choice Any order with all Anotations (won t be covered here) Typecasting (feature not yet supported) Equivalent elements Abstract elements (won t be covered here)

XSD - mixed content Address_Book_mixed.xml <?xml version= 1.0?> <Address_Book xmlns:xsi="http://www.w3.org/1999/xmlschema-instance" xsi:nonamespaceschemalocation="address_book.xsd"> <Address>Steve <Phone>123</Phone> </Address> <Address>Carol <Phone>321</Phone> </Address> </Address_Book>

XSD - mixed content No type definition for name possible Address_Book_mixed.xsd <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema > </xsd:schema> <xsd:element name="address_book" type="address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="addresstype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name="addresstype content= mixed > <xsd:element name="phone" type="phonetype"/> </xsd:complextype> <xsd:simpletype name="phonetype" base="xsd:string"/>

XSD - null content The element is not empty but NULL (databases!) Definition: <xsd:simpletype name= Name" base="xsd:string nullable= true /> Usage: <Name xsi:null= true />

XSD - Alternatives <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema > </xsd:schema> <xsd:element name="address_book" type="address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="addresstype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name="addresstype > <choice minoccurs= 0 maxoccurs= unbounded > </choice> </xsd:complextype> <xsd:element name="phone" type="phonetype"/> <xsd:element name= Name" type= NameType"/> <xsd:simpletype name="phonetype" base="xsd:string"/> <xsd:simpletype name= NameType" base="xsd:string"/>

XSD - Any order <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/1999/xmlschema > </xsd:schema> <xsd:element name="address_book" type="address_booktype"/> <xsd:complextype name="address_booktype"> <xsd:element name="address" type="addresstype maxoccurs="unbounded"/> </xsd:complextype> <xsd:complextype name="addresstype > <all> </all> </xsd:complextype> <xsd:element name="phone" type="phonetype"/> <xsd:element name= Name" type= NameType"/> <xsd:simpletype name="phonetype" base="xsd:string"/> <xsd:simpletype name= NameType" base="xsd:string"/>

XSD - Equivalent elements equivclass elements must be declared on the top level Types must be the same <xsd:element name="phone" type="phonetype"/> <xsd:element name= Tel equivclass= Phone type= PhoneType > <xsd:element name= Name" type= NameType"/>

XSD - Additional concepts Include / import Uniqueness / key / reference to a key anyattribute Open ContentModel Not covered in this seminar.

Exercises Write a schema for juicers_xsd.xml

XML - Rendering and Transformation How do you do it? Next session: XML Rendering and Transformation with XSL(T) XML XSL XML parser a b x y XSLT engine Transformation Filtering Sorting Adding c c c c d d d z a a a z WWW WWW XHTML XML d a z b a z