waqas anwar next slideprevious slide. waqas anwar next slideprevious slide xml xml stands for...
TRANSCRIPT
Waqas Anwar
Next SlidePrevious Slide
Waqas Anwar
Next SlidePrevious Slide
XML• XML stands for EXtensible Markup Language
Waqas Anwar
Next SlidePrevious Slide
XML• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
Waqas Anwar
Next SlidePrevious Slide
XML• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to describe data
Waqas Anwar
Next SlidePrevious Slide
XML• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to describe data
• XML tags are not predefined. You must define your own tags
Waqas Anwar
Next SlidePrevious Slide
XML• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to describe data
• XML tags are not predefined. You must define your own tags
• XML uses a Document Type Definition (DTD) or an XML Schema to describe the data
Waqas Anwar
Next SlidePrevious Slide
XML• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to describe data
• XML tags are not predefined. You must define your own tags
• XML uses a Document Type Definition (DTD) or an XML Schema to describe the data
• XML with a DTD or XML Schema is designed to be self-descriptive
Waqas Anwar
Next SlidePrevious Slide
XML• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to describe data
• XML tags are not predefined. You must define your own tags
• XML uses a Document Type Definition (DTD) or an XML Schema to describe the data
• XML with a DTD or XML Schema is designed to be self-descriptive
• XML is a W3C Recommendation
Waqas Anwar
Next SlidePrevious Slide
XML
• XML does not DO anything
Waqas Anwar
Next SlidePrevious Slide
XML
• XML does not DO anything
• XML is free and extensible
Waqas Anwar
Next SlidePrevious Slide
XML
• XML does not DO anything
• XML is free and extensible
• XML is a complement to HTML
Waqas Anwar
Next SlidePrevious Slide
XML
• XML does not DO anything
• XML is free and extensible
• XML is a complement to HTML
• XML is future Web development
Waqas Anwar
Next SlidePrevious Slide
XML
• XML does not DO anything
• XML is free and extensible
• XML is a complement to HTML
• XML is future Web development
• XML is going to be everywhere.
Waqas Anwar
Next SlidePrevious Slide
XML vs. HTML
HTML is about displaying information
XML is about describing information.
HTML was designed to display data and to focus on how data looks.
XML was designed to describe data and to focus on what data is.
Waqas Anwar
Next SlidePrevious Slide
How can XML be Used
XML can Separate Data from HTML
Waqas Anwar
Next SlidePrevious Slide
How can XML be Used
XML can Separate Data from HTML
XML is used to Exchange Data
Waqas Anwar
Next SlidePrevious Slide
How can XML be Used
XML can Separate Data from HTML
XML is used to Exchange Data
XML can be used to Share Data
Waqas Anwar
Next SlidePrevious Slide
How can XML be Used
XML can Separate Data from HTML
XML is used to Exchange Data
XML can be used to Share Data
XML can be used to Store Data
Waqas Anwar
Next SlidePrevious Slide
How can XML be Used
XML can Separate Data from HTML
XML is used to Exchange Data
XML can be used to Share Data
XML can be used to Store Data
XML can make your Data more Useful
Waqas Anwar
Next SlidePrevious Slide
How can XML be Used
XML can Separate Data from HTML
XML is used to Exchange Data
XML can be used to Share Data
XML can be used to Store Data
XML can make your Data more Useful
XML can be used to Create new Languages
Waqas Anwar
Next SlidePrevious Slide
XML ComponentsComment
Declaration
Root Element
Element
Nested Element (child element)
Template Data
Empty Element
Attribute
Waqas Anwar
Next SlidePrevious Slide
Comment
<!-- Email XML Document -->
…………
Waqas Anwar
Next SlidePrevious Slide
Declaration
<?xml version="1.0" encoding="ISO-8859-1"?>
encoding=" UTF-7”encoding=" UTF-8”
Waqas Anwar
Next SlidePrevious Slide
Root Element
<?xml version="1.0" encoding="ISO-8859-1"?> <note>
</note>
Waqas Anwar
Next SlidePrevious Slide
Nested Elements
<?xml version="1.0" encoding="ISO-8859-1"?> <note><to></to> <from></from> <heading></heading> <body></body>
</note>
Waqas Anwar
Next SlidePrevious Slide
Template Data
<?xml version="1.0" encoding="ISO-8859-1"?> <note><to>Waqas</to> <from>Nadeem</from> <heading>Meeting Reminder</heading> <body>Don’t forget me this weekend</body>
</note>
Waqas Anwar
Next SlidePrevious Slide
Empty Element
<?xml version="1.0" encoding="ISO-8859-1"?> <note><to>Waqas</to> <from>Nadeem</from> <heading>Meeting Reminder</heading> <body>Don't forget me this weekend!</body><send />
</note>
<send /> or <send></send> both are valid
Waqas Anwar
Next SlidePrevious Slide
Attribute
<?xml version="1.0" encoding="ISO-8859-1"?> <note id=“1101” date=“20-12-2006”><to>Waqas</to> <from>Nadeem</from> <heading>Meeting Reminder</heading> <body>Don't forget me this weekend!</body><send />
</note>
Waqas Anwar
Next SlidePrevious Slide
All XML Components
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Sample XML Document -->
<note id=“112”> <to>Waqas</to> <from>Nadeem</from> <heading>Meeting Reminder</heading> <body>Don't forget me this weekend!</body>
<send /></note>
Waqas Anwar
Next SlidePrevious Slide
Well Formed XML Documents
Waqas Anwar
Next SlidePrevious Slide
All XML elements must have a closing tag.
Well-Formed Document Rules
Waqas Anwar
Next SlidePrevious Slide
All XML elements must have a closing tag
XML tags are case sensitive
Well-Formed Document Rules
Waqas Anwar
Next SlidePrevious Slide
All XML elements must have a closing tag
XML tags are case sensitive
All XML elements must be properly nested
Well-Formed Document Rules
Waqas Anwar
Next SlidePrevious Slide
All XML elements must have a closing tag
XML tags are case sensitive
All XML elements must be properly nested
All XML documents must have a root element
Well-Formed Document Rules
Waqas Anwar
Next SlidePrevious Slide
Well-Formed Document Rules
All XML elements must have a closing tag
XML tags are case sensitive
All XML elements must be properly nested
All XML documents must have a root element
Attribute values must always be quoted
Waqas Anwar
Next SlidePrevious Slide
All XML elements must have a closing tag
XML tags are case sensitive
All XML elements must be properly nested
All XML documents must have a root element
Attribute values must always be quoted
Attributes can not be duplicated in one element.
Well-Formed Document Rules
Waqas Anwar
Next SlidePrevious Slide
ExerciseCreate a well-formed XML document describing the mobile phone specification which is send by one mobile phone manufacture to different phone dealers.
You need to describe the following information with every mobile.
mobile-codebrand-namemodelcolorprice
Waqas Anwar
Next SlidePrevious Slide
Solution<?xml version="1.0" encoding="UTF-8"?>
<mobiles><mobile>
<mobile-code>11-258-745</mobile-code><brand-name>Nokia</brand-name><model>6630</model><color>silver</color><price>299.99</price>
</mobile><mobile>
<mobile-code>11-365-125</mobile-code><brand-name>Samsung</brand-name><model>D500</model><color>black</color><price>499.99</price>
</mobile></mobiles>
Waqas Anwar
Next SlidePrevious Slide
XML Transformation
Waqas Anwar
Next SlidePrevious Slide
XML TransformationXML does not use predefined tags and the meaning of these tags are
not well understood.
Waqas Anwar
Next SlidePrevious Slide
XML TransformationXML does not use predefined tags and the meaning of these tags are
not well understood.
A <table> element could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it.
Waqas Anwar
Next SlidePrevious Slide
XML TransformationXML does not use predefined tags and the meaning of these tags are
not well understood.
A <table> element could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it.
We can transform XML files into other formats like HTML, Text, XML, DOC, PDF
Waqas Anwar
Next SlidePrevious Slide
XML TransformationXML does not use predefined tags and the meaning of these tags are
not well understood.
A <table> element could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it.
We can transform XML files into other formats like HTML, Text, XML, DOC, PDF
We use following technologies for transformation
• CSS
• XSL / XSLT
• XSLT-FO
Waqas Anwar
Next SlidePrevious Slide
CSS
Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in a markup languages.
Its most common application is to style web pages written in HTML, XHTML or XML
Waqas Anwar
Next SlidePrevious Slide
CSS
Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in a markup languages.
Its most common application is to style web pages written in HTML, XHTML or XML
CSS define how to display HTML elements
Waqas Anwar
Next SlidePrevious Slide
CSS
Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in a markup languages.
Its most common application is to style web pages written in HTML, XHTML or XML
CSS define how to display HTML elements Styles are normally stored in Style Sheets
Waqas Anwar
Next SlidePrevious Slide
CSS
Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in a markup languages.
Its most common application is to style web pages written in HTML, XHTML or XML
CSS define how to display HTML elements Styles are normally stored in Style Sheets Styles were added to HTML 4.0
Waqas Anwar
Next SlidePrevious Slide
CSS
Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in a markup languages.
Its most common application is to style web pages written in HTML, XHTML or XML
CSS define how to display HTML elements Styles are normally stored in Style Sheets Styles were added to HTML 4.0External Style Sheets are stored in CSS files
Waqas Anwar
Next SlidePrevious Slide
CSS
Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in a markup languages.
Its most common application is to style web pages written in HTML, XHTML or XML
CSS define how to display HTML elements Styles are normally stored in Style Sheets Styles were added to HTML 4.0External Style Sheets are stored in CSS filesExternal Style Sheets can save you a lot of work
Waqas Anwar
Next SlidePrevious Slide
catalog.xml<?xml version="1.0" encoding="UTF-8"?><catalog>
<cd><title>Titanic</title><country>Pakistan</country><company>Columbia Pictures</company><price>100</price><year>2000</year>
</cd><cd>
<title>Jurassic Park</title><country>United Kingdom</country><company>Paramount Pictures</company><price>100</price><year>2002</year>
</cd></catalog>
Waqas Anwar
Next SlidePrevious Slide
style.csscatalog {
background-color: #336699;width: 50%;font-size:12ptt;font-family:Arial;border-size:1;border-style:solid;border-color:#336699;
}
Waqas Anwar
Next SlidePrevious Slide
style.csscatalog {
background-color: #336699;width: 50%;font-size:12ptt;font-family:Arial;border-size:1;border-style:solid;border-color:#336699;
}cd{
display: block;background-color: #ffffff;
}
Waqas Anwar
Next SlidePrevious Slide
style.csscatalog {
background-color: #336699;width: 50%;font-size:12ptt;font-family:Arial;border-size:1;border-style:solid;border-color:#336699;
}cd{
display: block;background-color: #ffffff;
}title{
width:100%;background-color: #336699;color:white;padding: 5px;
}
Waqas Anwar
Next SlidePrevious Slide
style.csscatalog {
background-color: #336699;width: 50%;font-size:12ptt;font-family:Arial;border-size:1;border-style:solid;border-color:#336699;
}cd{
display: block;background-color: #ffffff;
}title{
width:100%;background-color: #336699;color:white;padding: 5px;
}country,price,year,company{
background-color: #ffffff;display: block;font-size:10pt;font-family:Arial;color: #000000;margin-left: 5pt;
}
Waqas Anwar
Next SlidePrevious Slide
Link CSS with XML<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/css" href="catalog.css"?><catalog>
<cd><title>Titanic</title><country>Pakistan</country><company>Columbia Pictures</company><price>100</price><year>2000</year>
</cd><cd>
<title>Jurassic Park</title><country>United Kingdom</country><company>Paramount Pictures</company><price>100</price><year>2002</year>
</cd></catalog>
Waqas Anwar
Next SlidePrevious Slide
XSL
XSL consists of three parts
XSLT - a language for transforming XML documents XPath - a language for navigating in XML documents XSL-FO - a language for formatting XML documents
Waqas Anwar
Next SlidePrevious Slide
XSLT Transformation
XSLT stands for XSL Transformations XSLT is the most important part of XSL XSLT transforms an XML document into another document XSLT uses XPath to navigate in XML documents XSLT is a W3C Recommendation
Waqas Anwar
Next SlidePrevious Slide
XML with XSLT<?xml version="1.0" encoding="UTF-8"?><catalog>
<cd><title>Titanic</title><country>Pakistan</country><company>Columbia Pictures</company><price>100</price><year>2000</year>
</cd><cd>
<title>Jurassic Park</title><country>United Kingdom</country><company>Paramount Pictures</company><price>100</price><year>2002</year>
</cd></catalog>
Waqas Anwar
Next SlidePrevious Slide
Link XML with XSLT
We link the external style sheet with XML using the following line
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xslt"?><catalog> ....</catalog>
Waqas Anwar
Next SlidePrevious Slide
XSLT DeclarationThe correct way to declare an XSL style sheet according to the W3C XSLT Recommendation is:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
or
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Waqas Anwar
Next SlidePrevious Slide
XSLT Templates<xsl-template>
An XSL style sheet consists of one or more set of rules that are called templates.
The <xsl:template> element is used to build templates.
The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document.
<xsl:template match=“/”>
The value of the match attribute is an XPath expression.
Waqas Anwar
Next SlidePrevious Slide
<xsl:value-of>
The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation.
<xsl:value-of select="catalog/cd/title"/>
The value of the select attribute is an XPath expression. An XPath expression works like navigating a file system.
Waqas Anwar
Next SlidePrevious Slide
<xsl:for-each>
The <xsl:for-each> element allows you to do looping in XSLT.
<xsl:for-each select="catalog/cd"> <xsl:value-of select="title"/><xsl:value-of select="artist"/>
</xsl:for-each>
The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set:
Waqas Anwar
Next SlidePrevious Slide
<xsl:sort>
The <xsl:sort> element is used to sort the output.
<xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <xsl:value-of select="title"/><xsl:value-of select="artist"/>
</xsl:for-each>
To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file
Waqas Anwar
Next SlidePrevious Slide
Complete XSLT File<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/catalog">
<table align="center" width="70%" style="background-color:#f3f3f3;" cellspacing="0" cellpadding="10px"><tr style="background-color:#336699; color:white;">
<td>DVD Title</td><td>Country</td><td>Company</td><td>Price</td><td>Year</td>
</tr><xsl:for-each select="cd">
<xsl:sort order="ascending" select="year" /><tr>
<td> <xsl:value-of select="title"/> </td><td> <xsl:value-of select="country"/> </td><td> <xsl:value-of select="company"/> </td><td> <xsl:value-of select="price"/> </td><td> <xsl:value-of select="year"/> </td>
</tr></xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Waqas Anwar
Next SlidePrevious Slide
XML Validation
Waqas Anwar
Next SlidePrevious Slide
XML Validation
We can use following two technologies two validate XML files.
• DTD
• Schema
Waqas Anwar
Next SlidePrevious Slide
Document Type Definition
The purpose of a DTD (Document Type Definition) is to define the legal building blocks of an XML document.
Waqas Anwar
Next SlidePrevious Slide
Document Type Definition
The purpose of a DTD (Document Type Definition) is to define the legal building blocks of an XML document.
It defines the document structure with a list of legal elements.
Waqas Anwar
Next SlidePrevious Slide
Document Type Definition
The purpose of a DTD (Document Type Definition) is to define the legal building blocks of an XML document.
It defines the document structure with a list of legal elements.
A DTD can be declared inline in your XML document, or as an external reference.
Waqas Anwar
Next SlidePrevious Slide
Benefits of DTD
With DTD, each of your XML files can carry a description of its own format with it.
Waqas Anwar
Next SlidePrevious Slide
Benefits of DTD
With DTD, each of your XML files can carry a description of its own format with it.
With a DTD, independent groups of people can agree to use a common DTD for interchanging data.
Waqas Anwar
Next SlidePrevious Slide
Benefits of DTD
With DTD, each of your XML files can carry a description of its own format with it.
With a DTD, independent groups of people can agree to use a common DTD for interchanging data.
Your application can use a standard DTD to verify that the data you receive from the outside world is valid.
Waqas Anwar
Next SlidePrevious Slide
Benefits of DTD
With DTD, each of your XML files can carry a description of its own format with it.
With a DTD, independent groups of people can agree to use a common DTD for interchanging data.
Your application can use a standard DTD to verify that the data you receive from the outside world is valid.
You can also use a DTD to verify your own data.
DTD is old technology and replaced more powerful and latest technology XML Schema.
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document 2. defines attributes that can appear in a document
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document 2. defines attributes that can appear in a document 3. defines which elements are child elements
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document 2. defines attributes that can appear in a document 3. defines which elements are child elements 4. defines the order of child elements
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document 2. defines attributes that can appear in a document 3. defines which elements are child elements 4. defines the order of child elements 5. defines the number of child elements
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document 2. defines attributes that can appear in a document 3. defines which elements are child elements 4. defines the order of child elements 5. defines the number of child elements 6. defines whether an element is empty or can include text
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document 2. defines attributes that can appear in a document 3. defines which elements are child elements 4. defines the order of child elements 5. defines the number of child elements 6. defines whether an element is empty or can include text 7. defines data types for elements and attributes
Waqas Anwar
Next SlidePrevious Slide
XML Schema
An XML Schema:
1. defines elements that can appear in a document 2. defines attributes that can appear in a document 3. defines which elements are child elements 4. defines the order of child elements 5. defines the number of child elements 6. defines whether an element is empty or can include text 7. defines data types for elements and attributes 8. defines default and fixed values for elements and attributes
Waqas Anwar
Next SlidePrevious Slide
XML Validation with XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<note><to>Waqas</to><from>Nadeem</from><heading>Meeting Reminder</heading><body>Don't forget me this weekend!</body>
</note>
Waqas Anwar
Next SlidePrevious Slide
XML Validation with XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<note xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Note.xsd">
<to>Waqas</to><from>Nadeem</from><heading>Meeting Reminder</heading><body>Don't forget me this weekend!</body>
</note>
Waqas Anwar
Next SlidePrevious Slide
Root Element <xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
</xs:schema>
Waqas Anwar
Next SlidePrevious Slide
Simple Element
A simple element is an element that only contains template date.
<firstname>Waqas</firstname>
<salary>120000</salary>
Waqas Anwar
Next SlidePrevious Slide
Complex Element
A complex element is an XML element that contains other elements and/or attributes.
There are four kinds of complex elements:
empty elements elements that contain only other elements elements that contain only text elements that contain both other elements and text
Note: Each of these elements may contain attributes as well!
Waqas Anwar
Next SlidePrevious Slide
Complex Element<product pid="1345"/>
<employee> <firstname>John</firstname> <lastname>Smith</lastname>
</employee>
<food type="dessert">Ice cream</food>
<description> It happened on <date lang="norwegian">03.03.99</date> .... </description>
Waqas Anwar
Next SlidePrevious Slide
Declare Simple Element <xs:element>
A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes.
<xs:element name="xxx" type="yyy"/>
Waqas Anwar
Next SlidePrevious Slide
Declare Simple Element <xs:element>
<xs:element name="xxx" type="yyy"/>
<name>Ali</name><age>34</age><birthdate>1978-03-27</birthdate>
Waqas Anwar
Next SlidePrevious Slide
Declare Simple Element <xs:element>
<xs:element name="xxx" type="yyy"/>
<name>Ali</name><age>34</age><birthdate>1978-03-27</birthdate>
<xs:element name="name" type="xs:string"/>
Waqas Anwar
Next SlidePrevious Slide
Declare Simple Element <xs:element>
<xs:element name="xxx" type="yyy"/>
<name>Ali</name><age>34</age><birthdate>1978-03-27</birthdate>
<xs:element name="name" type="xs:string"/> <xs:element name="age" type="xs:integer"/>
Waqas Anwar
Next SlidePrevious Slide
Declare Simple Element <xs:element>
<xs:element name="xxx" type="yyy"/>
<name>Ali</name><age>34</age><birthdate>1978-03-27</birthdate>
<xs:element name="lastname" type="xs:string"/> <xs:element name="age" type="xs:integer"/> <xs:element name=“birthdate" type="xs:date"/>
Waqas Anwar
Next SlidePrevious Slide
Common Schema Data types
xs:string xs:decimal xs:integer xs:boolean xs:date xs:time
Waqas Anwar
Next SlidePrevious Slide
Declare default and fixed valuefor simple elements
<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>
Waqas Anwar
Next SlidePrevious Slide
Declare Attributes<xs:attribute>
<xs:attribute name="xxx" type="yyy"/>
Waqas Anwar
Next SlidePrevious Slide
Declare Attributes<xs:attribute>
<xs:attribute name="xxx" type="yyy"/>
<lastname lang="EN">Waqas</lastname>
Waqas Anwar
Next SlidePrevious Slide
Declare Attributes<xs:attribute>
<xs:attribute name="xxx" type="yyy"/>
<lastname lang="EN">Waqas</lastname>
<xs:attribute name="lang" type="xs:string"/>
Waqas Anwar
Next SlidePrevious Slide
Declare default and fixed valuefor attributes
<xs:attribute name=“lang" type="xs:string" default=“EN"/>
<xs:attribute name=“lang" type="xs:string" fixed=“EN"/>
Waqas Anwar
Next SlidePrevious Slide
Declare optional and required attributes
<xs:attribute name="lang" type="xs:string" use="optional"/>
<xs:attribute name="lang" type="xs:string" use="required"/>
Waqas Anwar
Next SlidePrevious Slide
XSD Restrictions
Restrictions are used to control acceptable values for XML elements or attributes.
Restriction on Values
<xs:element name="age">
<xs:simpleType> <xs:restriction base="xs:integer">
<xs:minInclusive value="0"/> <xs:maxInclusive value="100"/>
</xs:restriction> </xs:simpleType>
</xs:element>
Waqas Anwar
Next SlidePrevious Slide
Restriction on Set of Values
<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>
Waqas Anwar
Next SlidePrevious Slide
Restriction on Series of Values
<xs:element name="letter">
<xs:simpleType> <xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/> </xs:restriction>
</xs:simpleType>
</xs:element>
Waqas Anwar
Next SlidePrevious Slide
Restriction on Series of Values<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>
<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>
Waqas Anwar
Next SlidePrevious Slide
Restriction on Series of Values<xs:element name="choice">
<xs:simpleType> <xs:restriction base="xs:string">
<xs:pattern value="[xyz]"/> </xs:restriction>
</xs:simpleType></xs:element>
<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>
Waqas Anwar
Next SlidePrevious Slide
Restriction on length
<xs:element name="password"><xs:simpleType>
<xs:restriction base="xs:string"> <xs:length value="8"/>
</xs:restriction> </xs:simpleType>
</xs:element>
<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>