SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
XSD
Incomplete Overview
A Simple XML Document
Look at this simple XML document called "note.xml":

<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
An XML Schema
The following example is an XML Schema file called "note.xsd" that defines the
elements of the XML document above ("note.xml"):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string“ maxOccours=“4” />
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:strincoug"/>
<xs:element name="body" type="xs:string“ minOccours=“0”/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Simple Element vs Complex Element
Reference to an XML Schema
A Reference to an XML Schema
This XML document has a reference to an XML Schema:
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The <schema> Element
The <schema> element is the root element of
every XML Schema:
<?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
Simple Element
What is a Simple Element?
A simple element is an XML element that can contain only
text. It cannot contain any other elements or attributes.
However, the "only text" restriction is quite misleading. The
text can be of many different types. It can be one of the types
included in the XML Schema definition (boolean, string, date,
etc.), or it can be a custom type that you can define yourself.
You can also add restrictions (facets) to a data type in order to
limit its content, or you can require the data to match a
specific pattern.
The syntax for defining a simple element is:
<xs:element name="xxx" type="yyy"/>
where xxx is the name of the element and yyy is the data
type of the element.
XML Schema has a lot of built-in data types. The most
common types are:
• xs:string
• xs:decimal
• xs:integer
• xs:boolean
• xs:date
• xs:time
Example
Here are some XML elements:
<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>
And here are the corresponding simple element definitions:
<xs:element name="lastname" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>
Attribute
What is an Attribute?
Simple elements cannot have attributes. If an element has attributes, it is considered
to be of a complex type. But the attribute itself is always declared as a simple type.
How to Define an Attribute?
The syntax for defining an attribute is:
<xs:attribute name="xxx" type="yyy"/>
where xxx is the name of the attribute and yyy specifies the data type of the attribute.
XML Schema has a lot of built-in data types. The most common types are:
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
Example
Here is an XML element with an attribute:
<lastname lang="EN">Smith</lastname>
And here is the corresponding attribute
definition:
<xs:attribute name="lang" type="xs:string"/>
Optional and Required Attributes
Attributes are optional by default. To specify
that the attribute is required, use the "use"
attribute:
<xs:attribute name="lang" type="xs:string"
use="required"/>
Restrictions on Values
The following example defines an element called "age"
with a restriction. The value of age cannot be lower than
0 or greater than 120:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on a Set of Values
To limit the content of an XML element to a set of acceptable values,
we would use the enumeration constraint.
The example below defines an element called "car" with a restriction.
The only acceptable values are: Audi, Golf, BMW:
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on a Series of Values
To limit the content of an XML element to define a series of numbers
or letters that can be used, we would use the pattern constraint.
The example below defines an element called "letter" with a
restriction. The only acceptable value is ONE of the LOWERCASE letters
from a to z:
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions for Datatypes
Constraint

Description

enumeration

Defines a list of acceptable values

fractionDigits

Specifies the maximum number of decimal places allowed. Must be equal to or greater
than zero

length

Specifies the exact number of characters or list items allowed. Must be equal to or greater
than zero

maxExclusive

Specifies the upper bounds for numeric values (the value must be less than this value)

maxInclusive

Specifies the upper bounds for numeric values (the value must be less than or equal to
this value)

maxLength

Specifies the maximum number of characters or list items allowed. Must be equal to or
greater than zero

minExclusive

Specifies the lower bounds for numeric values (the value must be greater than this value)

minInclusive

Specifies the lower bounds for numeric values (the value must be greater than or equal to
this value)

minLength

Specifies the minimum number of characters or list items allowed. Must be equal to or
greater than zero

pattern

Defines the exact sequence of characters that are acceptable

totalDigits

Specifies the exact number of digits allowed. Must be greater than zero

whiteSpace

Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
Complex Element
What is a Complex Element?
A complex element is an XML element that contains other
elements and/or attributes.
There are four 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!
Examples of Complex Elements
A complex XML element, "product", which is empty:

<product pid="1345"/>
A complex XML element, "employee", which contains only other elements:

<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
A complex XML element, "food", which contains only text:

<food type="dessert">Ice cream</food>
A complex XML element, "description", which contains both elements and text:

<description>
It happened on <date lang="norwegian">03.03.99</date> ....
</description>
How to Define a Complex Element
Look at this complex XML element, "employee", which contains only other elements:
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
We can define a complex element in an XML Schema two different ways:
The "employee" element can be declared directly by naming the element, like this:
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xsd:unique> Element
<xs:unique name="testUnique">
<xs:selector xpath="book"/>
<xs:field xpath="title"/>
</xs:unique>
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="book"/>
</xs:sequence>

</xs:complexType>
<xs:unique name="testUnique">
<xs:selector xpath="book"/>
<xs:field xpath="title"/>

</xs:unique>

</xs:element>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
</xs:sequence>

</xs:complexType>
</xs:element>

Más contenido relacionado

La actualidad más candente (19)

fundamentals of XML
fundamentals of XMLfundamentals of XML
fundamentals of XML
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml part4
Xml part4Xml part4
Xml part4
 
Xml schema
Xml schemaXml schema
Xml schema
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
Xsd tutorial
Xsd tutorialXsd tutorial
Xsd tutorial
 
Xml
Xml Xml
Xml
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
XML Schemas
XML SchemasXML Schemas
XML Schemas
 
Xsd
XsdXsd
Xsd
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
Xml
Xml Xml
Xml
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml
XmlXml
Xml
 
Xslt
XsltXslt
Xslt
 
Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
Xml part2
Xml part2Xml part2
Xml part2
 

Similar a XSD Incomplete Overview Draft

Similar a XSD Incomplete Overview Draft (20)

Xsd
XsdXsd
Xsd
 
XML Fundamentals
XML FundamentalsXML Fundamentals
XML Fundamentals
 
Schemas 2 - Restricting Values
Schemas 2 - Restricting ValuesSchemas 2 - Restricting Values
Schemas 2 - Restricting Values
 
Xsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtmlXsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtml
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML SCHEMAS
 
XML Schema
XML SchemaXML Schema
XML Schema
 
XML
XMLXML
XML
 
Xml
XmlXml
Xml
 
XML
XMLXML
XML
 
SCDJWS 1. xml schema
SCDJWS 1. xml schemaSCDJWS 1. xml schema
SCDJWS 1. xml schema
 
paper about xml
paper about xmlpaper about xml
paper about xml
 
XML - The Extensible Markup Language
XML - The Extensible Markup LanguageXML - The Extensible Markup Language
XML - The Extensible Markup Language
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
XML_schema_Structure
XML_schema_StructureXML_schema_Structure
XML_schema_Structure
 
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriyaIPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
 
Web Information Systems XML
Web Information Systems XMLWeb Information Systems XML
Web Information Systems XML
 
Soap win
Soap winSoap win
Soap win
 

Más de Pedro De Almeida

Más de Pedro De Almeida (20)

APM Model in .NET - PT-pt
APM Model in .NET - PT-ptAPM Model in .NET - PT-pt
APM Model in .NET - PT-pt
 
Java memory model primary ref. - faq
Java memory model   primary ref. - faqJava memory model   primary ref. - faq
Java memory model primary ref. - faq
 
Sistemas Operativos - Processos e Threads
Sistemas Operativos - Processos e ThreadsSistemas Operativos - Processos e Threads
Sistemas Operativos - Processos e Threads
 
IP Multicast Routing
IP Multicast RoutingIP Multicast Routing
IP Multicast Routing
 
O Projecto, Gestão de Projectos e o Gestor de Projectos - Parte 1
O Projecto, Gestão de Projectos e o Gestor de Projectos - Parte 1O Projecto, Gestão de Projectos e o Gestor de Projectos - Parte 1
O Projecto, Gestão de Projectos e o Gestor de Projectos - Parte 1
 
Validation of a credit card number
Validation of a credit card numberValidation of a credit card number
Validation of a credit card number
 
Classes e Objectos JAVA
Classes e Objectos JAVAClasses e Objectos JAVA
Classes e Objectos JAVA
 
Ficheiros em JAVA
Ficheiros em JAVAFicheiros em JAVA
Ficheiros em JAVA
 
Excepções JAVA
Excepções JAVAExcepções JAVA
Excepções JAVA
 
Sessão 10 Códigos Cíclicos
Sessão 10 Códigos CíclicosSessão 10 Códigos Cíclicos
Sessão 10 Códigos Cíclicos
 
Sessao 9 Capacidade de canal e Introdução a Codificação de canal
Sessao 9 Capacidade de canal e Introdução a Codificação de canalSessao 9 Capacidade de canal e Introdução a Codificação de canal
Sessao 9 Capacidade de canal e Introdução a Codificação de canal
 
Sessão 8 Codificação Lempel-Ziv
Sessão 8 Codificação Lempel-ZivSessão 8 Codificação Lempel-Ziv
Sessão 8 Codificação Lempel-Ziv
 
Sessao 7 Fontes com memória e codificação aritmética
Sessao 7 Fontes com memória e codificação aritméticaSessao 7 Fontes com memória e codificação aritmética
Sessao 7 Fontes com memória e codificação aritmética
 
Sessao 5 Redundância e introdução à codificação de fonte
Sessao 5 Redundância e introdução à codificação de fonteSessao 5 Redundância e introdução à codificação de fonte
Sessao 5 Redundância e introdução à codificação de fonte
 
Sessão 6 codificadores estatísticos
Sessão 6 codificadores estatísticosSessão 6 codificadores estatísticos
Sessão 6 codificadores estatísticos
 
Sessao 4 - Chaves espúrias e distância de unicidade
Sessao 4 - Chaves espúrias e distância de unicidadeSessao 4 - Chaves espúrias e distância de unicidade
Sessao 4 - Chaves espúrias e distância de unicidade
 
Sessao 3 Informação mútua e equívocos
Sessao 3 Informação mútua e equívocosSessao 3 Informação mútua e equívocos
Sessao 3 Informação mútua e equívocos
 
Sessao 2 Introdução à T.I e Entropias
Sessao 2 Introdução à T.I e EntropiasSessao 2 Introdução à T.I e Entropias
Sessao 2 Introdução à T.I e Entropias
 
Cripto - Introdução, probabilidades e Conceito de Segurança
Cripto - Introdução, probabilidades e Conceito de SegurançaCripto - Introdução, probabilidades e Conceito de Segurança
Cripto - Introdução, probabilidades e Conceito de Segurança
 
Basic java tutorial
Basic java tutorialBasic java tutorial
Basic java tutorial
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 

XSD Incomplete Overview Draft

  • 2. A Simple XML Document Look at this simple XML document called "note.xml": <?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 3. An XML Schema The following example is an XML Schema file called "note.xsd" that defines the elements of the XML document above ("note.xml"): <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string“ maxOccours=“4” /> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:strincoug"/> <xs:element name="body" type="xs:string“ minOccours=“0”/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Simple Element vs Complex Element
  • 4. Reference to an XML Schema A Reference to an XML Schema This XML document has a reference to an XML Schema: <?xml version="1.0"?> <note xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com note.xsd"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 5. The <schema> Element The <schema> element is the root element of every XML Schema: <?xml version="1.0"?> <xs:schema> ... ... </xs:schema>
  • 6. Simple Element What is a Simple Element? A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes. However, the "only text" restriction is quite misleading. The text can be of many different types. It can be one of the types included in the XML Schema definition (boolean, string, date, etc.), or it can be a custom type that you can define yourself. You can also add restrictions (facets) to a data type in order to limit its content, or you can require the data to match a specific pattern.
  • 7. The syntax for defining a simple element is: <xs:element name="xxx" type="yyy"/> where xxx is the name of the element and yyy is the data type of the element. XML Schema has a lot of built-in data types. The most common types are: • xs:string • xs:decimal • xs:integer • xs:boolean • xs:date • xs:time
  • 8. Example Here are some XML elements: <lastname>Refsnes</lastname> <age>36</age> <dateborn>1970-03-27</dateborn> And here are the corresponding simple element definitions: <xs:element name="lastname" type="xs:string"/> <xs:element name="age" type="xs:integer"/> <xs:element name="dateborn" type="xs:date"/>
  • 9. Attribute What is an Attribute? Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type. How to Define an Attribute? The syntax for defining an attribute is: <xs:attribute name="xxx" type="yyy"/> where xxx is the name of the attribute and yyy specifies the data type of the attribute. XML Schema has a lot of built-in data types. The most common types are: xs:string xs:decimal xs:integer xs:boolean xs:date xs:time
  • 10. Example Here is an XML element with an attribute: <lastname lang="EN">Smith</lastname> And here is the corresponding attribute definition: <xs:attribute name="lang" type="xs:string"/>
  • 11. Optional and Required Attributes Attributes are optional by default. To specify that the attribute is required, use the "use" attribute: <xs:attribute name="lang" type="xs:string" use="required"/>
  • 12. Restrictions on Values The following example defines an element called "age" with a restriction. The value of age cannot be lower than 0 or greater than 120: <xs:element name="age"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="120"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 13. Restrictions on a Set of Values To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint. The example below defines an element called "car" with a restriction. The only acceptable values are: Audi, Golf, BMW: <xs:element name="car"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Audi"/> <xs:enumeration value="Golf"/> <xs:enumeration value="BMW"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 14. Restrictions on a Series of Values To limit the content of an XML element to define a series of numbers or letters that can be used, we would use the pattern constraint. The example below defines an element called "letter" with a restriction. The only acceptable value is ONE of the LOWERCASE letters from a to z: <xs:element name="letter"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-z]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 15. Restrictions for Datatypes Constraint Description enumeration Defines a list of acceptable values fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value) maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value) maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value) minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value) minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero pattern Defines the exact sequence of characters that are acceptable totalDigits Specifies the exact number of digits allowed. Must be greater than zero whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
  • 16. Complex Element What is a Complex Element? A complex element is an XML element that contains other elements and/or attributes. There are four 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!
  • 17. Examples of Complex Elements A complex XML element, "product", which is empty: <product pid="1345"/> A complex XML element, "employee", which contains only other elements: <employee> <firstname>John</firstname> <lastname>Smith</lastname> </employee> A complex XML element, "food", which contains only text: <food type="dessert">Ice cream</food> A complex XML element, "description", which contains both elements and text: <description> It happened on <date lang="norwegian">03.03.99</date> .... </description>
  • 18. How to Define a Complex Element Look at this complex XML element, "employee", which contains only other elements: <employee> <firstname>John</firstname> <lastname>Smith</lastname> </employee> We can define a complex element in an XML Schema two different ways: The "employee" element can be declared directly by naming the element, like this: <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
  • 19. <xsd:unique> Element <xs:unique name="testUnique"> <xs:selector xpath="book"/> <xs:field xpath="title"/> </xs:unique>
  • 20. <xs:element name="books"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" ref="book"/> </xs:sequence> </xs:complexType> <xs:unique name="testUnique"> <xs:selector xpath="book"/> <xs:field xpath="title"/> </xs:unique> </xs:element>
  • 21. <xs:element name="book"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>