Schema Structure
by: Vijay Kumar Verma (VJY)
Objective
Schema
Component of Schema
What is Xml Schema?
α “A structured framework or plan”.
α XML Schema was originally proposed by
Microsoft, but became an official W3C
recommendation in May 2001.
α “XML Schemas,” we usually mean the W3C
XML Schema Language.
α Also known as “XML Schema Definition”
language, or XSD.
What is Xml Schema? (continue)
α An XML schema language is a formalization of
the constraints, expressed as rules or a model
of structure, that apply to a class of XML
documents. It validate the XML document.
α XML Schema documents (ie: XSD) are used to
define and validate the content and structure
of XML data.
Why XMLSchema?
Information
Structure
Format
Traditional Document:
Everything is clumped
together
Information
Structure
Format
“Fashionable” Document: A document
is broken into discrete parts, which can
be treated separately
XMLSchema Syntax
α XML schema use xml syntax for there
declaration of schema, unlike DTD syntax
<!ELEMENT first (#PCDATA)>
α Same in XSD is defined using
<element name="first" type="string"/>
Schema Components
Schema Elements
Element Definition
Attribute Definition
Annotations
Type Definition
SCHEMA ELEMENTS
α <schema> is the root element.
α It contain namespace to add the xml
schema vocabularies.
α Syntax
<schema targetNamespace=”URI”
attributeFormDefault=“qualified or unqualified”
elementFormDefault=“qualified or unqualified”
version=”version number”>
α Example:
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
ELEMENT DEFINITION
α Basic building block of our XML files.
α Syntax for Schema Element:
<xs:element name=“element-name”
type=“data-type”
default|fixed=“value” />
α Example
<xs:element name=“name” type=“xs:string”/>
<xs:element name=“Colour” type=“xs:string” default=“red” />
α Global Declaration
α Local Declarattion
EXAMPLE
<?xml version=“1.0”?>
<schema xmlns=“http://www.w3.org/2001/XMLSchema”
xmlns:target=“http://www.example.com/name”
targetNamespace=“http://www.example.com/name”
elementFormDefault=“qualified”>
<element name=“name”>
<complexType>
<sequence>
<element name=“first” type=“string”/>
<element name=“middle” type=“string”/>
<element name=“last” type=“string”/>
</sequence>
<attribute name=“title” type=“string”/>
</complexType>
</element>
</schema>
ATTRIBUTE DEFINITATION
α Simple element have not attribute, if
yes, are considered as complex type.
α Syntax for attribute definition:
<xs:attribute name=“attribute-name”
type=“data-type”
default|fixed=“value”
use=“optional|required”/>
α Example
Xml file <lastname lang="EN">Smith</lastname>
In Schma <xs:attribute name="lang" type="xs:string" />
ANNOTATIONS
α An annotation is information for human
and/or mechanical consumers. The
interpretation of such information is not
defined in this specification.
α These are metadata.
α Annotation Syntax:
<xs:annotation>
<xs:documentation>…</xs:documentation>
<xs:appinfo>…</xs:appinfo>
</xs:annotation>
α Here appinfo for mechine and
documentation for user.
ANNOTATION EXAMPLE
<annotation>
<appinfo source=”name-sample.xml”/>
<documentation xml:lang=”en”>
The name vocabulary was created
for an example of a DTD. We have
recycled it into an XML Schema.
</documentation>
</annotation>
TYPE DEFINITION
α XML schema have Many built-in Data types
α Facility to create User define data types.
α All type declaration classified in
 Simple Type
 Complex Type
SIMPLE TYPE
<xs:element name=“price”>
<xs:simpleType>
<xs:restriction base=“xs:string”>
<xs:pattern
value=”$[0-9]{1,4}.[0-9]{2}”/>
</xs:restriction>
</xs:simpleType>
</xs:element>
COMPLEX TYPE
<xs:element name=”bookInfo”>
<xs:complexType>
<xs:sequence>
<xs:element ref=”title”/>
<xs:element ref=”author”/>
<xs:element ref=”publisher”/>
<xs:element ref=”isbn”/>
</xs:sequence>
</xs:complexType>
</xs:element>
XML_schema_Structure
XML_schema_Structure

XML_schema_Structure