Check for DTD Errors

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Schemas

Check for DTD Errors

If a DTD is used within or linked to an XML document, a quick way to check for errors in the DTD is to try loading an XML document file that uses it in Internet Explorer.

Example

The following are an external DTD file with an error (a single missing close parentheses) and an XML file that links to and uses this DTD.

DTD File (errored.dtd)

<!ELEMENT catalog    (book+) >
<!ELEMENT book       (author, title, genre, price, publish_date, description) >
<!ATTLIST book       id ID #REQUIRED >
<!ELEMENT author         (#PCDATA)   >
<!-- The following line has the error -->
<!ELEMENT title          (#PCDATA   >
<!ELEMENT genre          (#PCDATA)   >
<!ELEMENT price          (#PCDATA)   >
<!ELEMENT publish_date   (#PCDATA)   >
<!ELEMENT description    (#PCDATA)   >

XML File (books-using-errored.xml)

<?xml version="1.0"?>
<!DOCTYPE catalog SYSTEM "errored.dtd">
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications with
      XML.</description>
   </book>
</catalog>

Try It!

  1. Open Notepad.
  2. Copy the errored.dtd. Paste it into the Notepad window.
  3. From the File menu, click Save As. Save the file as errored.dtd to a folder on your computer.
  4. Copy the books-using-errored.xml. Paste it into the Notepad window.
  5. From the File menu, click Save As. Save the file as books-using-errored.xml to the same folder in which you saved errored.dtd.
  6. Open books-using-errored.xml in Internet Explorer.

Output

Results should appear in the browser window similar to the following, indicating an error in the DTD.

<P STYLE='line-height:15.0pt'><SPAN STYLE='font-size:13.0pt;font-family:Verdana'>The
XML page cannot be displayed</SPAN></P>
<P STYLE='line-height:11.0pt'><SPAN STYLE='font-size:8.0pt;font-family:Verdana'>Cannot
view XML input using style sheet. Please correct the error and then click the Refresh
button, or try again later. </SPAN></P>
<P STYLE='line-height:11.0pt'><B><SPAN STYLE='font-size:8.0pt;font-family:Verdana'>Mixed
content model cannot contain this character. Error processing resource
'file:///C:/temp/books.dtd'. Line 6, Position 37 </SPAN></B></P>
<P STYLE='line-height:12.0pt'><CODE><SPAN STYLE='color:blue'>&lt;!ELEMENT title&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(#PCDATA &gt;</SPAN></CODE></P>

If you correct the error in errored.dtd by adding the missing close parentheses to line 6, you can successfully reload the books-using-errored.xml file.