SlideShare a Scribd company logo
© People Strategists www.peoplestrategists.com Slide 1 of 64
XML Schemas
© People Strategists www.peoplestrategists.com Slide 2 of 64
Objectives
In this session, you will learn to:
Explain the concept of XML schema
Identify the advantages of XML schema over DTDs
Define XML schema elements
Create simple and complex type elements
Use of compositors with XML schema elements
Apply restrictions on simple type elements
Extend complex type elements
Creating reusable types and schemas
Explain the concept of SAX
Explain the concept of DOM
© People Strategists www.peoplestrategists.com Slide 3 of 64
Introduction to XML Schema
How can I get rid
of large DTDs that
are hard to read
and maintain?
© People Strategists www.peoplestrategists.com Slide 4 of 64
Introduction to XML Schema (Contd.)
© People Strategists www.peoplestrategists.com Slide 5 of 64
Introduction to XML Schema (Contd.)
© People Strategists www.peoplestrategists.com Slide 6 of 64
Introduction to XML Schema (Contd.)
Let us create an XML schema file, employee.xsd, for an XML file,
employee.xml, and add the reference of schema file in the XML file.
<?xml version="1.0"
encoding="utf-8"?>
<employee xmlns="mynamespace"
xmlns:xsi=http://www.w3.org/2001/
XMLSchema-instance
xsi:schemaLocation="mynamespace
employee.xsd">
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="mynamespace"
elementFormDefault="qualified"
xmlns="mynamespace employee.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname"
type="xs:string"/>
<xs:element name="lastname"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
employee.xsd employee.xml
© People Strategists www.peoplestrategists.com Slide 7 of 64
Introduction to XML Schema (Contd.)
The <schema> element is the root element of every XML Schema and
contains some attributes.
The targetNamespace attribute defines the namespace of the XML
file that has to be validated.
The elementFormDefault attribute defines whether its local
elements must be qualified or unqualified in an XML document.
The xmlns attribute specifies the default namespace.
The attribute xmlns:xs specifies the namespace of the elements and
datatypes used in the schema.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="<target_namespace>"
elementFormDefault="<qualified/unqualified>"
xmlns="<default_namespace>"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
.................
.................
</xs:schema>
© People Strategists www.peoplestrategists.com Slide 8 of 64
Introduction to XML Schema (Contd.)
You can add reference of an XML schema in an XML file by using
attributes, as shown in the following code snippet:
The xmlns attribute defines the namespace of the elements declared
in the XML file.
The xmlns:xsi attribute specifies the instance of the schema that is
used for the XML document.
The xsi:schemaLocation attribute specifies the location of the
schema.
<?xml version="1.0"?>
<emp xmlns="default_namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xsi:schemaLocation="<namespace> <schema_file>"
..............
..............
</emp>
© People Strategists www.peoplestrategists.com Slide 9 of 64
Advantages Over DTD
What are the
advantages of
using XML schema
over DTD?
© People Strategists www.peoplestrategists.com Slide 10 of 64
Advantages Over DTD (Contd.)
XML schemas follow a universal standard that made data
communication over the Internet safe.
For example, a date like: "01-07-2015" can be interpreted as 7
January in some countries, whereas in other countries as 1 July.
However, an XML element accepts date in the fixed format "YYYY-
MM-DD" to ensure its correct interpretation.
XML schemas support data types that allow programmers to:
Specify the acceptable content in the document
Ensure the validity of data
Work with databases
Apply restrictions on data
Specify data formats
Convert data from one data type to another
© People Strategists www.peoplestrategists.com Slide 11 of 64
Advantages Over DTD (Contd.)
You can define number and order of child elements using XML
schemas, but not with DTDs.
XML schemas support namespaces, whereas DTDs do not support
namespaces.
XML schemas can be also extended, therefore, you can:
Reuse an XML schema in other schemas.
Drive your own data types from the standard types.
Add the reference of multiple schemas in a single XML
document.
© People Strategists www.peoplestrategists.com Slide 12 of 64
Defining Elements
How can I define
an element in an
XML schema?
© People Strategists www.peoplestrategists.com Slide 13 of 64
Defining Elements (Contd.)
XML schemas define the elements of XML files.
You can use the XML syntax to define elements in an XML schema file.
To define an element, you can use the following syntax:
The following code snippet depicts some examples of defining
elements:
<xs:element name="<element_name>" type="data_name"/>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="dob" type="xs:date"/>
<xs:element name= "age" type="xs:numeric"/>
© People Strategists www.peoplestrategists.com Slide 14 of 64
Simple and Complex Types
You can define two types of elements in XML schemas. These are:
Element Types
Simple Complex
© People Strategists www.peoplestrategists.com Slide 15 of 64
Simple and Complex Types (Contd.)
Simple Type:
Is an XML element that contains only text.
Cannot contain other elements or attributes.
To define a simple type element, you can use the following syntax:
Some common built-in data types that XML schema supports are:
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
<xs:element name="<element_name>" type="data_name"/>
© People Strategists www.peoplestrategists.com Slide 16 of 64
Simple and Complex Types (Contd.)
You can also specify default or fixed value for a simple element.
The default value is implicitly assigned to the element if a specific
value is not provided.
The following code snippet shows an example of specifying default
value for an element:
If you specify a fixed value for an element, you cannot provide another
value for that element in your XML document.
The specified value is automatically assigned to the element.
<xs:element name="city" type="xs:string"
default="New York"/>
<xs:element name="city" type="xs:string"
fixed="New York"/>
© People Strategists www.peoplestrategists.com Slide 17 of 64
XSD Attributes:
Are used to provide additional information about an element.
Are defined with name and type properties in an XSD document.
The syntax of defining an attribute is shown as follows:
The following code snippet shows an example of defining an
attribute:
Simple and Complex Types (Contd.)
<xs:attribute name="<attribute_name>"
type="<data_type>" use="<type_of_use>"/>
<xs:attribute name="ID" type="xs:string"
use="required"/>
© People Strategists www.peoplestrategists.com Slide 18 of 64
Simple and Complex Types (Contd.)
Complex Type:
Elements include other elements and/or attributes.
For example, to define a complex type, person name, with two
other elements, first name and last name, you can use the
following code snippet:
<xs:element name="person_name">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 19 of 64
Simple and Complex Types (Contd.)
You can also create a complex type and reuse it in several other
complex element, as shown in the following code snippet:
<xs:element name="student" type="person_name"/>
<xs:element name="employee" type="person_name"/>
<xs:complexType name="person_name">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
© People Strategists www.peoplestrategists.com Slide 20 of 64
Simple and Complex Types (Contd.)
Complex type elements are of the following types:
ComplexType
Empty Elements
Elements Only
Text Only
Mixed
© People Strategists www.peoplestrategists.com Slide 21 of 64
Simple and Complex Types (Contd.)
Empty Elements:
Can only have attributes, but not text.
For example, you want to define a complex type empty element,
employee, with an attribute, emp id as an integer value, you can
use the following code snippet:
<xs:element name="employee">
<xs:complexType>
<xs:attribute name="empid" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 22 of 64
Simple and Complex Types (Contd.)
Elements Only:
Can contain other elements only.
For example, you want to define a complex type, employee name,
with two other elements, first name and last name, you can use the
following code snippet:
In the preceding code snippet, the <xs:sequence> tag specifies
that the first name and last name elements must appear in the given
order inside the employee_name element.
<xs:element name="employee_name">
<xs:complexType><xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence></xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 23 of 64
Simple and Complex Types (Contd.)
Text Only:
Can only contain text and attributes.
The simpleContent element must be defined to specify the
content for the element.
An extension or a restriction element must be used within
the simpleContent element to expand or to limit the content of
the element.
<xs:element name="contact_number">
<xs:complexType><xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent></xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 24 of 64
Simple and Complex Types (Contd.)
Mixed:
Can contain attributes, elements, and text.
is defined by setting the mixed attribute to "true" inside the
complexType element.
<xs:element name="order">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="pname" type="xs:string"/>
<xs:element name="orderid"
type="xs:positiveInteger"/>
<xs:element name="orderdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 25 of 64
Use of Compositors
What are
compositors?
© People Strategists www.peoplestrategists.com Slide 26 of 64
Use of Compositors (Contd.)
Compositors are one of the widely used XSD standards that specify the
XML document structure.
You can use compositors to describe the composition of child
elements within a parent element in an XML document.
They are generally used with complex type element.
They are used to control the use of elements in an XML document.
When compositors are used appropriately, they offer comprehensive
and robust data models.
© People Strategists www.peoplestrategists.com Slide 27 of 64
Use of Compositors (Contd.)
There are seven major compositors in XML, which are divided into three
categories.
Compositors
Order
All
Choice
Sequence
Occurrence
Min Occurs
Max Occurs
Group
Element
Attribute
© People Strategists www.peoplestrategists.com Slide 28 of 64
Use of Compositors (Contd.)
Order Compositors:
Are used to used to define the order of the elements.
The <all> compositor specifies that the child elements of an element
can appear in any order, and each child element must appear only once.
<xs:element name="person_name">
<xs:complexType>
<xs:all>
<xs:element name="firstname“ type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 29 of 64
Use of Compositors (Contd.)
You can use the <choice> compositor to specify that either one child
element or another can occur.
<xs:element name="person_name">
<xs:complexType>
<xs:choice>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 30 of 64
Use of Compositors (Contd.)
The <sequence> compositor is used to specify that the child elements
must appear in the given order.
<xs:element name="person_name">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 31 of 64
Use of Compositors (Contd.)
Occurrence Compositors:
Specify the maximum or minimum number of occurrences of an element
in an document.
You can use the using the <maxOccurs> compositor to specify the
maximum number of occurrences of an element.
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="contact_number"
type="xs:integer" maxOccurs="3"/>
</xs:sequence>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 32 of 64
Use of Compositors (Contd.)
You can specify the minimum number of occurrences of an element in an
document using the <minOccurs> compositor.
You can also specify that an element can occur any number of times by
specifying maxOccurs="unbounded" .
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="contact_number"
type="xs:integer" maxOccurs="3" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 33 of 64
Use of Compositors (Contd.)
Group Compositors:
Are use to specify the related sets of elements.
You can define an element group and refer it in another XML schema, as
shown in the following code snippet.
<xs:group name="empgroup">
<xs:sequence>
<xs:element
name="firstname"
type="xs:string"/>
<xs:element name="lastname"
type="xs:string"/>
<xs:element name="doj"
type="xs:date"/>
</xs:sequence></xs:group>
<xs:element name="emp"
type="empinfo"/>
<xs:complexTypename="empinfo">
<xs:sequence>
<xs:group ref="empgroup"/>
<xs:element name="city"
type="xs:string"/>
</xs:sequence></xs:complexType>
Group Definition Group Reference
© People Strategists www.peoplestrategists.com Slide 34 of 64
Use of Compositors (Contd.)
You can define an attribute group and refer it in another XML schema, as
shown in the following code snippet.
<xs:attributeGroup
name="empattrgroup">
<xs:attribute
name="firstname"
type="xs:string"/>
<xs:attribute
name="lastname"
type="xs:string"/>
<xs:attribute name="doj"
type="xs:date"/>
</xs:attributeGroup>
<xs:element name="employee">
<xs:complexType>
<xs:attributeGroup
ref="empattrgroup"/>
</xs:complexType>
</xs:element>
Group Definition Group Reference
© People Strategists www.peoplestrategists.com Slide 35 of 64
Restriction on Simple Types
© People Strategists www.peoplestrategists.com Slide 36 of 64
Restriction on Simple Types (Contd.)
You can apply restrictions on simple element types to specify the
acceptable values of XML elements or attributes.
In XML, restrictions on XML elements are known as facets.
TypesofRestrictions
Restrictions on Values
Restrictions on a Set of Values
Restrictions on a Series of Values
Restrictions on Whitespace Characters
Restrictions on Length
Restrictions for Data types
© People Strategists www.peoplestrategists.com Slide 37 of 64
Restriction on Simple Types (Contd.)
Restrictions on Values:
You can apply restriction on the value of an element. For example, the age of
an employee cannot be less than 21 and greater 60.
<xs:element name="emp_age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="21"/>
<xs:maxInclusive value="60"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 38 of 64
Restriction on Simple Types (Contd.)
Restrictions on a Set of Values:
You can apply restriction on an XML element such that the element can only
accept a value from a set of specified values.
For example, you can specify a job role element that can only accept one of
the values: Sales, Management, and Operations.
<xs:element name="job_role">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Sales"/>
<xs:enumeration value="Management"/>
<xs:enumeration value="Operations"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 39 of 64
Restriction on Simple Types (Contd.)
Restrictions on a Series of Values:
You can apply restrictions on a series of numbers or letters that can be used by
using the pattern constraint.
For example, you define the contact element that can accept only 10 digit
values such that the first digit should not be 0, and other digits must be from 0
to 9.
<xs:element name="contact">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="[1-9][0-9][0-9][0-9]
[0-9][0-9][0 9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 40 of 64
Restriction on Simple Types (Contd.)
Similarly, you can also apply restrictions on character values.
For example, you can define an element, lcase that can only accept a
lowercase letter from a-z.
<xs:element name="lcase">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 41 of 64
Restriction on Simple Types (Contd.)
For example, you define an element password that can accept exactly 10
characters in a row and those characters can be lowercase or uppercase letters
from a to z or a number from 0 to 9:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 42 of 64
Restriction on Simple Types (Contd.)
Restrictions on Whitespace Characters:
You can specify how whitespaces are treated for an element by using the
whiteSpace constraint.
The whiteSpace constraint may accept one of the following values:
 preserve: Leaves all the whitespace characters as they are.
 replace: Replaces all the whitespace characters with spaces.
 Collapse: Replaces line feeds, tabs, spaces, carriage returns are with
spaces and multiple spaces with a single space and removes leading
and trailing spaces.
© People Strategists www.peoplestrategists.com Slide 43 of 64
Restriction on Simple Types (Contd.)
For example, if you want to define a full_name element such that the
whitespaces are not removed by the XML processor, you can use the
following code snippet:
<xs:element name="full_name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 44 of 64
Restriction on Simple Types (Contd.)
Restrictions on Length:
You can limit the length of the value of an element by using the
maxLength and minLength constraints.
For example, you want to define an element, password, that have
minimum 6 letters and maximum 14 letters, you can use the following
code snippet:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="6"/>
<xs:maxLength value="14"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 45 of 64
Restriction on Simple Types (Contd.)
Restrictions on Data Types:
Some of the common restrictions that you can apply on data types are
listed in the following table.
Constraints Description
enumeration Specifies a set of acceptable values.
fractionDigits Specifies the maximum number of decimal
digits, must be equal to or greater than 0.
length Specifies the length of the value of an element.
maxExclusive Specifies the upper bound of a numeric value
that must be less than the specified value.
maxInclusive Specifies the upper bound of a numeric value
that must be less than or equal to the specified
value.
maxLength Specifies the maximum number of allowed
characters.
minExclusive Specifies the lower bounds of a numeric value
that must be greater than the specified value.
© People Strategists www.peoplestrategists.com Slide 46 of 64
Restriction on Simple Types (Contd.)
Constraints Description
minInclusive Specifies the lower bounds of a numeric value that
must be greater than or equal to the specified value.
minLength Specifies the minimum number of allowed
characters.
pattern Specifies a sequence of characters that are allowed.
totalDigits Specifies the number of allowed digits.
whiteSpace Specifies how to treat whitespaces.
© People Strategists www.peoplestrategists.com Slide 47 of 64
Extending Complex Types
You can take an existing entity and add more specific information to it
as per your requirement.
In programming languages, this concept is known as inheritance or sub
classing.
Inheritance or sub classing saves development time and effort.
The same concept is also applied in XSD standard.
You can take an existing complex type element and extend it to add
more information.
© People Strategists www.peoplestrategists.com Slide 48 of 64
Extending Complex Types (Contd.)
Consider that you have a complex element personal_info defined as
follows:
<xs:element name="personal_info">
<xs:complexType>
<xs:sequence>
<xs:element name="first_name" type="xs:string"/>
<xs:element name="last_name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
© People Strategists www.peoplestrategists.com Slide 49 of 64
Extending Complex Types (Contd.)
Now, you want to define two more elements, home_address and
office_address.
The addresses also contain the first name and last name of the person.
Instead of defining the first name and last name elements inside the
home_address and office_address elements, you can extend the
personal_info element to reuse the existing information by using the
<xs:extension> element.
You can define home_address by extending personal_info, as:
<xs:complexType name="home_address">
<xs:complexContent>
<xs:extension base="personal_info">
<xs:sequence>
<xs:element name="line1" type="xs:string"/>
<xs:element name="line2" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
home_address Element
© People Strategists www.peoplestrategists.com Slide 50 of 64
Extending Complex Types (Contd.)
Similarly, you can define the office_address element as:
<xs:complexType name="home_address">
<xs:complexContent>
<xs:extension base="personal_info">
<xs:sequence>
<xs:element name="line1" type="xs:string"/>
<xs:element name="line2" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
office_address Element
© People Strategists www.peoplestrategists.com Slide 51 of 64
Extending Complex Types (Contd.)
If you want to use only some specific elements from a complex type
element, you can use the <xs:restriction> element.
For example, you want to create a new element first_name, you can
restrict the personal_info type by using the <xs:restriction>
element, as:
<xs:complexType name="first_name">
<xs:complexContent>
<xs:restriction base="personal_info">
<xs:sequence>
<xs:element name="first_name" type="xs:string" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
first_name Element
© People Strategists www.peoplestrategists.com Slide 52 of 64
Creating Reusable Types
Can I create an XML
schema and reuse
it in other XML
schemas?
© People Strategists www.peoplestrategists.com Slide 53 of 64
Creating Reusable Types (Contd.)
If you want to create some elements that can be reused on
multiple files in your project, you should define these elements in
a separate XML schema, and refer it in other schemas whenever
required.
You can create an XML schema and reuse it in other schemas
with the help of the <xs:import> element.
For example, suppose, you have an XML schema, info.xsd that
defines the first name and last name of a person.
Now, you want to create a new schema, empinfo.xsd that also
contains the first name and last name of the person.
In this case, you can provide the reference of the info.xsd schema
in the empinfo.xsd and reuse the elements defined in the info.xsd
schema.
© People Strategists www.peoplestrategists.com Slide 54 of 64
Creating Reusable Types (Contd.)
The following code snippet shows the XML markup of info.xsd
schema:
You can reuse this schema in another schema with the help of
<xs:import> element.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.org/person"
targetNamespace="http://example.org/person">
<xsd:complexType name="personal_info">
<xsd:sequence>
<xsd:element name="first_name" type="xsd:string"/>
<xsd:element name="last_name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
info.xsd
© People Strategists www.peoplestrategists.com Slide 55 of 64
Creating Reusable Types (Contd.)
The following code snippet shows the XML markup of
empinfo.xsd schema:
<xs:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:basetns="http://example.org/person"
xmlns:tns="http://example.org/person/derived"
targetNamespace="http://example.org/person/derived">
<xs:import namespace="http://example.org/person"
schemaLocation="info.xsd"/>
<xs:complexType name="empInfo">
<xs:complexContent>
<xs:extension base="basetns:personal_info">
<xs:sequence>
<xs:element name="contact_num"
type="xs:numeric"/>
<xs:element name="doj" type="xs:date"/>
<xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
empinfo.xsd
© People Strategists www.peoplestrategists.com Slide 56 of 64
Identifying SAX
SAX stands for Simple API for XML.
It is an Application Programming Interface (API) to interpret
XML-based Web files or the Web files that use XML.
The API interprets the XML markup and describe the collection of
data.
SAX provides an alternative way to DOM for interpreting the XML
file.
It is a simpler interface in comparison to DOM and does not
require in-memory resource for processing.
© People Strategists www.peoplestrategists.com Slide 57 of 64
SAX (Contd.)
It is used where large number of files need to be processed.
You can use SAX to search small pieces of information in a large
document and abort processing when the information is found.
SAX is also capable to build DOM trees.
Developers can also traverse DOM trees to create SAX streams as well.
© People Strategists www.peoplestrategists.com Slide 58 of 64
DOM
The XML DOM is used to represent an XML document as a tree like
structure.
The DOM tree is called as the node-tree.
The DOM tree represents a hierarchical relationship between the nodes
of the tree.
The tree starts with the root node branches out to the text node to the
lowest level of the tree.
Each node of the tree can be accessed from the tree.
The content of the tree can be modified or deleted.
A new element can be also inserted in a DOM tree.
© People Strategists www.peoplestrategists.com Slide 59 of 64
DOM (Contd.)
The parent, children, and sibling terms are used to specify relationships
between nodes in a DOM tree.
A parent node have children.
Nodes that are at the same level are known as siblings.
The top node is known as the root node.
Each DOM tree has only one root node.
Each node except root node has a parent node.
A parent node can have any number of children.
A node that has no children is known as leaf node.
Nodes that have the same parent are known as siblings.
© People Strategists www.peoplestrategists.com Slide 60 of 64
Text:
ASP.NET
Text:
Benson
Text:
Kelly Bond
Text:
XML
Root Node
Sibling Nodes
Data
Parent-Child
Relationship
DOM (Contd.)
A sample XML DOM tree is shown as follows.
Book
Book 1
AuthorTitle
Book 2
Title Author
© People Strategists www.peoplestrategists.com Slide 61 of 64
Summary
XML schema, similar to DTDs, describes and validates the structure
of an XML document.
XML schemas are written in XML itself.
The targetNamespace attribute defines the namespace of the
XML file that has to be validated.
The attribute xmlns:xs specifies the namespace of the elements
and datatypes used in the schema.
XML schemas support data types that allow users to:
Specify the acceptable content in the document
Ensure the validity of data
Work with databases
Apply restrictions on data
Specify data formats
Convert data from one data type to another
© People Strategists www.peoplestrategists.com Slide 62 of 64
Summary (Contd.)
XML schemas can be also extended, therefore, you can:
Reuse an XML schema in other schemas.
Drive your own data types from the standard types.
Add the reference of multiple schemas in a single XML document.
You can define two types of elements in XML schemas. These are:
Simple Type
Complex Type
You can use XSDs to specify the structure of markup in an XML
document at different levels.
Compositors are one of the widely used XSD standards that specify
the XML document structure.
When compositors are used appropriately, they offer comprehensive
and robust data models.
© People Strategists www.peoplestrategists.com Slide 63 of 64
Summary (Contd.)
In XML, restrictions on XML elements are known as facets. Types of
restrictions are:
Restrictions on Values
Restrictions on a Set of Values
Restrictions on a Series of Values
Restrictions on Whitespace Characters
Restrictions on Length
Restrictions for Datatypes
You can create an XML schema and reuse it in other schemas with
the help of the <xs:import> element.
SAX stands for Simple API for XML.
SAX provides an alternative way to DOM for interpreting the XML
file.
© People Strategists www.peoplestrategists.com Slide 64 of 64
Summary (Contd.)
The XML DOM is used to represent an XML document as a tree like
structure.
The DOM tree represents a hierarchical relationship between the
nodes of the tree.

More Related Content

What's hot

Dtd
DtdDtd
XSLT
XSLTXSLT
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
Manish Chaurasia
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Soa unit-1-well formed and valid document08.07.2019
Soa unit-1-well formed and valid document08.07.2019Soa unit-1-well formed and valid document08.07.2019
Soa unit-1-well formed and valid document08.07.2019
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
Xml Presentation-3
Xml Presentation-3Xml Presentation-3
Xml Presentation-3Sudharsan S
 
Xml namespace
Xml namespaceXml namespace
Xml namespace
GayathriS578276
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
Ravinder Kamboj
 
presentation in html,css,javascript
presentation in html,css,javascriptpresentation in html,css,javascript
presentation in html,css,javascript
FaysalAhammed5
 
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introductionapnwebdev
 
Xml ppt
Xml pptXml ppt
Xml ppt
seemadav1
 
XML
XMLXML
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
Gtu Booker
 
Xml schema
Xml schemaXml schema
Xml schema
Prabhakaran V M
 
Xml schema
Xml schemaXml schema
Xml schema
Dr.Saranya K.G
 
Document object model
Document object modelDocument object model
Document object model
Amit kumar
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
Json
JsonJson

What's hot (20)

Dtd
DtdDtd
Dtd
 
XSLT
XSLTXSLT
XSLT
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Soa unit-1-well formed and valid document08.07.2019
Soa unit-1-well formed and valid document08.07.2019Soa unit-1-well formed and valid document08.07.2019
Soa unit-1-well formed and valid document08.07.2019
 
XML
XMLXML
XML
 
Xml Presentation-3
Xml Presentation-3Xml Presentation-3
Xml Presentation-3
 
Xml namespace
Xml namespaceXml namespace
Xml namespace
 
Lesson 2 php data types
Lesson 2   php data typesLesson 2   php data types
Lesson 2 php data types
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
presentation in html,css,javascript
presentation in html,css,javascriptpresentation in html,css,javascript
presentation in html,css,javascript
 
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introduction
 
Xml ppt
Xml pptXml ppt
Xml ppt
 
XML
XMLXML
XML
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml schema
Xml schemaXml schema
Xml schema
 
Document object model
Document object modelDocument object model
Document object model
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Json
JsonJson
Json
 

Similar to XML Schemas

XML Fundamentals
XML FundamentalsXML Fundamentals
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12
RohanMistry15
 
XML_schema_Structure
XML_schema_StructureXML_schema_Structure
XML_schema_Structure
Vijay Kumar Verma
 
Xsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtmlXsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtml
AMIT VIRAMGAMI
 
Mazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml ToolsMazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml Tools
CardinaleWay Mazda
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
Roselin Mary S
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
David Ionut
 
Generation_XSD_Article - Part 4.pdf
Generation_XSD_Article - Part 4.pdfGeneration_XSD_Article - Part 4.pdf
Generation_XSD_Article - Part 4.pdf
David Harrison
 
Xsd tutorial
Xsd tutorialXsd tutorial
Xsd tutorial
Ashoka Vanjare
 
Euclid Data Model 101 - Episode 01: Overview
Euclid Data Model 101 - Episode 01: OverviewEuclid Data Model 101 - Episode 01: Overview
Euclid Data Model 101 - Episode 01: Overview
euc-dm-test
 
XSD Incomplete Overview Draft
XSD Incomplete Overview DraftXSD Incomplete Overview Draft
XSD Incomplete Overview Draft
Pedro De Almeida
 
SchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdfSchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdf
David Harrison
 
Java 17
Java 17Java 17
Java 17
Mutlu Okuducu
 
CTDA Workshop on XML and MODS
CTDA Workshop on XML and MODSCTDA Workshop on XML and MODS
CTDA Workshop on XML and MODS
University of Connecticut Libraries
 

Similar to XML Schemas (20)

Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 
XML Fundamentals
XML FundamentalsXML Fundamentals
XML Fundamentals
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12
 
XML_schema_Structure
XML_schema_StructureXML_schema_Structure
XML_schema_Structure
 
Xsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtmlXsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtml
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
Mazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml ToolsMazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml Tools
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
 
Generation_XSD_Article - Part 4.pdf
Generation_XSD_Article - Part 4.pdfGeneration_XSD_Article - Part 4.pdf
Generation_XSD_Article - Part 4.pdf
 
Xsd tutorial
Xsd tutorialXsd tutorial
Xsd tutorial
 
XML
XMLXML
XML
 
Euclid Data Model 101 - Episode 01: Overview
Euclid Data Model 101 - Episode 01: OverviewEuclid Data Model 101 - Episode 01: Overview
Euclid Data Model 101 - Episode 01: Overview
 
XSD Incomplete Overview Draft
XSD Incomplete Overview DraftXSD Incomplete Overview Draft
XSD Incomplete Overview Draft
 
SchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdfSchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdf
 
Java 17
Java 17Java 17
Java 17
 
CTDA Workshop on XML and MODS
CTDA Workshop on XML and MODSCTDA Workshop on XML and MODS
CTDA Workshop on XML and MODS
 

More from People Strategists

Overview of web services
Overview of web servicesOverview of web services
Overview of web services
People Strategists
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
People Strategists
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
People Strategists
 
Identifing Listeners and Filters
Identifing Listeners and FiltersIdentifing Listeners and Filters
Identifing Listeners and Filters
People Strategists
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
People Strategists
 
JSP Technology II
JSP Technology IIJSP Technology II
JSP Technology II
People Strategists
 

More from People Strategists (20)

MongoDB Session 3
MongoDB Session 3MongoDB Session 3
MongoDB Session 3
 
MongoDB Session 2
MongoDB Session 2MongoDB Session 2
MongoDB Session 2
 
MongoDB Session 1
MongoDB Session 1MongoDB Session 1
MongoDB Session 1
 
Android - Day 1
Android - Day 1Android - Day 1
Android - Day 1
 
Android - Day 2
Android - Day 2Android - Day 2
Android - Day 2
 
Overview of web services
Overview of web servicesOverview of web services
Overview of web services
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
Spring Framework -I
Spring Framework -ISpring Framework -I
Spring Framework -I
 
Hibernate II
Hibernate IIHibernate II
Hibernate II
 
Hibernate III
Hibernate IIIHibernate III
Hibernate III
 
Hibernate I
Hibernate IHibernate I
Hibernate I
 
Identifing Listeners and Filters
Identifing Listeners and FiltersIdentifing Listeners and Filters
Identifing Listeners and Filters
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
 
Agile Dev. II
Agile Dev. IIAgile Dev. II
Agile Dev. II
 
Agile Dev. I
Agile Dev. IAgile Dev. I
Agile Dev. I
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
 
JSP Technology II
JSP Technology IIJSP Technology II
JSP Technology II
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 

Recently uploaded

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

XML Schemas

  • 1. © People Strategists www.peoplestrategists.com Slide 1 of 64 XML Schemas
  • 2. © People Strategists www.peoplestrategists.com Slide 2 of 64 Objectives In this session, you will learn to: Explain the concept of XML schema Identify the advantages of XML schema over DTDs Define XML schema elements Create simple and complex type elements Use of compositors with XML schema elements Apply restrictions on simple type elements Extend complex type elements Creating reusable types and schemas Explain the concept of SAX Explain the concept of DOM
  • 3. © People Strategists www.peoplestrategists.com Slide 3 of 64 Introduction to XML Schema How can I get rid of large DTDs that are hard to read and maintain?
  • 4. © People Strategists www.peoplestrategists.com Slide 4 of 64 Introduction to XML Schema (Contd.)
  • 5. © People Strategists www.peoplestrategists.com Slide 5 of 64 Introduction to XML Schema (Contd.)
  • 6. © People Strategists www.peoplestrategists.com Slide 6 of 64 Introduction to XML Schema (Contd.) Let us create an XML schema file, employee.xsd, for an XML file, employee.xml, and add the reference of schema file in the XML file. <?xml version="1.0" encoding="utf-8"?> <employee xmlns="mynamespace" xmlns:xsi=http://www.w3.org/2001/ XMLSchema-instance xsi:schemaLocation="mynamespace employee.xsd"> <firstname>John</firstname> <lastname>Smith</lastname> </employee> <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="mynamespace" elementFormDefault="qualified" xmlns="mynamespace employee.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> employee.xsd employee.xml
  • 7. © People Strategists www.peoplestrategists.com Slide 7 of 64 Introduction to XML Schema (Contd.) The <schema> element is the root element of every XML Schema and contains some attributes. The targetNamespace attribute defines the namespace of the XML file that has to be validated. The elementFormDefault attribute defines whether its local elements must be qualified or unqualified in an XML document. The xmlns attribute specifies the default namespace. The attribute xmlns:xs specifies the namespace of the elements and datatypes used in the schema. <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="<target_namespace>" elementFormDefault="<qualified/unqualified>" xmlns="<default_namespace>" xmlns:xs="http://www.w3.org/2001/XMLSchema"> ................. ................. </xs:schema>
  • 8. © People Strategists www.peoplestrategists.com Slide 8 of 64 Introduction to XML Schema (Contd.) You can add reference of an XML schema in an XML file by using attributes, as shown in the following code snippet: The xmlns attribute defines the namespace of the elements declared in the XML file. The xmlns:xsi attribute specifies the instance of the schema that is used for the XML document. The xsi:schemaLocation attribute specifies the location of the schema. <?xml version="1.0"?> <emp xmlns="default_namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xsi:schemaLocation="<namespace> <schema_file>" .............. .............. </emp>
  • 9. © People Strategists www.peoplestrategists.com Slide 9 of 64 Advantages Over DTD What are the advantages of using XML schema over DTD?
  • 10. © People Strategists www.peoplestrategists.com Slide 10 of 64 Advantages Over DTD (Contd.) XML schemas follow a universal standard that made data communication over the Internet safe. For example, a date like: "01-07-2015" can be interpreted as 7 January in some countries, whereas in other countries as 1 July. However, an XML element accepts date in the fixed format "YYYY- MM-DD" to ensure its correct interpretation. XML schemas support data types that allow programmers to: Specify the acceptable content in the document Ensure the validity of data Work with databases Apply restrictions on data Specify data formats Convert data from one data type to another
  • 11. © People Strategists www.peoplestrategists.com Slide 11 of 64 Advantages Over DTD (Contd.) You can define number and order of child elements using XML schemas, but not with DTDs. XML schemas support namespaces, whereas DTDs do not support namespaces. XML schemas can be also extended, therefore, you can: Reuse an XML schema in other schemas. Drive your own data types from the standard types. Add the reference of multiple schemas in a single XML document.
  • 12. © People Strategists www.peoplestrategists.com Slide 12 of 64 Defining Elements How can I define an element in an XML schema?
  • 13. © People Strategists www.peoplestrategists.com Slide 13 of 64 Defining Elements (Contd.) XML schemas define the elements of XML files. You can use the XML syntax to define elements in an XML schema file. To define an element, you can use the following syntax: The following code snippet depicts some examples of defining elements: <xs:element name="<element_name>" type="data_name"/> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="dob" type="xs:date"/> <xs:element name= "age" type="xs:numeric"/>
  • 14. © People Strategists www.peoplestrategists.com Slide 14 of 64 Simple and Complex Types You can define two types of elements in XML schemas. These are: Element Types Simple Complex
  • 15. © People Strategists www.peoplestrategists.com Slide 15 of 64 Simple and Complex Types (Contd.) Simple Type: Is an XML element that contains only text. Cannot contain other elements or attributes. To define a simple type element, you can use the following syntax: Some common built-in data types that XML schema supports are: xs:string xs:decimal xs:integer xs:boolean xs:date xs:time <xs:element name="<element_name>" type="data_name"/>
  • 16. © People Strategists www.peoplestrategists.com Slide 16 of 64 Simple and Complex Types (Contd.) You can also specify default or fixed value for a simple element. The default value is implicitly assigned to the element if a specific value is not provided. The following code snippet shows an example of specifying default value for an element: If you specify a fixed value for an element, you cannot provide another value for that element in your XML document. The specified value is automatically assigned to the element. <xs:element name="city" type="xs:string" default="New York"/> <xs:element name="city" type="xs:string" fixed="New York"/>
  • 17. © People Strategists www.peoplestrategists.com Slide 17 of 64 XSD Attributes: Are used to provide additional information about an element. Are defined with name and type properties in an XSD document. The syntax of defining an attribute is shown as follows: The following code snippet shows an example of defining an attribute: Simple and Complex Types (Contd.) <xs:attribute name="<attribute_name>" type="<data_type>" use="<type_of_use>"/> <xs:attribute name="ID" type="xs:string" use="required"/>
  • 18. © People Strategists www.peoplestrategists.com Slide 18 of 64 Simple and Complex Types (Contd.) Complex Type: Elements include other elements and/or attributes. For example, to define a complex type, person name, with two other elements, first name and last name, you can use the following code snippet: <xs:element name="person_name"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
  • 19. © People Strategists www.peoplestrategists.com Slide 19 of 64 Simple and Complex Types (Contd.) You can also create a complex type and reuse it in several other complex element, as shown in the following code snippet: <xs:element name="student" type="person_name"/> <xs:element name="employee" type="person_name"/> <xs:complexType name="person_name"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType>
  • 20. © People Strategists www.peoplestrategists.com Slide 20 of 64 Simple and Complex Types (Contd.) Complex type elements are of the following types: ComplexType Empty Elements Elements Only Text Only Mixed
  • 21. © People Strategists www.peoplestrategists.com Slide 21 of 64 Simple and Complex Types (Contd.) Empty Elements: Can only have attributes, but not text. For example, you want to define a complex type empty element, employee, with an attribute, emp id as an integer value, you can use the following code snippet: <xs:element name="employee"> <xs:complexType> <xs:attribute name="empid" type="xs:positiveInteger"/> </xs:complexType> </xs:element>
  • 22. © People Strategists www.peoplestrategists.com Slide 22 of 64 Simple and Complex Types (Contd.) Elements Only: Can contain other elements only. For example, you want to define a complex type, employee name, with two other elements, first name and last name, you can use the following code snippet: In the preceding code snippet, the <xs:sequence> tag specifies that the first name and last name elements must appear in the given order inside the employee_name element. <xs:element name="employee_name"> <xs:complexType><xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence></xs:complexType> </xs:element>
  • 23. © People Strategists www.peoplestrategists.com Slide 23 of 64 Simple and Complex Types (Contd.) Text Only: Can only contain text and attributes. The simpleContent element must be defined to specify the content for the element. An extension or a restriction element must be used within the simpleContent element to expand or to limit the content of the element. <xs:element name="contact_number"> <xs:complexType><xs:simpleContent> <xs:extension base="xs:integer"> <xs:attribute name="country" type="xs:string" /> </xs:extension> </xs:simpleContent></xs:complexType> </xs:element>
  • 24. © People Strategists www.peoplestrategists.com Slide 24 of 64 Simple and Complex Types (Contd.) Mixed: Can contain attributes, elements, and text. is defined by setting the mixed attribute to "true" inside the complexType element. <xs:element name="order"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="pname" type="xs:string"/> <xs:element name="orderid" type="xs:positiveInteger"/> <xs:element name="orderdate" type="xs:date"/> </xs:sequence> </xs:complexType> </xs:element>
  • 25. © People Strategists www.peoplestrategists.com Slide 25 of 64 Use of Compositors What are compositors?
  • 26. © People Strategists www.peoplestrategists.com Slide 26 of 64 Use of Compositors (Contd.) Compositors are one of the widely used XSD standards that specify the XML document structure. You can use compositors to describe the composition of child elements within a parent element in an XML document. They are generally used with complex type element. They are used to control the use of elements in an XML document. When compositors are used appropriately, they offer comprehensive and robust data models.
  • 27. © People Strategists www.peoplestrategists.com Slide 27 of 64 Use of Compositors (Contd.) There are seven major compositors in XML, which are divided into three categories. Compositors Order All Choice Sequence Occurrence Min Occurs Max Occurs Group Element Attribute
  • 28. © People Strategists www.peoplestrategists.com Slide 28 of 64 Use of Compositors (Contd.) Order Compositors: Are used to used to define the order of the elements. The <all> compositor specifies that the child elements of an element can appear in any order, and each child element must appear only once. <xs:element name="person_name"> <xs:complexType> <xs:all> <xs:element name="firstname“ type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:all> </xs:complexType> </xs:element>
  • 29. © People Strategists www.peoplestrategists.com Slide 29 of 64 Use of Compositors (Contd.) You can use the <choice> compositor to specify that either one child element or another can occur. <xs:element name="person_name"> <xs:complexType> <xs:choice> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:choice> </xs:complexType> </xs:element>
  • 30. © People Strategists www.peoplestrategists.com Slide 30 of 64 Use of Compositors (Contd.) The <sequence> compositor is used to specify that the child elements must appear in the given order. <xs:element name="person_name"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
  • 31. © People Strategists www.peoplestrategists.com Slide 31 of 64 Use of Compositors (Contd.) Occurrence Compositors: Specify the maximum or minimum number of occurrences of an element in an document. You can use the using the <maxOccurs> compositor to specify the maximum number of occurrences of an element. <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="full_name" type="xs:string"/> <xs:element name="contact_number" type="xs:integer" maxOccurs="3"/> </xs:sequence> </xs:complexType> </xs:element>
  • 32. © People Strategists www.peoplestrategists.com Slide 32 of 64 Use of Compositors (Contd.) You can specify the minimum number of occurrences of an element in an document using the <minOccurs> compositor. You can also specify that an element can occur any number of times by specifying maxOccurs="unbounded" . <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="full_name" type="xs:string"/> <xs:element name="contact_number" type="xs:integer" maxOccurs="3" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element>
  • 33. © People Strategists www.peoplestrategists.com Slide 33 of 64 Use of Compositors (Contd.) Group Compositors: Are use to specify the related sets of elements. You can define an element group and refer it in another XML schema, as shown in the following code snippet. <xs:group name="empgroup"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="doj" type="xs:date"/> </xs:sequence></xs:group> <xs:element name="emp" type="empinfo"/> <xs:complexTypename="empinfo"> <xs:sequence> <xs:group ref="empgroup"/> <xs:element name="city" type="xs:string"/> </xs:sequence></xs:complexType> Group Definition Group Reference
  • 34. © People Strategists www.peoplestrategists.com Slide 34 of 64 Use of Compositors (Contd.) You can define an attribute group and refer it in another XML schema, as shown in the following code snippet. <xs:attributeGroup name="empattrgroup"> <xs:attribute name="firstname" type="xs:string"/> <xs:attribute name="lastname" type="xs:string"/> <xs:attribute name="doj" type="xs:date"/> </xs:attributeGroup> <xs:element name="employee"> <xs:complexType> <xs:attributeGroup ref="empattrgroup"/> </xs:complexType> </xs:element> Group Definition Group Reference
  • 35. © People Strategists www.peoplestrategists.com Slide 35 of 64 Restriction on Simple Types
  • 36. © People Strategists www.peoplestrategists.com Slide 36 of 64 Restriction on Simple Types (Contd.) You can apply restrictions on simple element types to specify the acceptable values of XML elements or attributes. In XML, restrictions on XML elements are known as facets. TypesofRestrictions Restrictions on Values Restrictions on a Set of Values Restrictions on a Series of Values Restrictions on Whitespace Characters Restrictions on Length Restrictions for Data types
  • 37. © People Strategists www.peoplestrategists.com Slide 37 of 64 Restriction on Simple Types (Contd.) Restrictions on Values: You can apply restriction on the value of an element. For example, the age of an employee cannot be less than 21 and greater 60. <xs:element name="emp_age"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="21"/> <xs:maxInclusive value="60"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 38. © People Strategists www.peoplestrategists.com Slide 38 of 64 Restriction on Simple Types (Contd.) Restrictions on a Set of Values: You can apply restriction on an XML element such that the element can only accept a value from a set of specified values. For example, you can specify a job role element that can only accept one of the values: Sales, Management, and Operations. <xs:element name="job_role"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Sales"/> <xs:enumeration value="Management"/> <xs:enumeration value="Operations"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 39. © People Strategists www.peoplestrategists.com Slide 39 of 64 Restriction on Simple Types (Contd.) Restrictions on a Series of Values: You can apply restrictions on a series of numbers or letters that can be used by using the pattern constraint. For example, you define the contact element that can accept only 10 digit values such that the first digit should not be 0, and other digits must be from 0 to 9. <xs:element name="contact"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:pattern value="[1-9][0-9][0-9][0-9] [0-9][0-9][0 9][0-9][0-9][0-9]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 40. © People Strategists www.peoplestrategists.com Slide 40 of 64 Restriction on Simple Types (Contd.) Similarly, you can also apply restrictions on character values. For example, you can define an element, lcase that can only accept a lowercase letter from a-z. <xs:element name="lcase"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-z]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 41. © People Strategists www.peoplestrategists.com Slide 41 of 64 Restriction on Simple Types (Contd.) For example, you define an element password that can accept exactly 10 characters in a row and those characters can be lowercase or uppercase letters from a to z or a number from 0 to 9: <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-zA-Z0-9]{8}"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 42. © People Strategists www.peoplestrategists.com Slide 42 of 64 Restriction on Simple Types (Contd.) Restrictions on Whitespace Characters: You can specify how whitespaces are treated for an element by using the whiteSpace constraint. The whiteSpace constraint may accept one of the following values:  preserve: Leaves all the whitespace characters as they are.  replace: Replaces all the whitespace characters with spaces.  Collapse: Replaces line feeds, tabs, spaces, carriage returns are with spaces and multiple spaces with a single space and removes leading and trailing spaces.
  • 43. © People Strategists www.peoplestrategists.com Slide 43 of 64 Restriction on Simple Types (Contd.) For example, if you want to define a full_name element such that the whitespaces are not removed by the XML processor, you can use the following code snippet: <xs:element name="full_name"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:whiteSpace value="preserve"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 44. © People Strategists www.peoplestrategists.com Slide 44 of 64 Restriction on Simple Types (Contd.) Restrictions on Length: You can limit the length of the value of an element by using the maxLength and minLength constraints. For example, you want to define an element, password, that have minimum 6 letters and maximum 14 letters, you can use the following code snippet: <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="6"/> <xs:maxLength value="14"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 45. © People Strategists www.peoplestrategists.com Slide 45 of 64 Restriction on Simple Types (Contd.) Restrictions on Data Types: Some of the common restrictions that you can apply on data types are listed in the following table. Constraints Description enumeration Specifies a set of acceptable values. fractionDigits Specifies the maximum number of decimal digits, must be equal to or greater than 0. length Specifies the length of the value of an element. maxExclusive Specifies the upper bound of a numeric value that must be less than the specified value. maxInclusive Specifies the upper bound of a numeric value that must be less than or equal to the specified value. maxLength Specifies the maximum number of allowed characters. minExclusive Specifies the lower bounds of a numeric value that must be greater than the specified value.
  • 46. © People Strategists www.peoplestrategists.com Slide 46 of 64 Restriction on Simple Types (Contd.) Constraints Description minInclusive Specifies the lower bounds of a numeric value that must be greater than or equal to the specified value. minLength Specifies the minimum number of allowed characters. pattern Specifies a sequence of characters that are allowed. totalDigits Specifies the number of allowed digits. whiteSpace Specifies how to treat whitespaces.
  • 47. © People Strategists www.peoplestrategists.com Slide 47 of 64 Extending Complex Types You can take an existing entity and add more specific information to it as per your requirement. In programming languages, this concept is known as inheritance or sub classing. Inheritance or sub classing saves development time and effort. The same concept is also applied in XSD standard. You can take an existing complex type element and extend it to add more information.
  • 48. © People Strategists www.peoplestrategists.com Slide 48 of 64 Extending Complex Types (Contd.) Consider that you have a complex element personal_info defined as follows: <xs:element name="personal_info"> <xs:complexType> <xs:sequence> <xs:element name="first_name" type="xs:string"/> <xs:element name="last_name" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
  • 49. © People Strategists www.peoplestrategists.com Slide 49 of 64 Extending Complex Types (Contd.) Now, you want to define two more elements, home_address and office_address. The addresses also contain the first name and last name of the person. Instead of defining the first name and last name elements inside the home_address and office_address elements, you can extend the personal_info element to reuse the existing information by using the <xs:extension> element. You can define home_address by extending personal_info, as: <xs:complexType name="home_address"> <xs:complexContent> <xs:extension base="personal_info"> <xs:sequence> <xs:element name="line1" type="xs:string"/> <xs:element name="line2" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> home_address Element
  • 50. © People Strategists www.peoplestrategists.com Slide 50 of 64 Extending Complex Types (Contd.) Similarly, you can define the office_address element as: <xs:complexType name="home_address"> <xs:complexContent> <xs:extension base="personal_info"> <xs:sequence> <xs:element name="line1" type="xs:string"/> <xs:element name="line2" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> office_address Element
  • 51. © People Strategists www.peoplestrategists.com Slide 51 of 64 Extending Complex Types (Contd.) If you want to use only some specific elements from a complex type element, you can use the <xs:restriction> element. For example, you want to create a new element first_name, you can restrict the personal_info type by using the <xs:restriction> element, as: <xs:complexType name="first_name"> <xs:complexContent> <xs:restriction base="personal_info"> <xs:sequence> <xs:element name="first_name" type="xs:string" /> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> first_name Element
  • 52. © People Strategists www.peoplestrategists.com Slide 52 of 64 Creating Reusable Types Can I create an XML schema and reuse it in other XML schemas?
  • 53. © People Strategists www.peoplestrategists.com Slide 53 of 64 Creating Reusable Types (Contd.) If you want to create some elements that can be reused on multiple files in your project, you should define these elements in a separate XML schema, and refer it in other schemas whenever required. You can create an XML schema and reuse it in other schemas with the help of the <xs:import> element. For example, suppose, you have an XML schema, info.xsd that defines the first name and last name of a person. Now, you want to create a new schema, empinfo.xsd that also contains the first name and last name of the person. In this case, you can provide the reference of the info.xsd schema in the empinfo.xsd and reuse the elements defined in the info.xsd schema.
  • 54. © People Strategists www.peoplestrategists.com Slide 54 of 64 Creating Reusable Types (Contd.) The following code snippet shows the XML markup of info.xsd schema: You can reuse this schema in another schema with the help of <xs:import> element. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.org/person" targetNamespace="http://example.org/person"> <xsd:complexType name="personal_info"> <xsd:sequence> <xsd:element name="first_name" type="xsd:string"/> <xsd:element name="last_name" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema> info.xsd
  • 55. © People Strategists www.peoplestrategists.com Slide 55 of 64 Creating Reusable Types (Contd.) The following code snippet shows the XML markup of empinfo.xsd schema: <xs:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:basetns="http://example.org/person" xmlns:tns="http://example.org/person/derived" targetNamespace="http://example.org/person/derived"> <xs:import namespace="http://example.org/person" schemaLocation="info.xsd"/> <xs:complexType name="empInfo"> <xs:complexContent> <xs:extension base="basetns:personal_info"> <xs:sequence> <xs:element name="contact_num" type="xs:numeric"/> <xs:element name="doj" type="xs:date"/> <xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> </xs:schema> empinfo.xsd
  • 56. © People Strategists www.peoplestrategists.com Slide 56 of 64 Identifying SAX SAX stands for Simple API for XML. It is an Application Programming Interface (API) to interpret XML-based Web files or the Web files that use XML. The API interprets the XML markup and describe the collection of data. SAX provides an alternative way to DOM for interpreting the XML file. It is a simpler interface in comparison to DOM and does not require in-memory resource for processing.
  • 57. © People Strategists www.peoplestrategists.com Slide 57 of 64 SAX (Contd.) It is used where large number of files need to be processed. You can use SAX to search small pieces of information in a large document and abort processing when the information is found. SAX is also capable to build DOM trees. Developers can also traverse DOM trees to create SAX streams as well.
  • 58. © People Strategists www.peoplestrategists.com Slide 58 of 64 DOM The XML DOM is used to represent an XML document as a tree like structure. The DOM tree is called as the node-tree. The DOM tree represents a hierarchical relationship between the nodes of the tree. The tree starts with the root node branches out to the text node to the lowest level of the tree. Each node of the tree can be accessed from the tree. The content of the tree can be modified or deleted. A new element can be also inserted in a DOM tree.
  • 59. © People Strategists www.peoplestrategists.com Slide 59 of 64 DOM (Contd.) The parent, children, and sibling terms are used to specify relationships between nodes in a DOM tree. A parent node have children. Nodes that are at the same level are known as siblings. The top node is known as the root node. Each DOM tree has only one root node. Each node except root node has a parent node. A parent node can have any number of children. A node that has no children is known as leaf node. Nodes that have the same parent are known as siblings.
  • 60. © People Strategists www.peoplestrategists.com Slide 60 of 64 Text: ASP.NET Text: Benson Text: Kelly Bond Text: XML Root Node Sibling Nodes Data Parent-Child Relationship DOM (Contd.) A sample XML DOM tree is shown as follows. Book Book 1 AuthorTitle Book 2 Title Author
  • 61. © People Strategists www.peoplestrategists.com Slide 61 of 64 Summary XML schema, similar to DTDs, describes and validates the structure of an XML document. XML schemas are written in XML itself. The targetNamespace attribute defines the namespace of the XML file that has to be validated. The attribute xmlns:xs specifies the namespace of the elements and datatypes used in the schema. XML schemas support data types that allow users to: Specify the acceptable content in the document Ensure the validity of data Work with databases Apply restrictions on data Specify data formats Convert data from one data type to another
  • 62. © People Strategists www.peoplestrategists.com Slide 62 of 64 Summary (Contd.) XML schemas can be also extended, therefore, you can: Reuse an XML schema in other schemas. Drive your own data types from the standard types. Add the reference of multiple schemas in a single XML document. You can define two types of elements in XML schemas. These are: Simple Type Complex Type You can use XSDs to specify the structure of markup in an XML document at different levels. Compositors are one of the widely used XSD standards that specify the XML document structure. When compositors are used appropriately, they offer comprehensive and robust data models.
  • 63. © People Strategists www.peoplestrategists.com Slide 63 of 64 Summary (Contd.) In XML, restrictions on XML elements are known as facets. Types of restrictions are: Restrictions on Values Restrictions on a Set of Values Restrictions on a Series of Values Restrictions on Whitespace Characters Restrictions on Length Restrictions for Datatypes You can create an XML schema and reuse it in other schemas with the help of the <xs:import> element. SAX stands for Simple API for XML. SAX provides an alternative way to DOM for interpreting the XML file.
  • 64. © People Strategists www.peoplestrategists.com Slide 64 of 64 Summary (Contd.) The XML DOM is used to represent an XML document as a tree like structure. The DOM tree represents a hierarchical relationship between the nodes of the tree.