XML Schema
- Previous Page XML DTD
- Next Page XML Server
XML Schema Describes the structure of an XML document, similar to DTD.
A grammar-correct XML document is called 'well-formed'.
An XML document validated by XML Schema is both 'well-formed' and 'valid'.
XML Schema
XML Schema is based on XML and is an alternative to DTD:
<xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
The following is an explanation of the Schema above:
The <xs:element name="note"> defines an element named "note" The element "note" is a complex type The complex type is a sequence of elements The element "to" with the type "xs:string" is defined as a text type (text) The element "from" with the type "xs:string" is defined by the <xs:element name="from" type="xs:string"> element The element "heading" with the type "xs:string" is defined by the <xs:element name="heading" type="xs:string"> element The element "body" with the type "xs:string" is defined by the <xs:element name="body" type="xs:string"> element
XML Schema is more powerful than DTD
- XML Schema is written in XML
- XML Schema is extensible
- XML Schema supports data types
- XML Schema supports namespaces
Why use XML Schema?
With XML Schema, your XML files can carry descriptions of their own formats.
With XML Schema, independent groups can reach an agreement on the standards for data exchange.
With XML Schema, you can validate data.
XML Schema supports data types
One of the major advantages of XML Schema is its support for data types:
- It is easier to describe the content of documents
- It is easier to define data constraints
- It is easier to verify the correctness of data
- It is easier to convert data of different data types
XML Schema uses XML syntax
One of the powerful advantages of XML Schema is that it is written in XML:
- You do not need to learn a new language
- You can use an XML editor to edit the Schema file
- You can use an XML parser to parse the Schema file
- You can use XML DOM to manipulate your Schema
- You can use XSLT to transform your Schema
If you want to learn XML Schema, please read our XML Schema Tutorial.
- Previous Page XML DTD
- Next Page XML Server