0

A very simple HTML file. I deliberately placed all required attributes even though it may be an overkill. (Actually, é is recognised by practically all browsers without explicit specification, but this is just an example to highlight the problem):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
    <!ENTITY eacute "&#233;">
]> 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Test HTML with an entity</title>
</head>

<body lang="en">
<h1>R&eacute;sum&eacute;</h1>
</body>
</html>

When I open it in a browser (I tried Firefox, Chrome, IE and Android WebView), it always comes up as

]>

Résumé

and I can't see a reason why ]> appears. Of course, it I remove ]> in DOCTYPE, everything appears all right, but in this case my html is not a valid xml file, so it gives an error when opened in DOM.

Any suggestions?

cyanide
  • 3,885
  • 3
  • 25
  • 33

1 Answers1

0

What you are doing is correct as per XML rules, and it actually works in browsers that support XML, when served as XML; cf. How do I define HTML entity references inside a valid XML document?

The problem is that if the document is opened as legacy HTML in a browser, it will be processed by legacy HTML principles. This means, among other things, that an internal DTD subset (the thing you have in brackets in the DOCTYPE declaration) is not parsed by the book; instead, when processing a DOCTYPE string, browsers end with the first > character, and the rest will be consumed as character data.

So the problem isn’t just the ]>. The construct does not work at all, i.e. no entity is defined. In the example, the “é” character is displayed, but only because &eacute; is predefined in HTML. If you tried defining <!ENTITY foo "&#233;"> and using &foo;, you would see &foo; literally.

If your document will be processed as legacy HTML, you cannot define entity references. Apparently it currently is, since the example document does not display at all when processed as XML (it is not well-formed, so only a syntax error message appears).

Community
  • 1
  • 1
Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
  • I've got to that myself. Just replaced html extension by xhtml and it worked all right! Thank you anyway. – cyanide Sep 15 '14 at 10:46