SlideShare a Scribd company logo
V.M.Prabhakaran,
Department of CSE,
KIT- Coimbatore
XML Schema
What is an XML Schema?
• An XML Schema describes the structure of an XML
document.
• The XML Schema language is also referred to as
XML Schema Definition (XSD).
• XML documents can have a reference to a DTD or
to an XML Schema.
• The purpose of a Schema is to define the legal
building blocks of an XML document, just like a
DTD.
An XML Schema:
• defines elements that can appear in a document
• defines attributes that can appear within elements
• defines which elements are child elements
• defines the sequence in which the child elements can
appear
• defines the number of child elements
• defines whether an element is empty or can include text
• defines default values for attributes
Schema vs. DTD
• XML Schemas are extensible to future
additions
• XML Schemas are richer and more powerful
than DTDs
• XML Schemas are written in XML
• XML Schemas support data types
• XML Schemas support namespaces
Purpose of an XML Schema
• The purpose of an XML Schema is to define
the legal building blocks of an XML
document:
– the elements and attributes that can appear in a
document
– the number of (and order of) child elements
– data types for elements and attributes
– default and fixed values for elements and attributes
XSD - The <schema> Element
• The <schema> element is the root element of
every XML Schema.
• <?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
• The <schema> element may contain some
attributes.
Referring to a schema
• To refer to a DTD in an XML document, the reference goes before the root
element:
– <?xml version="1.0"?>
<!DOCTYPE rootElement SYSTEM "url">
<rootElement> ... </rootElement>
• To refer to an XML Schema in an XML document, the reference goes in the
root element:
– <?xml version="1.0"?>
<rootElement
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
(The XML Schema Instance reference is required)
xsi:noNamespaceSchemaLocation="url.xsd">
(This is where your XML Schema definition can be found)
...
</rootElement>
7
“Simple” and “complex” elements
• A “simple” element is one that contains text and
nothing else
– A simple element cannot have attributes
– A simple element cannot contain other elements
– A simple element cannot be empty
– However, the text can be of many different types,
and may have various restrictions applied to it
• If an element isn’t simple, it’s “complex”
– A complex element may have attributes
– A complex element may be empty, or it may contain
text, other elements, or both text and other elements
Defining a simple element
• A simple element is defined as
<xs:element name="name" type="type" />
where:
– name is the name of the element
– the most common values for type are
xs:boolean xs:integer
xs:date xs:string
xs:decimal xs:time
• Other attributes a simple element may have:
– default="default value" if no other value is
specified
– fixed="value" no other value may be
specified
Example of 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"/>
XSD Example
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Default and Fixed Values for Simple Elements
• Simple elements may have a default value OR a fixed
value specified.
• Default value: Automatically assigned to the element
when no other value is specified.
– In the following example the default value is "red":
– <xs:element name="color" type="xs:string"
default="red"/>
• Fixed value : Automatically assigned to the element,
and you cannot specify another value.
– In the following example the fixed value is "red":
– <xs:element name="color" type="xs:string" fixed="red"/>
Defining an attribute
• Attributes themselves are always declared as
simple types
• An attribute is defined as
<xs:attribute name="name" type="type" />
where:
– name and type are the same as for xs:element
• Other attributes a simple element may have:
– default="default value" if no other value is specified
– fixed="value" no other value may be specified
– use="optional" the attribute is not required
(default)
– use="required" the attribute must be present
XML Schemas Secure Data Communication
• When sending data from a sender to a receiver, it is
essential that both parts have the same "expectations" about
the content.
• With XML Schemas, the sender can describe the data in a
way that the receiver will understand.
• A date like: "03-11-2004" will, in some countries, be
interpreted as 3.November and in other countries as
11.March.
• However, an XML element with a data type like this:
• <date type="date">2004-03-11</date>
• ensures a mutual understanding of the content, because the
XML data type "date" requires the format "YYYY-MM-
DD".
XSD Restrictions
• Restrictions on Values
• Restrictions on a Set of Values
• Restrictions on a Series of Values
• Restrictions on Whitespace Characters
• Restrictions on Length
Restrictions on Values
• The general form for putting a restriction on a text value is:
– <xs:element name="name"> (or xs:attribute)
<xs:restriction base="type">
... the restrictions ...
</xs:restriction>
</xs:element>
• For example:
– <xs:element name="age">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0">
<xs:maxInclusive value="140">
</xs:restriction>
</xs:element>
Restrictions on numbers
• minInclusive -- number must be ≥ the given value
• minExclusive -- number must be > the given value
• maxInclusive -- number must be ≤ the given value
• maxExclusive -- number must be < the given value
• totalDigits -- number must have exactly value digits
• fractionDigits -- number must have no more than value
digits after the decimal point
Restrictions on a Set of Values
• An enumeration restricts the value to be one of a fixed set of
values
• 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 on a Series of Values
(continued)
• The next example defines an element called "initials"
with a restriction. The only acceptable value is
THREE of the UPPERCASE letters from a to z:
• <xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on a Series of Values
(continued)
• The next example also defines an element called
"initials" with a restriction. The only acceptable value
is THREE of the LOWERCASE OR UPPERCASE
letters from a to z:
• <xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on a Series of Values
(continued)
• The next example defines an element called
"choice" with a restriction. The only acceptable
value is ONE of the following letters: x, y, OR z:
• <xs:element name="choice">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[xyz]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on a Series of Values
(continued)
• The next example defines an element called "prodid"
with a restriction. The only acceptable value is FIVE
digits in a sequence, and each digit must be in a range
from 0 to 9:
• <xs:element name="prodid">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on Whitespace
Characters
• whiteSpace -- not really a
“restriction”--tells what to
do with whitespace
– value="preserve" Keep
all whitespace
– value="replace"
Change all whitespace
characters to spaces
– value="collapse"
Remove leading and trailing
whitespace, and
replace all
sequences of whitespace with
a single space
<xs:element
name="address">
<xs:simpleType>
<xs:restriction
base="xs:string">
<xs:whiteSpace
value="preserve"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on Length
• To limit the length of a value in an element, we would use the
length, maxLength, and minLength constraints.
• This example defines an element called "password" with a
restriction. The value must be exactly eight characters:
• <xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on Length (continued)
• This example defines another element called "password" with
a restriction. The value must be minimum five characters
and maximum eight characters:
• <xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Predefined date and time types
• xs:date -- A date in the format CCYY-MM-DD,
for example, 2002-11-05
• xs:time -- A date in the format hh:mm:ss (hours,
minutes, seconds)
• xs:dateTime -- Format is CCYY-MM-
DDThh:mm:ss
– The T is part of the syntax
• Allowable restrictions on dates and times:
– enumeration, minInclusive, minExclusive,
maxInclusive, maxExclusive, pattern, whiteSpace
Predefined numeric types
• Here are some of the predefined numeric types:
• Allowable restrictions on numeric types:
– enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive,
fractionDigits, totalDigits, pattern, whiteSpace
xs:decimal xs:positiveInteger
xs:byte xs:negativeInteger
xs:short xs:nonPositiveInteger
xs:int xs:nonNegativeInteger
xs:long
Example: Shipping Order
<?xml version="1.0"?>
<shipOrder>
<shipTo>
<name>Svendson</name>
<street>Oslo St</street>
<address>400 Main</address>
<country>Norway</country>
</shipTo>
<items>
<item>
<title>Wheel</title>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Cam</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</items>
</shipOrder>
XML Schema for Shipping Order
<xsd:schema xmlns:xsd=http://www.w3.org/1999/XMLSchema>
<xsd:element name="shipOrder" type="order"/>
<xsd:complexType name="order">
<xsd:element name="shipTo" type="shipAddress"/>
<xsd:element name="items" type="cdItems"/>
</xsd:complexType>
<xsd:complexType name="shipAddress">
<xsd:element name="name“ type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
</xsd:complexType>
XML Schema - Shipping Order (continued)
<xsd:complexType name="cdItems">
<xsd:element name="item" type="cdItem"/>
</xsd:complexType>
<xsd:complexType name="cdItem">
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="quantity“ type="xsd:positiveInteger"/>
<xsd:element name="price" type="xsd:decimal"/>
</xsd:complexType>
</xsd:schema>

More Related Content

What's hot

XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
BOSS Webtech
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLyht4ever
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
Knoldus Inc.
 
Css selectors
Css selectorsCss selectors
Css selectors
Parth Trivedi
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
priyadharshini murugan
 
Xml parsers
Xml parsersXml parsers
Xml parsers
Manav Prasad
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
 
Dynamic HTML (DHTML)
Dynamic HTML (DHTML)Dynamic HTML (DHTML)
Dynamic HTML (DHTML)
Himanshu Kumar
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
Mohammed Arif
 
Css3
Css3Css3
Javascript
JavascriptJavascript
Javascript
Manav Prasad
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Gil Fink
 
Introduction to Web Programming - first course
Introduction to Web Programming - first courseIntroduction to Web Programming - first course
Introduction to Web Programming - first courseVlad Posea
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 

What's hot (20)

XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Css selectors
Css selectorsCss selectors
Css selectors
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Dynamic HTML (DHTML)
Dynamic HTML (DHTML)Dynamic HTML (DHTML)
Dynamic HTML (DHTML)
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Css3
Css3Css3
Css3
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Introduction to Web Programming - first course
Introduction to Web Programming - first courseIntroduction to Web Programming - first course
Introduction to Web Programming - first course
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Xpath presentation
Xpath presentationXpath presentation
Xpath presentation
 

Similar to Xml schema

02 xml schema
02 xml schema02 xml schema
02 xml schema
Baskarkncet
 
Xml schema
Xml schemaXml schema
Xml schema
sana mateen
 
Xml part4
Xml part4Xml part4
Xml part4
NOHA AW
 
XSD Incomplete Overview Draft
XSD Incomplete Overview DraftXSD Incomplete Overview Draft
XSD Incomplete Overview Draft
Pedro De Almeida
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
David Ionut
 
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML Schema
XML SchemaXML Schema
XML Schema
Kumar
 
Xml 2
Xml  2 Xml  2
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
Pradeep Rapolu
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
Bình Trọng Án
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
Swati Parmar
 
XML-Schema-Elements_Types_Attributes.pptx
XML-Schema-Elements_Types_Attributes.pptxXML-Schema-Elements_Types_Attributes.pptx
XML-Schema-Elements_Types_Attributes.pptx
AkshayKumar100378
 
Service Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML SchemaService Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML Schema
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
XML's validation - XML Schema
XML's validation - XML SchemaXML's validation - XML Schema
XML's validation - XML Schema
videde_group
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
Harry Potter
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
James Wong
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
Young Alista
 

Similar to Xml schema (20)

02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml part4
Xml part4Xml part4
Xml part4
 
Schemas 2 - Restricting Values
Schemas 2 - Restricting ValuesSchemas 2 - Restricting Values
Schemas 2 - Restricting Values
 
XSD Incomplete Overview Draft
XSD Incomplete Overview DraftXSD Incomplete Overview Draft
XSD Incomplete Overview Draft
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
 
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML SCHEMAS
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Xml 2
Xml  2 Xml  2
Xml 2
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
XML-Schema-Elements_Types_Attributes.pptx
XML-Schema-Elements_Types_Attributes.pptxXML-Schema-Elements_Types_Attributes.pptx
XML-Schema-Elements_Types_Attributes.pptx
 
Service Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML SchemaService Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML Schema
 
XML's validation - XML Schema
XML's validation - XML SchemaXML's validation - XML Schema
XML's validation - XML Schema
 
Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 

More from Prabhakaran V M

Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Operators in python
Operators in pythonOperators in python
Operators in python
Prabhakaran V M
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
Prabhakaran V M
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
Prabhakaran V M
 
Html 5
Html 5Html 5
Introduction to Multi-core Architectures
Introduction to Multi-core ArchitecturesIntroduction to Multi-core Architectures
Introduction to Multi-core Architectures
Prabhakaran V M
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Applets
AppletsApplets

More from Prabhakaran V M (8)

Strings in python
Strings in pythonStrings in python
Strings in python
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
 
Html 5
Html 5Html 5
Html 5
 
Introduction to Multi-core Architectures
Introduction to Multi-core ArchitecturesIntroduction to Multi-core Architectures
Introduction to Multi-core Architectures
 
Java threads
Java threadsJava threads
Java threads
 
Applets
AppletsApplets
Applets
 

Recently uploaded

Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 

Recently uploaded (20)

Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 

Xml schema

  • 2. What is an XML Schema? • An XML Schema describes the structure of an XML document. • The XML Schema language is also referred to as XML Schema Definition (XSD). • XML documents can have a reference to a DTD or to an XML Schema. • The purpose of a Schema is to define the legal building blocks of an XML document, just like a DTD.
  • 3. An XML Schema: • defines elements that can appear in a document • defines attributes that can appear within elements • defines which elements are child elements • defines the sequence in which the child elements can appear • defines the number of child elements • defines whether an element is empty or can include text • defines default values for attributes
  • 4. Schema vs. DTD • XML Schemas are extensible to future additions • XML Schemas are richer and more powerful than DTDs • XML Schemas are written in XML • XML Schemas support data types • XML Schemas support namespaces
  • 5. Purpose of an XML Schema • The purpose of an XML Schema is to define the legal building blocks of an XML document: – the elements and attributes that can appear in a document – the number of (and order of) child elements – data types for elements and attributes – default and fixed values for elements and attributes
  • 6. XSD - The <schema> Element • The <schema> element is the root element of every XML Schema. • <?xml version="1.0"?> <xs:schema> ... ... </xs:schema> • The <schema> element may contain some attributes.
  • 7. Referring to a schema • To refer to a DTD in an XML document, the reference goes before the root element: – <?xml version="1.0"?> <!DOCTYPE rootElement SYSTEM "url"> <rootElement> ... </rootElement> • To refer to an XML Schema in an XML document, the reference goes in the root element: – <?xml version="1.0"?> <rootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" (The XML Schema Instance reference is required) xsi:noNamespaceSchemaLocation="url.xsd"> (This is where your XML Schema definition can be found) ... </rootElement> 7
  • 8. “Simple” and “complex” elements • A “simple” element is one that contains text and nothing else – A simple element cannot have attributes – A simple element cannot contain other elements – A simple element cannot be empty – However, the text can be of many different types, and may have various restrictions applied to it • If an element isn’t simple, it’s “complex” – A complex element may have attributes – A complex element may be empty, or it may contain text, other elements, or both text and other elements
  • 9. Defining a simple element • A simple element is defined as <xs:element name="name" type="type" /> where: – name is the name of the element – the most common values for type are xs:boolean xs:integer xs:date xs:string xs:decimal xs:time • Other attributes a simple element may have: – default="default value" if no other value is specified – fixed="value" no other value may be specified
  • 10. Example of 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"/>
  • 11. XSD Example <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
  • 12. Default and Fixed Values for Simple Elements • Simple elements may have a default value OR a fixed value specified. • Default value: Automatically assigned to the element when no other value is specified. – In the following example the default value is "red": – <xs:element name="color" type="xs:string" default="red"/> • Fixed value : Automatically assigned to the element, and you cannot specify another value. – In the following example the fixed value is "red": – <xs:element name="color" type="xs:string" fixed="red"/>
  • 13. Defining an attribute • Attributes themselves are always declared as simple types • An attribute is defined as <xs:attribute name="name" type="type" /> where: – name and type are the same as for xs:element • Other attributes a simple element may have: – default="default value" if no other value is specified – fixed="value" no other value may be specified – use="optional" the attribute is not required (default) – use="required" the attribute must be present
  • 14. XML Schemas Secure Data Communication • When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content. • With XML Schemas, the sender can describe the data in a way that the receiver will understand. • A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March. • However, an XML element with a data type like this: • <date type="date">2004-03-11</date> • ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM- DD".
  • 15. XSD Restrictions • Restrictions on Values • Restrictions on a Set of Values • Restrictions on a Series of Values • Restrictions on Whitespace Characters • Restrictions on Length
  • 16. Restrictions on Values • The general form for putting a restriction on a text value is: – <xs:element name="name"> (or xs:attribute) <xs:restriction base="type"> ... the restrictions ... </xs:restriction> </xs:element> • For example: – <xs:element name="age"> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"> <xs:maxInclusive value="140"> </xs:restriction> </xs:element>
  • 17. Restrictions on numbers • minInclusive -- number must be ≥ the given value • minExclusive -- number must be > the given value • maxInclusive -- number must be ≤ the given value • maxExclusive -- number must be < the given value • totalDigits -- number must have exactly value digits • fractionDigits -- number must have no more than value digits after the decimal point
  • 18. Restrictions on a Set of Values • An enumeration restricts the value to be one of a fixed set of values • 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>
  • 19. 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>
  • 20. Restrictions on a Series of Values (continued) • The next example defines an element called "initials" with a restriction. The only acceptable value is THREE of the UPPERCASE letters from a to z: • <xs:element name="initials"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[A-Z][A-Z][A-Z]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 21. Restrictions on a Series of Values (continued) • The next example also defines an element called "initials" with a restriction. The only acceptable value is THREE of the LOWERCASE OR UPPERCASE letters from a to z: • <xs:element name="initials"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 22. Restrictions on a Series of Values (continued) • The next example defines an element called "choice" with a restriction. The only acceptable value is ONE of the following letters: x, y, OR z: • <xs:element name="choice"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[xyz]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 23. Restrictions on a Series of Values (continued) • The next example defines an element called "prodid" with a restriction. The only acceptable value is FIVE digits in a sequence, and each digit must be in a range from 0 to 9: • <xs:element name="prodid"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 24. Restrictions on Whitespace Characters • whiteSpace -- not really a “restriction”--tells what to do with whitespace – value="preserve" Keep all whitespace – value="replace" Change all whitespace characters to spaces – value="collapse" Remove leading and trailing whitespace, and replace all sequences of whitespace with a single space <xs:element name="address"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:whiteSpace value="preserve"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 25. Restrictions on Length • To limit the length of a value in an element, we would use the length, maxLength, and minLength constraints. • This example defines an element called "password" with a restriction. The value must be exactly eight characters: • <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:length value="8"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 26. Restrictions on Length (continued) • This example defines another element called "password" with a restriction. The value must be minimum five characters and maximum eight characters: • <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="5"/> <xs:maxLength value="8"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 27. Predefined date and time types • xs:date -- A date in the format CCYY-MM-DD, for example, 2002-11-05 • xs:time -- A date in the format hh:mm:ss (hours, minutes, seconds) • xs:dateTime -- Format is CCYY-MM- DDThh:mm:ss – The T is part of the syntax • Allowable restrictions on dates and times: – enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, pattern, whiteSpace
  • 28. Predefined numeric types • Here are some of the predefined numeric types: • Allowable restrictions on numeric types: – enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, fractionDigits, totalDigits, pattern, whiteSpace xs:decimal xs:positiveInteger xs:byte xs:negativeInteger xs:short xs:nonPositiveInteger xs:int xs:nonNegativeInteger xs:long
  • 29. Example: Shipping Order <?xml version="1.0"?> <shipOrder> <shipTo> <name>Svendson</name> <street>Oslo St</street> <address>400 Main</address> <country>Norway</country> </shipTo> <items> <item> <title>Wheel</title> <quantity>1</quantity> <price>10.90</price> </item> <item> <title>Cam</title> <quantity>1</quantity> <price>9.90</price> </item> </items> </shipOrder>
  • 30. XML Schema for Shipping Order <xsd:schema xmlns:xsd=http://www.w3.org/1999/XMLSchema> <xsd:element name="shipOrder" type="order"/> <xsd:complexType name="order"> <xsd:element name="shipTo" type="shipAddress"/> <xsd:element name="items" type="cdItems"/> </xsd:complexType> <xsd:complexType name="shipAddress"> <xsd:element name="name“ type="xsd:string"/> <xsd:element name="street" type="xsd:string"/> <xsd:element name="address" type="xsd:string"/> <xsd:element name="country" type="xsd:string"/> </xsd:complexType>
  • 31. XML Schema - Shipping Order (continued) <xsd:complexType name="cdItems"> <xsd:element name="item" type="cdItem"/> </xsd:complexType> <xsd:complexType name="cdItem"> <xsd:element name="title" type="xsd:string"/> <xsd:element name="quantity“ type="xsd:positiveInteger"/> <xsd:element name="price" type="xsd:decimal"/> </xsd:complexType> </xsd:schema>