This section describes a tutorial example on how to assign an XML Schema file (XSD) to an XML document using XMLPad.
If you want to validate an XML document against an XSD (XML Schema Definition) document,
you need to assign (link) the XSD file to the XML document. Since we have created
a simple XSD document, first_html.xsd, and a simple XML document, first_html.xml,
that should conform to the rules defined in first_html.xsd,
let's try to assign first_html.xsd to first_html.xml with XMLPad:
1. Run XMLPad and click menu File > Open. Select c:\herong\first_html.xml in the "Open"
dialog box. XMLPad displays the XML document in the edit window:
<?xml version = "1.0" encoding = "utf-8"?>
<html>
<body>My first HTML document in XML format.</body>
</html>
2. Click menu XML > Assign Schema/DTD. The "Assign Schema/DTD" dialog box shows up.
3. Check the "W3C Schema" radio button and the "Browse..." button
to select the XSD document c:\herong\first_html.xsd.
4. Leave the Namespace field blank and click OK.
XMLPad will modify the root element "html" to insert two attributes to
assign the XSD file, first_html, as the validation schema for first_html.xml.
<?xml version="1.0" encoding="utf-8"?>
<html xsi:noNamespaceSchemaLocation="file:///C:/herong/first_html.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<body>My first HTML document in XML format.</body>
</html>
5. The last step is to click menu File > Save As. And save this modified XML document
as c:\herong\first_html_xsd.xml.
To fully understand this XSD document, you need to read other chapters in book to learn
XML Schema language syntax. But here is quick description what the two extra attributes are:
"xmlns:xsi" defines a namespace called "xsi" to be used as a prefix for element and
attribute names.
"xsi:noNamespaceSchemaLocation" defines where is the XSD file located.