SlideShare a Scribd company logo
1 of 15
Web Technology
(NCS-504)
Prepared By
Mr.Abhishek Kesharwani
Assistant Professor,UCER Naini,Allahabad
XML Schema
Introduction to XML Schema
XML Schema is an XML-based alternative to
DTD.
An XML schema describes the structure of an
XML document.
The XML Schema language is also referred to
as XML Schema Definition (XSD).
3
Purpose of an XML Schema
The purpose of an XML Schema is to define the legal building
blocks of an XML document, just like a DTD.
defines elements that can appear in a document
defines attributes that can appear in a document
defines which elements are child elements
defines the order of child elements
defines the number of child elements
defines whether an element is empty or can include text
defines data types for elements and attributes
defines default and fixed values for elements and attributes
4
XML Schemas Support Data
Types
One of the greatest strength of XML Schemas is the support for
data types.
With support for data types:
It is easier to describe allowable document content
It is easier to validate the correctness of data
It is easier to work with data from a database
It is easier to define data facets (restrictions on data)
It is easier to define data patterns (data formats)
It is easier to convert data between different data types
5
XML Schemas use XML Syntax
Another great strength about XML Schemas is that they are written
in XML.Some benefits of that XML Schemas are written in XML:
You don't have to learn a new language
You can use your XML editor to edit your Schema files
You can use your XML parser to parse your Schema files
You can manipulate your Schema with the XML DOM
You can transform your Schema with XSLT
6
XML Schemas Secure Data
Communication
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".
7
XML Schemas are Extensible
XML Schemas are extensible, because they are written in XML.
With an extensible Schema definition you can:
Reuse your Schema in other Schemas
Create your own data types derived from the standard types
Reference multiple schemas in the same document
8
A Simple XML Document
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
9
An XML Schema
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"targetNam
espace="http://www.w3schools.com"xmlns="http://www.w3
schools.com" elementFormDefault="qualified">
<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>10
</xs:complexType>
</xs:element>
</xs:schema>
The <schema> Element
The <schema> element is the root element of every XML Schema
<?xml version="1.0"?>
<xs:schema>......</xs:schema>
11
xmlns:xs="http://www.w3.org/2001/XMLSchema"
indicates that the elements and data types used in the schema
come from the "http://www.w3.org/2001/XMLSchema"
namespace. It also specifies that the elements and data types
that come from the
"http://www.w3.org/2001/XMLSchema" namespace
should be prefixed with xs:
12
targetNamespace="http://www.w3schools.com" indicates
that the elements defined by this schema (note, to, from,
heading, body.) come from the
"http://www.w3schools.com" namespace.
This fragment:
xmlns="http://www.w3schools.com" indicates that the
default namespace is "http://www.w3schools.com".
13
XML Schemas define the elements of your XML
files.
A simple element is an XML element that contains
only text. It cannot contain any other elements or
attributes.
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
<xs:attribute name="xxx" type="yyy"/>
where xxx is the name of the attribute and yyy specifies the
data type of the attribute.
14
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
15

More Related Content

What's hot (20)

Xml
XmlXml
Xml
 
XML
XMLXML
XML
 
03 namespace
03 namespace03 namespace
03 namespace
 
Xml
XmlXml
Xml
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
XML
XMLXML
XML
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 
XML-Extensible Markup Language
XML-Extensible Markup Language XML-Extensible Markup Language
XML-Extensible Markup Language
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
10. XML in DBMS
10. XML in DBMS10. XML in DBMS
10. XML in DBMS
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Web programming xml
Web programming  xmlWeb programming  xml
Web programming xml
 
XML
XMLXML
XML
 
XML and Databases
XML and DatabasesXML and Databases
XML and Databases
 
Xml dom
Xml domXml dom
Xml dom
 
XML
XMLXML
XML
 
Xml Presentation-3
Xml Presentation-3Xml Presentation-3
Xml Presentation-3
 
Extensible Markup Language (XML)
Extensible Markup Language (XML)Extensible Markup Language (XML)
Extensible Markup Language (XML)
 

Viewers also liked

¿Què es un sistema?
¿Què es un sistema?¿Què es un sistema?
¿Què es un sistema?nanatorres
 
AWilson_finalunit_12-9-13 CTI
AWilson_finalunit_12-9-13 CTIAWilson_finalunit_12-9-13 CTI
AWilson_finalunit_12-9-13 CTIAmbrosia Wilson
 
Cилы взаимодействия молекул
Cилы взаимодействия молекулCилы взаимодействия молекул
Cилы взаимодействия молекулNickEliot
 
Metody poszukiwania pracy ANNA PASŁAWSKA-MIODUSZEWSKA
Metody poszukiwania pracy  ANNA PASŁAWSKA-MIODUSZEWSKAMetody poszukiwania pracy  ANNA PASŁAWSKA-MIODUSZEWSKA
Metody poszukiwania pracy ANNA PASŁAWSKA-MIODUSZEWSKAWolny Przemysław
 
Gerenciadores de boot
Gerenciadores de bootGerenciadores de boot
Gerenciadores de bootTiago
 
Trust-Based PPC: Stop Explaining What. Start Proving Why
Trust-Based PPC: Stop Explaining What. Start Proving WhyTrust-Based PPC: Stop Explaining What. Start Proving Why
Trust-Based PPC: Stop Explaining What. Start Proving WhyJoe Martinez
 
The Tools of Video Game Analysis
The Tools of Video Game AnalysisThe Tools of Video Game Analysis
The Tools of Video Game AnalysisAustin O'Brien
 

Viewers also liked (11)

Destacadas
DestacadasDestacadas
Destacadas
 
¿Què es un sistema?
¿Què es un sistema?¿Què es un sistema?
¿Què es un sistema?
 
AWilson_finalunit_12-9-13 CTI
AWilson_finalunit_12-9-13 CTIAWilson_finalunit_12-9-13 CTI
AWilson_finalunit_12-9-13 CTI
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Cилы взаимодействия молекул
Cилы взаимодействия молекулCилы взаимодействия молекул
Cилы взаимодействия молекул
 
Metody poszukiwania pracy ANNA PASŁAWSKA-MIODUSZEWSKA
Metody poszukiwania pracy  ANNA PASŁAWSKA-MIODUSZEWSKAMetody poszukiwania pracy  ANNA PASŁAWSKA-MIODUSZEWSKA
Metody poszukiwania pracy ANNA PASŁAWSKA-MIODUSZEWSKA
 
Risk Assessments Qeb Standards 19
Risk Assessments   Qeb Standards 19Risk Assessments   Qeb Standards 19
Risk Assessments Qeb Standards 19
 
Asp introduction
Asp introductionAsp introduction
Asp introduction
 
Gerenciadores de boot
Gerenciadores de bootGerenciadores de boot
Gerenciadores de boot
 
Trust-Based PPC: Stop Explaining What. Start Proving Why
Trust-Based PPC: Stop Explaining What. Start Proving WhyTrust-Based PPC: Stop Explaining What. Start Proving Why
Trust-Based PPC: Stop Explaining What. Start Proving Why
 
The Tools of Video Game Analysis
The Tools of Video Game AnalysisThe Tools of Video Game Analysis
The Tools of Video Game Analysis
 

Similar to uptu web technology unit 2 Xml2

Similar to uptu web technology unit 2 Xml2 (20)

XML1.pptx
XML1.pptxXML1.pptx
XML1.pptx
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
XML Schema.pdf
XML Schema.pdfXML Schema.pdf
XML Schema.pdf
 
Xml schema
Xml schemaXml schema
Xml schema
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faq
 
Xml viva questions
Xml viva questionsXml viva questions
Xml viva questions
 
Full xml
Full xmlFull xml
Full xml
 
Xml PPT
Xml PPTXml PPT
Xml PPT
 
paper about xml
paper about xmlpaper about xml
paper about xml
 
Xml iet 2015
Xml iet 2015Xml iet 2015
Xml iet 2015
 
Enhanced xml validation using srml01
Enhanced xml validation using srml01Enhanced xml validation using srml01
Enhanced xml validation using srml01
 
Xml basics for beginning
Xml basics for beginningXml basics for beginning
Xml basics for beginning
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
Xml programming language myassignmenthelp.net
Xml programming  language myassignmenthelp.netXml programming  language myassignmenthelp.net
Xml programming language myassignmenthelp.net
 
eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
 
Data interchange integration, HTML XML Biological XML DTD
Data interchange integration, HTML XML Biological XML DTDData interchange integration, HTML XML Biological XML DTD
Data interchange integration, HTML XML Biological XML DTD
 
ADBMS_ASSIGNMENT_PPT1[1] (2).pptx
ADBMS_ASSIGNMENT_PPT1[1] (2).pptxADBMS_ASSIGNMENT_PPT1[1] (2).pptx
ADBMS_ASSIGNMENT_PPT1[1] (2).pptx
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
 
ENCh26.ppt
ENCh26.pptENCh26.ppt
ENCh26.ppt
 

More from Abhishek Kesharwani (20)

uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
Unit 1 web technology uptu slide
Unit 1 web technology uptu slideUnit 1 web technology uptu slide
Unit 1 web technology uptu slide
 
Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1 Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1
 
Unit1 2
Unit1 2 Unit1 2
Unit1 2
 
Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1 Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1
 
Mtech syllabus computer science uptu
Mtech syllabus computer science uptu Mtech syllabus computer science uptu
Mtech syllabus computer science uptu
 
Wi max tutorial
Wi max tutorialWi max tutorial
Wi max tutorial
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Tcp traffic control and red ecn
Tcp traffic control and red ecnTcp traffic control and red ecn
Tcp traffic control and red ecn
 
Schedulling
SchedullingSchedulling
Schedulling
 
Scheduling
SchedulingScheduling
Scheduling
 
Rsa example
Rsa exampleRsa example
Rsa example
 
Routers and planes (1)
Routers and planes (1)Routers and planes (1)
Routers and planes (1)
 

Recently uploaded

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
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 17Celine George
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
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 ModeThiyagu K
 

Recently uploaded (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
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
 

uptu web technology unit 2 Xml2

  • 1. Web Technology (NCS-504) Prepared By Mr.Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad
  • 3. Introduction to XML Schema XML Schema is an XML-based alternative to DTD. An XML schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD). 3
  • 4. Purpose of an XML Schema The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. defines elements that can appear in a document defines attributes that can appear in a document defines which elements are child elements defines the order of child elements defines the number of child elements defines whether an element is empty or can include text defines data types for elements and attributes defines default and fixed values for elements and attributes 4
  • 5. XML Schemas Support Data Types One of the greatest strength of XML Schemas is the support for data types. With support for data types: It is easier to describe allowable document content It is easier to validate the correctness of data It is easier to work with data from a database It is easier to define data facets (restrictions on data) It is easier to define data patterns (data formats) It is easier to convert data between different data types 5
  • 6. XML Schemas use XML Syntax Another great strength about XML Schemas is that they are written in XML.Some benefits of that XML Schemas are written in XML: You don't have to learn a new language You can use your XML editor to edit your Schema files You can use your XML parser to parse your Schema files You can manipulate your Schema with the XML DOM You can transform your Schema with XSLT 6
  • 7. XML Schemas Secure Data Communication 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". 7
  • 8. XML Schemas are Extensible XML Schemas are extensible, because they are written in XML. With an extensible Schema definition you can: Reuse your Schema in other Schemas Create your own data types derived from the standard types Reference multiple schemas in the same document 8
  • 9. A Simple XML Document <?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> 9
  • 10. An XML Schema <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"targetNam espace="http://www.w3schools.com"xmlns="http://www.w3 schools.com" elementFormDefault="qualified"> <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>10
  • 11. </xs:complexType> </xs:element> </xs:schema> The <schema> Element The <schema> element is the root element of every XML Schema <?xml version="1.0"?> <xs:schema>......</xs:schema> 11
  • 12. xmlns:xs="http://www.w3.org/2001/XMLSchema" indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs: 12
  • 13. targetNamespace="http://www.w3schools.com" indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "http://www.w3schools.com" namespace. This fragment: xmlns="http://www.w3schools.com" indicates that the default namespace is "http://www.w3schools.com". 13
  • 14. XML Schemas define the elements of your XML files. A simple element is an XML element that contains only text. It cannot contain any other elements or attributes. 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 <xs:attribute name="xxx" type="yyy"/> where xxx is the name of the attribute and yyy specifies the data type of the attribute. 14
  • 15. 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 15