An Introduction to XML Schemas - Validating a Document
(Page 6 of 7 )
Now that you have your schema document, if you want to use it to validate a document, you have to link it to one. Open the document it is to be used with, in this case news.xml and add the following code to the root element:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="newsSchema.xsd"
This needs to be contained within the brackets of the root element, like this:
<news xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="newsSchema.xsd">
To use the location reference above, the XSD file needs to be in the same directory as the XML file. If the documents are in different directories, you’ll need to use the full path, with double forward slashes to properly escape the slash characters.
Now save the XML document and open it in a browser; the document should load as normal in IE. To use IE to actually validate the XML document using the schema, you may need to change some of the settings of IE or download an additional plug-in; see the MSDN site for further information. As Schema documents are for use mainly in XML applications, if you want to use the schema to validate a document for your own purposes, it is best to visit an on-line validator that uses the schema to validate your XML document. An excellent on-line validator can be found at the following location:
http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx
If this is the case, and your XML document uses just text, it may be wiser to use a DTD.
Next: A Few Final Tips >>
More XML Articles
More By Dan Wellman