Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot link effectively to external dtd file 1

Status
Not open for further replies.

JProg

Programmer
Joined
Apr 4, 2002
Messages
88
Location
JP
Hi,

I have three files related to my challenge. I have one xml file, one css file and one dtd. The files are as follows:

The following file is books.xml

<!DOCTYPE booklist SYSTEM “booklist.dtd”>
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="booklist.css" ?>
<booklist>
<book>
<name>Backpacker's Field Manual</name>
<author>Rick Curtis</author>
<publisher>Crown Publishers Inc.</publisher>
<ISBN>0517887835</ISBN>
<date>March 1998</date>
</book>
<book>
<name>Modern Backpacker's Handbook</name>
<author>Glen Randall</author>
<publisher>Lyons and Burford Publishers</publisher>
<ISBN>1558212485</ISBN>
<date>February 1994</date>
</book>
<book>
<name>Backpacker's Handbook</name>
<author>Chris Townsend</author>
<publisher>Ragged Mountain Press</publisher>
<ISBN>0070653151</ISBN>
<date>October 1996</date>
</book>
</booklist>

The following file is booklist.css:

book
{
font-family: "Arial",sans-serif;
font-size:10pt
}
name
{
display:block;
font-size: 12pt;
background-color:#ffffcc
}
author
{
display:block;
color: #cc6600
}
publisher
{
display:inline;
color: navy
}
ISBN
{
display:inline;
color: blue
}
Date
{
display:inline;
font-style:italic;
color: navy
}

The following file is booklist.dtd:

<!DOCTYPE booklist [
<!ELEMENT booklist (book+)>
<!ELEMENT book (name,author,publisher,ISBN?,date?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT date (#PCDATA)>
]>

I have very little understanding of xml however all was going well until I externalized the dtd. Originally the dtd was part of books.xml, and this displayed fine in IE however now that the dtd has been moved to an external file nothing is working as expected. Here is a report of the errors that I am getting in Internet Explorer and Mozilla respectively:

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.

IE! :)

An invalid character was found in text content. Error processing resource 'file:///D:/Swinburne Docs/Classes/Web Development 1/Lab Work/books.xml'. Line 1, Position 27

<!DOCTYPE booklist SYSTEM

Mozilla!! :)

XML Parsing Error: not well-formed
Location: file:///D:/Swinburne%20Docs/Classes/Web%20Development%201/Lab%20Work/books.xml
Line Number 1, Column 27:<!DOCTYPE booklist SYSTEM ?booklist.dtd?>

I imagine that this is a simple error that I am not familiar with. However as I am not familiar with XML an help with sorting this out will be really appreciated.

Thanks

David

 
Okay...so there are a few issues here.

First, your PI (Processing Instructions) should always come first. So change:

<!DOCTYPE booklist SYSTEM “booklist.dtd”>
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="booklist.css" ?>

to

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="booklist.css" ?>
<!DOCTYPE booklist SYSTEM "booklist.dtd">

<?xml version="1.0"?> should always be the first line if you are going to include it into your XML file.

Second, when you move from an internal dtd to external dtd. Remove the DOCTYPE from your external dtd. This is correct:

<!DOCTYPE booklist SYSTEM “booklist.dtd”>

But this is not needed any more:

<!DOCTYPE booklist [
]>

Remove this DOCTYPE, because the DOCTYPE is only necessary in the XML file. Which you are doing with:

<!DOCTYPE booklist SYSTEM “booklist.dtd”>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top