2

In a web project, I have a lot of XML files with non-escaped characters. I declare these characters as DTD Entities and include the list of declaration internally in each XML file, like so:

!DOCTYPE article SYSTEM "../../pubmedref/archivearticle.dtd" [
   <!ENTITY bull "&#8226;">
   <!ENTITY copy "&#169;">
   ... a long list ...
]>

Is there any way I can have these declarations in an external file and import it in the XML files? The XML files are rendered to the browser using XSLT.

FWIW, I've tried referencing a .ent file but it does not work on any of the browsers.

dpant
  • 1,622
  • 19
  • 30

1 Answers1

6

Normally you would use a parameter entity...

XML File

<!DOCTYPE article SYSTEM "../../pubmedref/archivearticle.dtd" [
<!ENTITY % ents SYSTEM "../../pubmedref/entities.ent">
%ents;
]>
<article>...</article>

Entity File (you could have multiple files)

<!ENTITY bull "&#8226;">
<!ENTITY copy "&#169;">

However, most browsers will not resolve an external entity reference so you're stuck with having the entity declarations directly in the internal subset (between [ and ] in your doctype declaration).

Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
  • I am really shocked. I can't believe this is not supported by the browsers. Any particular reason? – dpant Jul 11 '15 at 15:59
  • 1
    i stumbled across this old answer for kind of the same reasons. if think this part `<!ENTITY ents %` should be corrected this way: `<!ENTITY % ents` – Mauro Panzeri Dec 15 '16 at 17:28
  • @MauroPanzeri - Excellent catch! Thank you! – Daniel Haley Dec 15 '16 at 17:55
  • 1
    @dpant > Some browsers(like FireFox and Chrome) have very strict security settings and will not load files entity references and XSLT processing instructions that reference files on the filesystm. > https://stackoverflow.com/questions/7783578/how-to-use-external-entities-in-xml – Nor.Z Jul 01 '22 at 23:02