2

I have an XHTML document that defines several text entities in its internal DTD. I want these entities to be available in other XHTML documents without having to cut and paste the internal DTD everywhere.

The answer that seems to keep coming up for other XML files (not specifically XHTML) -- for example, here: https://stackoverflow.com/questions/13567930/how-to-use-multiple-dtd-files-in-a-single-xul -- suggests that the XHTML file I want to write would look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
          "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" [
<!ENTITY % mydtd SYSTEM "x.ent">
%mydtd;
]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <title>Example</title>
</head>
<body>
<p>&ldquo;&x; &y;&rdquo;</p>
</body>
</html>

... where the file x.ent has these contents:

<!ENTITY x "Hello">
<!ENTITY y "world!">

But no. At any rate, it doesn't show what I expect in either of the browsers I need to work with. I expect to see "Hello world!" enclosed in left-hand and right-hand double quotes. But Firefox says &ldquo; is an undefined entity, and Opera shows the text between <p> and </p> verbatim (displaying ampersands instead of quotation marks).

I also tried inserting the public DTD within my internal DTD, so:

<!DOCTYPE html [
<!ENTITY % publicdtd PUBLIC "-//W3C//DTD XHTML 1.1//EN"
          "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
%publicdtd;
<!ENTITY % mydtd SYSTEM "x.dtd">
%mydtd;
]>

Then Firefox complained that &x; was an undefined entity. Opera displayed the quotation marks I expected, but still displayed &x; and &y; verbatim; no hello, no world.

I thought x.ent didn't need an XML tag, but someone put one in their example of a file of entity definitions, so I tried it. That didn't work either.

Is there some reason that this can't work in XHTML? Or is this a defect in both of these browsers? Or is there another way to share the entities among multiple files? Unfortunately, I need something that works in these two browsers, or I might as well not do it at all. But if it's a flaw in the XHTML 1.1 DTD, I can use a different version.

1

The most plausible solution to this problem so far seems to be to use software to generate the files that will actually be loaded by the browser.

For example, a page on Using Entities to Include Files shows examples of entities defined in a file which is then included in a document so that the document can use those entities. Looking at the exercises in the lower half of the page, however, there is an important step that was not part of the process I was following:

Produce example.html by normalizing example.xml.
% xmllint --dropdtd --noent example.xml > example.html

In other words, while the file you write (example.xml) bears some syntactic resemblance to the file that you load into your browser (example.html), it is not the same file. The xmllint utility has resolved all the named entity references that you created, producing a file that depends only on the public DTD.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.