XML : eXtensible Markup Language :: Introduction to XML Schema
- Introduction to Schema
- Need for Schema
- Benefits of XML Schema
- Limitations of DTDs
- Schema Data Types
- Schema Elements
- Download Examples
Introduction to Schema |
Dictionary Meaning:
A diagrammatic representation; an outline or a model.
In Software Context :
A model used to describe the structure of a database. Defines internal structures such as tables, fields and the relationship between them.
In XML Context :
A set of rules to constrain the structure and articulate the information set of XML documents.
Need for Schema |
- XML schema is a technology created by Microsoft that implements a subset of a W3C note
- Improves upon many weaknesses of DTDs such as the cryptic syntax, the lack of data typing, the closed content model, and the lack of support for namespaces
- Supports a wide range of data types such as integers, floating point numbers, dates and times
- Includes support for other features, such as an open content model and namespace integration
Benefits of XML Schema |
- Created using XML syntax, so, the processing of XML Schemas and XML Instances by the same software tool is possible.
- Less expenditure for the data management and data administration results in overall low programming expenditure.
- As XML Schemas were finalized after the Namespace Recommendation, the concept of namespaces was available to be included in the design. Thus, XML Schemas enables to define vocabularies that utilize namespace declarations.
- XML Schemas allow you to validate text element content based on built-in and user-defined data types.
- XML Schemas allows to easily create complex and reusable content models.
- XML Schemas allows to model concepts such as object inheritance and type substitution.
-
XML Schemas are Extensible
- Reuse your Schema in other Schemas
- Create your own data types derived from the standard types
- Reference multiple schemas in the same document
Limitations of DTDs |
Limitations of DTDs
- DTDs are written in a non-XML syntax
- DTDs are not extensible
- Do not support namespaces
- Only offer extremely limited datatyping
Schemas overcome these limitations and allow Web applications to exchange XML data more robustly, without relying on adhoc validation tools.
- XML Schemas are extensible to future additions
- XML Schemas are richer and more powerful than DTDs
- XML Schemas are written in XML
- XML Schemas support data types
- XML Schemas support namespaces
- XML Schema is a W3C Standard
- XML Schema became a W3C Recommendation on 02. May 2001.
Schema Data Types |
DataTypes Supported by Schema | |||
---|---|---|---|
ID | ENTITY | NMTOKEN | boolean |
IDREF | ENTITIES | NMTOKENS | number |
IDREFS | NOTATION | string | binary |
dateTime | uri |
Additional data types are generated from the basic built-in data types, which are called basetype data types
Base type Data Types |
---|
integer |
decimal |
real |
time |
timePeriod |
Schema Elements |
The <schema> Element
The <schema> element is the root element for every XML Schema:
<?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
Example
Attribute
Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type
Syntax
<xsd:attribute name="aaa" type="bbb"/>
Here aaa is the name of the attribute and bbb specifies the data type of the attribute.
XML Schema has a lot of built-in data types. Some common types are:
- xsd:string
- xsd:decimal
- xsd:integer
- xsd:boolean
- xsd:date
- xsd:time
Example
<authorname lang="HND">Tom</authorname>
here is the attribute definition:
<xs:attribute name="lang" type="xs:string"/>
Download Examples |
Recent Comments