Download presentation
1
4 XML Schema
2
XML Schema Based on XML grammar, tools and technology
Alternative to DTD syntax XML Schema (W3C) Definition in accordance with the XML syntax Allows the definition of complex data types
3
Validation Content Model Validation DTD Content Model Validation
XML Schema Part 1: Structures XML Schema (W3C) Content Model Validation Datatype Validation XML Schema Part 2: Datatypes
4
Features Data typing concept
Data types for attributes and element content User-defined data types Detailed and flexible content modeling Attribute and element grouping Refinement of content models, inheritance Modularization Self-documentation Namespace support
5
Example <?xml version="1.0" encoding="utf-8"?>
<book isbn=" "> <title>Being a Dog Is a Full-Time Job</title> <author>Charles M. Schulz</author> <character> <name>Snoopy</name> <friend-of>Peppermint Patty</friend-of> <since> </since> <qualification>extroverted beagle</qualification> </character> <name>Peppermint Patty</name> <since> </since> <qualification>bold, brash and tomboyish</qualification> </book> library.xml
6
Elements and Attributes
<?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd=" .... Element Declaration <xsd:element name="name" type="xsd:string"/> <xsd:element name="friend-of" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> <xsd:element name="since" type="xsd:date"/> .... Built-in simple Type Cardinality <xsd:attribute name="isbn" type="xsd:string"/> .... Attribute Declaration </xsd:schema>
7
Simple Data Types string normalizedString boolean byte number long
Built-in simple Types string boolean number float double decimal duration datetime time date ... normalizedString byte long int short positiveInteger negativeInteger unsignedLong unsignedShort ... Built-in Types derived from simple Types
8
"Russian Doll Design" Schema
<?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd=" <xsd:element name="book"> <xsd:complexType> <xsd:sequence> <xsd:element name="title" type="xsd:string"/> <xsd:element name="author" type="xsd:string"/> <xsd:element name="character" minOccurs="0" maxOccurs="unbounded"> <xsd:element name="name" type="xsd:string"/> <xsd:element name="friend-of" type="xsd:string“ minOccurs="0" maxOccurs="unbounded"/> <xsd:element name="since" type="xsd:date"/> <xsd:element name="qualification" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:attribute name="isbn" type="xsd:string"/> </xsd:schema> Element of type complexType Compositor
9
"Salami Slice Design" Schema
<?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd=“ <xsd:element name="title" type="xsd:string"/> <xsd:element name="author" type="xsd:string"/> <xsd:element name="name" type="xsd:string"/> <xsd:element name="friend-of" type="xsd:string"/> <xsd:element name="since" type="xsd:date"/> <xsd:element name="qualification" type="xsd:string"/> <xsd:attribute name="isbn" type="xsd:string"/> Definition of Elements of type "simple" Definition of Attributes
10
"Salami Slice Design" Schema
<xsd:element name="character"> <xsd:complexType> <xsd:sequence> <xsd:element ref="name"/> <xsd:element ref="friend-of" minOccurs="0" maxOccurs="unbounded"/> <xsd:element ref="since"/> <xsd:element ref="qualification"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="book"> <xsd:element ref="title"/> <xsd:element ref="author"/> <xsd:element ref="character" <xsd:attribute ref="isbn"/> </xsd:schema> Definition of "complexType" Elements
11
Schema with "Named Types"
<?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd=" <xsd:simpleType name="nameType"> <xsd:restriction base="xsd:string"> <xsd:maxLength value="32"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="sinceType"> <xsd:restriction base="xsd:date"/> <xsd:simpleType name="descType"> <xsd:restriction base="xsd:string"/> <xsd:simpleType name="isbnType"> <xsd:pattern value="[0-9]{10}"/> Facet Definition of "named simpleTypes" Facet
12
... Schema with "Named Types"
<xsd:complexType name="characterType"> <xsd:sequence> <xsd:element name="name" type="nameType"/> <xsd:element name="friend-of" type="nameType" minOccurs="0" maxOccurs="unbounded"/> <xsd:element name="since" type="sinceType"/> <xsd:element name="qualification" type="descType"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="bookType"> <xsd:element name="title" type="nameType"/> <xsd:element name="author" type="nameType"/> <xsd:element name="character" type="characterType" <xsd:attribute name="isbn" type="isbnType" use="required"/> <xsd:element name="book" type="bookType"/> </xsd:schema> Definition of "named complexTypes" Declaration of book Element
13
Grouping Attributes and Elements
<xsd:group name="mainBookElements"> <xsd:sequence> <xsd:element name="title" type="nameType"/> <xsd:element name="author" type="nameType"/> </xsd:sequence> </xsd:group> <xsd:attributeGroup name="bookAttributes"> <xsd:attribute name="isbn" type="isbnType" use="required"/> <xsd:attribute name="available" type="xsd:string"/> </xsd:attributeGroup> <xsd:complexType name="bookType"> <xsd:sequence> <xsd:group ref="mainBookElements"/> <xsd:element name="character“ type="characterType" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attributeGroup ref="bookAttributes"/> </xsd:complexType>
14
Compositors <xsd:group name="nameTypes"> <xsd:choice>
<xsd:element name="name" type="xsd:string"/> <xsd:sequence> <xsd:element name="firstName" type="xsd:string"/> <xsd:element name="middleName" type="xsd:string" minOccurs="0"/> <xsd:element name="lastName" type="xsd:string"/> </xsd:sequence> </xsd:choice> </xsd:group> <xsd:complexType name="bookType"> <xsd:all> <xsd:element name="title" type="xsd:string"/> <xsd:element name="author" type="xsd:string"/> <xsd:element name="character" type="characterType" minOccurs="0" maxOccurs="unbounded"/> </xsd:all> <xsd:attribute name="isbn" type="isbnType" use="required"/> </xsd:complexType>
15
Derivations from Simple Types
xsd:restriction xsd:maxLength, xsd:minLength xsd:minInclusive,xsd:maxInclusive xsd:totalDigits, xsd:fractionDigits .... xsd:pattern xsd:union xsd:list ... Facets
16
Content Types Empty Content with Attribute
<xsd:element name="book"> <xsd:complexType> <xsd:attribute name="isbn" type="isbnType"/> </xsd:complexType> </xsd:element> Empty Content with Attribute <xsd:element name="book"> <xsd:complexType> <xsd:simpleContent> <xsd:extension base="xsd:string"> <xsd:attribute name="isbn" type="isbnType"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> </xsd:element> Character Data Content with Attribute
17
Mixed Content <xsd:element name="book">
<xsd:complexType mixed="true"> <xsd:all> <xsd:element name="title" type="xsd:string"/> <xsd:element name="author" type="xsd:string"/> </xsd:all> <xsd:attribute name="isbn" type="xsd:string"/> </xsd:complexType> </xsd:element> <book isbn=" "> Funny book by <author>Charles M. Schulz</author>. Its title (<title>Being a Dog Is a Full-Time Job</title>) says it all! </book>
18
Documentation <xsd:element name="book"> <xsd:annotation>
<xsd:documentation xml:lang="en"> Top level element. </xsd:documentation> <xsd:documentation xml:lang="fr"> Element racine </xsd:documentation> <xsd:appinfo source=" <bind xmlns=" <class name="Book"/> </bind> </xsd:appinfo> </xsd:annotation> ...
19
Namespaces library.xsd library.xml <xsd:schema
xmlns:xsd=" xmlns=" targetNamespace=" elementFormDefault="unqualified" attributeFormDefault="unqualified" > .... </xsd:schema> library.xsd <book isbn=" " xmlns=" <title> Being a Dog is a Full-Time Job </title> ... </book> library.xml
20
XML Schema and Instances
<xsd:schema xmlns:xsd=" .... </xsd:schema> library.xsd without targetNamespace <book isbn=" " xmlns:xsi=" xsi:noNamespaceSchemaLocation="library.xsd"> <title> Being a Dog is a Full-Time Job </title> ... </book> library.xml
21
... XML Schema and Instances
<xsd:schema xmlns:xsd=" xmlns=" targetNamespace=" .... </xsd:schema> library.xsd with targetNamespace <book isbn=" " xmlns:xsi=" xmlns=" xsi:schemaLocation=" library.xsd"> <title> Being a Dog is a Full-Time Job </title> ... </book> library.xml
22
Summary Schema languages apply and enhance the concepts of DTDs to a more modern and consistent level. XML Schema can construct very complex content models. Moreover, it supports a complex datatyping concept.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.