Bryan
Bryan

Reputation: 3009

XML & DTD - Internal General Entity

I'm trying to include an internal general entity, but it isn't working. XML Copy Editor tells me that the XML file is both well-formed and valid. I used an online resource to check that my DTD file was valid, and that is too, but when I check the xml file in my web browser, I get this: enter image description here

Here is the XML code:

<instructor>
  <first>Bob</first>
  <last>Dole</last>
</instructor>
<instructor>
  &instructor-name;
</instructor>

Here is the DTD code:

<!-- Element instructor -->
<!ELEMENT instructor (first, last)>
<!-- Create an internal, general entity for instructor -->
<!ENTITY instructor-name "
    <first>Jimmy</first>
     <last>Davis</last>">

There are two instructors listed. Bob Dole, and Jimmy Davis (which is stored in the DTD file). I originally used the same format for both instructors and didn't use any entities and it worked just fine. As soon as I tried to use an internal general entity to list Jimmy Davis, I got the error message seen in the image above. What am I doing wrong?

Upvotes: 0

Views: 707

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52888

If your DTD is truly internal, as in internal subset, like stated in the comments you shouldn't have any issues opening your XML in a browser.

For example, the following XML has no issues opening in IE or Firefox...

<!DOCTYPE instructors [

<!ELEMENT instructors (instructor+)>
<!ELEMENT instructor (first, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT last (#PCDATA)>

<!ENTITY instructor-name "
    <first>Jimmy</first>
     <last>Davis</last>">
]>
<instructors>
    <instructor>
        <first>Bob</first>
        <last>Dole</last>
    </instructor>
    <instructor>
        &instructor-name;
    </instructor>
</instructors>

IE Display

enter image description here

Firefox Display

enter image description here

Upvotes: 1

Related Questions