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

why won't this external general entity reference work?

Status
Not open for further replies.

JeffCaz

Programmer
Aug 13, 2004
5
0
0
US
I have been banging my head over this simple problem for hours and can't find anything on the internet that helps...

The entity substitution will not work unless it is defined in the Main XML file. I tried putting it in the SimpleExternalDTD2.dtd and in another MyEntities.dtd file, but neither work. It used to work until I added the parameter entity. Adding that broke the general entity substitution. What am I doing wrong?

Main XML file using external general entity:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE doc SYSTEM "SimpleExternalDTD2.dtd">
<doc xmlns=" <greeting>
Hello &me;!
</greeting>
<message>
<title>Using ENTITYs</title>
<body>Are we having fun yet?</body>
</message>
</doc>

SimpleExternalDTD2.dtd:

<!ENTITY % names SYSTEM "MyEntities.dtd">
<!ELEMENT doc(greeting, message)>
<!ATTLIST doc xmlns CDATA #FIXED "<!ENTITY % record "(title, body)">
<!ELEMENT greeting (#PCDATA)>
<!ELEMENT message %record;>
<!ELEMENT title (#PCDATA)>
<!ELEMENT body (#PCDATA)>
%names;

MyEntities.dtd:

<!ENTITY me "Mr. Mystery Guy">
 
As far as I see, your problem is this.
><!ELEMENT doc(greeting, message)>
It should be this.
[tt]<!ELEMENT doc[highlight] [/highlight](greeting, message)>[/tt]
 
Hmmm... That must have been an error when I copy/pasted the text in and changed the name of my root element. In mine there is a space there and it doesn't work. Did you try it and it worked for you? When I attempt to look at it in Firefox or Opera, it complains about:

XML Parsing Error: undefined entity
Location: file:///W:/Java/xml/test/XMLwithExternalDTD1.xml
Line Number 18, Column 13:
Hello &me;!
------------^

but it passes well-formed and validation checks.

Anymore suggestions?
 
[1] There are a couple of concepts.
[1.1] The document is validated against the dtd. With it, the resolution of external entities go with it.
[1.2] The document is parsed on load for well-formedness. The external entities are resolved.

[2] If you just want to answer the question if the xml documents so defined is valid or not. The answer is that it is valid.

[3] If you want to use browser(s) as a tool to display an xml document, then you are at the mercy of the browser's special (default) features.

[3.1] For ie, the default features are [a] _not_ to validate on load, and resolve external entities. Hence, the xml shown will display just fine in ie.

[3.2] For firefox, in version 2, the default features are [a] _not_ to validate on load, and not to resolve the external entities. Consequent, it does not display well.

[3.2.1] If I recall correctly, for version 1.0 (not even 1.5), the default is to resolve external. (My recall may fail me, so you have to check.) If that's the case, it displays again well.

The above is how you have to perceive the problem properly.
 
Thank you tsuji. Yes, it works fine in IE. (I didn't have it installed before.) I am surprised that Firefox and Opera don't resolve external entities, but now I know. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top