Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
152<br />
<strong>XML</strong> Demystifi ed<br />
You’ll notice that the <strong>XML</strong> document refers to the catalog.dtd. As you’ll recall<br />
from Chapter 3, a DTD file contains the document type definition that defines the<br />
markup tags that can be used in the <strong>XML</strong> document and specifies the parent-child<br />
structure of those tags. The <strong>XML</strong> parser references the DTD when parsing elements<br />
of the <strong>XML</strong> document.<br />
Create a DTD for this example. You do this by writing the following information<br />
into a file and saving the file as catalog.dtd in the directory that contains the catalog<br />
.xml file.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
The final step you’ll take to prepare to learn MS<strong>XML</strong> is to create the HTML file<br />
that contains the JavaScript used to access the catalog.xml document. The HTML<br />
file follows. Some of it is familiar because it’s HTML. Other parts, you’ll understand<br />
if you know JavaScript (don’t worry if you don’t understand them; we explain<br />
JavaScript throughout this chapter). However, the portions of the HTML file that<br />
use MS<strong>XML</strong> are probably confusing, even if you previously worked with<br />
JavaScript.<br />
For now, simply create this HTML file and save it to a file called default.html in<br />
the directory where you saved catalog.xml and catalog.dtd. We explain each part of<br />
the HTML file throughout this chapter.<br />
<br />
<br />
<br />
var obj<strong>XML</strong>;<br />
function LoadDocument()<br />
{<br />
var inputfile = document.all("inputfile").value;<br />
obj<strong>XML</strong> = new ActiveXObject("MS<strong>XML</strong>2.DOMDocument.4.0");<br />
obj<strong>XML</strong>.async = false;<br />
obj<strong>XML</strong>.load(inputfile);<br />
if (obj<strong>XML</strong>.parseError.errorCode != 0)<br />
{<br />
alert("Error loading input file: " + obj<strong>XML</strong>.parseError.reason);<br />
return;<br />
}<br />
document.all("xmldoc").value = obj<strong>XML</strong>.xml;<br />
}