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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newby here - dtd entity problem

Status
Not open for further replies.

carvin5string

IS-IT--Management
Apr 8, 2004
10
US
I am writing my first xml and dtd documents. I am referring to the external dtd from the .xml file and it works great. Until I add an entity declaration. My .dtd file looks like this -
Code:
<!-- Begin book catalog dtd last updated apr 7, 2004 -->
                                                                                                                                                                                                                                                                                 <!ENTITY tit "Title: ">
<!ENTITY aut "Author: ">
<!ENTITY pub "Publisher: ">
<!ENTITY dat "Year Published: ">
<!ELEMENT Catalog (Book+)>
<!ELEMENT Book (Title, Author*, Publisher*, Pub_Date*)>
<!ELEMENT Title (#PCDATA)*>
<!ATTLIST Title ISBN CDATA #REQUIRED>
<!ELEMENT Author (#PCDATA)*>
<!ATTLIST Author Status CDATA #IMPLIED>
<!ELEMENT Publisher (#PCDATA)*>
<!ELEMENT Pub_Date (#PCDATA)*>

The error I get is this -

Code:
XML Parsing Error: undefined entity
Location: file:///C:/temp/test.xml
Line Number 9, Column 29:	  <Title ISBN="1234567890">&tit;Test Book 1</Title>
----------------------------^

Why does the entity result in an error?
Thanks,
Chip
 
Guess that &tit; is the problem.
If you want to use ampersands you have to escape them like this:
&amp;
 
In the DTD I create the internal entity-

<!ENTITY aut "Author: ">

and I reference it like this in the xml file-

<Author Status="deceased">&aut;Some Guy</Author>

which I think is the correct way to do this.

But, when I escape the ampersand, like this:

<Author Status="deceased">&amp;aut;Some Guy</Author>

I get this for output:

&aut;Some Guy

When I should be seeing:

Author: Some Guy

So it seems I am doing something wrong. When I use the dtd at the top of the xml file the entities work properly, only when they are in the seperate dtd file they do not work.
 
Ow, of course you didn't want to print an ampersand.
I'm sorry, that was just a silly remark of me.
I've been working too late, obviously.
 
:) heh,heh. I understand. But I guess you have no suggestion about my problem?

--
Chip
 
Okay, here's what I have found - In Netscape 7 I run the test xml file using the external dtd and css and it errors out on the first entity it encounters. But in IE it displays the xml file just fine.

Anybody seen this before?

--
Chip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top