I’m using a seperate .dtd file as a doctype for my custom xml file:
names.xml
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE name SYSTEM 'names.dtd'> <names> <name> <text>Pepé</text> <creator>&lost;</creator> <history>&lost;</history> </name> <name> <text>Charles</text> <creator>James</creator> <history>&lost;</history> </name> </names>
names.dtd
<!ELEMENT name (text, creator+, history)> <!ELEMENT text (#PCDATA)> <!ELEMENT creator (#PCDATA)> <!ELEMENT history (#PCDATA)> <!-- Placeholder/unknown history or creator name --> <!ENTITY lost 'Lost in the depths of time.'> <!ENTITY eacute 'é'>
However when trying to access names.xml I get the following error:
XML Parsing Error: undefined entity Location: http://localhost/…/names.xml Line Number 5, Column 18:
<text>Pepé</text> ---------^
Just for clarification names.xml and names.dtd are in the same directory and using http://localhost/…/names.dtd doesn’t work either.
This does seem to work when putting the <!ENTITY inside a <!DOCTYPE in names.xml however. Can anyone advise on this?
If you’re opening the document in Firefox to try to find out if you have the dtd correct, don’t. Firefox doesn’t pass the xml and dtd through a proper xml parser. Open your xml document in IE which will cause your document to be passed through the MSXML parser.
When opening the xml document in IE, it will throw an error about your DTD using invalid characters. You need to use the character code for the eacute rather than the character itself. Here is the code I got to work…
and