Download presentation
Presentation is loading. Please wait.
Published byLesley Jordan Modified over 9 years ago
1
Beginning XML 4th Edition
2
Chapter 5: XML Schemas
3
Chapter 5 Objectives Benefits of XML Schemas How to create and use XML Schemas How to document your XML Schemas
4
Benefits of XML Schemas XML Schemas use XML syntax XML Schemas Namespace Support XML Schema Types Simple Complex XML Schema Content Models
5
The XML Schema Document Example
6
Try It Out What’s in a Name?
7
Schema Declarations Example <schema targetNamespace=“URI” attributeFormDefault=“qualified or unqualified” elementFormDefault=“qualified or unqualified” version=“version number”>
8
The Schema XML Namespace Examples or or
9
Target Namespaces Example 1 Example 2
10
Element and Attribute Qualification Qualified John Fitzgerald Doe Qualified and Prefixed John Fitzgerald Doe Unqualified John Fitzgerald Doe
11
Declarations Example <element name= “name of the element” type=“global type” ref=“global element declaration” form=“qualified or unqualified” minOccurs=“non negative number” maxOccurs=“non negative number or ‘unbounded’” default=“default value” fixed=“fixed value”>
12
Global versus Local Global declarations are declarations that appear as direct children of the element. Global element declarations can be reused throughout the XML Schema. Local declarations do not have the element as their direct parent and are valid only in their specific context.
13
Global versus Local Example
14
Creating a Local Type complexType
15
Creating a Local Type simpleType
16
Using a Global Type Example 1 <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:target="http://www.example.com/name" targetNamespace="http://www.example.com/name" elementFormDefault="qualified">
17
Using a Global Type Example 2 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.com/name" targetNamespace="http://www.example.com/name" elementFormDefault="qualified">
18
Try It Out Creating Reusable Global Types Referring to Global Element Declarations
19
Naming Elements
20
Element Qualified Form elementFormDefault Is an attribute that can be set to qualified unqualified
21
Cardinality It is important to note that the minOccurs and maxOccurs attributes are not permitted within global element declarations. Instead, you should use these attributes within the element references in your content models.
22
Default and Fixed Values Default Fixed
23
Element Wildcards <any minOccurs=“non negative number” maxOccurs=“non negative number or unbounded” namespace=“allowable namespaces” processContents=“lax or skip or strict”> ValueDescription ##anyAllows elements from all namespaces to be included as part of the wildcard. ##otherAllows elements from namespaces other than the targetNamespace to be included as part of the wildcard. ##targetNamespaceAllows elements from only the targetNamespace to be included as part of the wildcard. ##localAllows any well-formed elements that are not qualified by a namespace to be included as part of the wildcard. Whitespace-separated list of allowable namespace URIs Allows elements from any listed namespaces to be included as part of the wildcard. Possible list values also include ##targetNamespace and ##local.
24
Element Wildcards Example <any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
25
Declarations Example 1 <complexType mixed="true or false" name="Name of complexType"> Example2
26
Declarations Example <group name=“name of global group”>
27
Try It Out Using a Global Group
28
Content Models A declaration A reference to a global declaration An declaration
29
Declarations Example 1 <sequence minOccurs=“non negative number” maxOccurs=“non negative number or unbounded”> Example 2
30
Declarations Example 1 <choice minOccurs=“non negative number” maxOccurs=“non negative number or unbounded”> Example 2
31
References Example 1 <group ref=“ global group definition” minOccurs=“ non negative number” maxOccurs=“ non negative number or unbounded”> Example 2
32
Declarations First, the declaration must be the only content model declaration that appears as a child of a definition. Secondly, the declaration may contain only declarations as its children. It is not permitted to contain,, or declarations. Finally, the declaration’s children may appear once each in the instance document. This means that within the declaration the values for minOccurs are limited to 0 or 1.
33
Declaration Example John Fitzgerald Doe or John Doe Fitzgerald
34
Try It Out Making Contact
35
Declarations Example <attribute name=“name of the attribute” type=“global type” ref=“global attribute declaration” form=“qualified or unqualified” use=“optional or prohibited or required” default=“default value” fixed=“fixed value”>
36
Creating a Local Type Example
37
Using a Global Type Example (no prefix) <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:contacts="http://www.example.com/contacts" targetNamespace="http://www.example.com/contacts" elementFormDefault="qualified">
38
Using a Global Type Example (prefix) <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.com/contacts" targetNamespace="http://www.example.com/contacts" elementFormDefault="qualified">
39
Attribute Wildcards Example <anyAttribute namespace=“##local http://www.w3.org/XML/1998/namespace” processContents=“lax”/>
40
Attribute Wildcards ValueDescription ##anyAllows attributes from all namespaces to be included as part of the wildcard. ##otherAllows attributes from namespaces other than the targetNamespace to be included as part of the wildcard. ##targetNamespaceAllows attributes from only the targetNamespace to be included as part of the wildcard. ##localAllows attributes that are not qualified by a namespace to be included as part of the wildcard. Whitespace separated list of allowable namespace URIs Allows attributes from any listed namespaces to be included as part of the wildcard. Possible list values also include ##targetNamespace and ##local.
41
Try It Out Adding Attributes
42
Declarations Example 1 <attributeGroup name="name of global attribute group"> Example 2
43
Declarations Example 1 (illegal) Example 2 (illegal)
44
Try It Out Using a Global Attribute Group
45
Creating Elements with Simple Content Example (simple content)
46
Creating Elements with Simple Content and Attributes Example (simple content and attribute)
47
Data Types TypeDescription stringAny character data normalizedStringA whitespace normalized string where all spaces, tabs, carriage returns, and line feed characters are converted to single spaces tokenA string that does not contain sequences of two or more spaces, tabs, carriage returns, or line feed characters byteA numeric value from -128 to 127 unsignedByteA numeric value from 0 to 255 base64BinaryBase64 encoded binary information hexBinaryHexadecimal encoded binary information integerA numeric value representing a whole number positiveIntegerAn integer whose value is greater than 0
48
Try It Out Built-in XML Schema Data Types
49
User-Defined Data Types Example Declarations <simpleType name=“name of the simpleType” final= “#all or list or union or restriction”> There are three primary derived types: *Restriction types *List types *Union types
50
Declarations Example
51
Try It Out Creating a Restriction Simple Type
52
Declarations Example
53
Declarations Example 1
54
Declarations Example 2 Valid 43.847156 Unknown Not valid unknown 43.847156 Unknown
55
Try It Out Contacts – More Simple Types
56
Creating a Schema from Multiple Documents Declarations <import namespace=“” schemaLocation=“”> Declarations <include schemaLocation=“”>
57
Try It Out Making Contact – Importing XML Schema Delarations Making Contact – Including XML Schema Declarations
58
Documenting XML Schemas Comments Attributes from other namespaces Annotations
59
Comments Example <!-- This complexType allows you to describe a person's name broken down by first, middle and last parts of the name. You can also specify a greeting by including the title attribute. --> <!-- The NameGroup is a global group defined in this XML Schema. -->
60
Attributes from Other Namespaces Example <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:target="http://www.example.com/name" xmlns:doc="http://www.w3.org/documentation" targetNamespace="http://www.example.com/name" elementFormDefault="qualified"> <complexType name="NameType" doc:comments="This complexType allows you to describe a person's name broken down by first, middle and last parts of the name. You can also specify a greeting by including the title attribute."> <group ref="target:NameGroup" doc:comments="The NameGroup is a global group defined in this XML Schema."/>
61
Annotations Example <schema xmlns=“http://www.w3.org/2001/XMLSchema” targetNamespace=“http://www.example.com/name” xmlns:target=“http://www.example.com/name” elementFormDefault=“qualified”> The name vocabulary was created for a Chapter 2 sample. We have upgraded it to an XML Schema. The appinfo of this <annotation> element points to a sample XML file. The sample should be used only as an example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.