An Introduction to XML Schemas - The Complete File
(Page 5 of 7 )
Anyway, as this is all that our extremely simple schema document needs in order to validate our extremely simple XML document, we can end the schema with the closing schema element:
</xsd:schema>
The whole file should now look like this:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="news">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element ref="article"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="article">
<xsd:complexType>
<xsd:sequence maxOccurs="1" minOccurs="1">
<xsd:element ref="headline" />
<xsd:element ref="story" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="headline" type="xsd:string" />
<xsd:element name="story" type="xsd:string" />
</xsd:schema>
Save the document with an .xsd prefix. As schema documents are just well-formed XML documents, you can also save it with an .xml prefix and load it up in a browser. If there are any typos or syntax errors in the schema, it won’t load. You need to use an XML compliant browser of course; for the purpose of this article, I’ve used MS IE6.
Next: Validating a Document >>
More XML Articles
More By Dan Wellman