SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
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>

Weitere ähnliche Inhalte

Was ist angesagt?

Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)Partnered Health
 
transforming xml using xsl and xslt
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xsltHemant Suthar
 
HTML Frameset & Inline Frame
HTML Frameset & Inline FrameHTML Frameset & Inline Frame
HTML Frameset & Inline FrameNisa Soomro
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Html images syntax
Html images syntaxHtml images syntax
Html images syntaxJayjZens
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Difference between dtd and xsd
Difference between dtd and xsdDifference between dtd and xsd
Difference between dtd and xsdUmar Ali
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptMuhammadRehan856177
 
Extensible Markup Language (XML)
Extensible Markup Language (XML)Extensible Markup Language (XML)
Extensible Markup Language (XML)AakankshaR
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Gil Fink
 

Was ist angesagt? (20)

Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
transforming xml using xsl and xslt
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xslt
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
HTML Frameset & Inline Frame
HTML Frameset & Inline FrameHTML Frameset & Inline Frame
HTML Frameset & Inline Frame
 
Xml ppt
Xml pptXml ppt
Xml ppt
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Css selectors
Css selectorsCss selectors
Css selectors
 
Xml namespace
Xml namespaceXml namespace
Xml namespace
 
Html images syntax
Html images syntaxHtml images syntax
Html images syntax
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
DTD
DTDDTD
DTD
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Difference between dtd and xsd
Difference between dtd and xsdDifference between dtd and xsd
Difference between dtd and xsd
 
Html frames
Html framesHtml frames
Html frames
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).ppt
 
Extensible Markup Language (XML)
Extensible Markup Language (XML)Extensible Markup Language (XML)
Extensible Markup Language (XML)
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
Css box-model
Css box-modelCss box-model
Css box-model
 

Ähnlich wie Xml schema (20)

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
 
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
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 

Mehr von Prabhakaran V M

Mehr von 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
 

Kürzlich hochgeladen

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 

Kürzlich hochgeladen (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

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>