Scarlet Line home page Scarlet Line - SOFTWARE DESIGN & DEVELOPMENT

[Home]->[Documentation]->[How To ...]->[Use HTML and MathML Entities in any XML File]

How To Use HTML and MathML Entities in any XML File

You may find that you are using XML to store data and you want to be able to use entities such as ©,  , etc. in your file.
If you simply use them in the file then you will get various errors from xslt processing or web display. The trick is to add the doctype header as seen in the following example.
Here is a simple example of an xml file using entities:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dataset [
   <!ENTITY % w3centities
     PUBLIC "-//W3C//ENTITIES Combined Set//EN//XML"
     "" >

   <entry>Copyright &copy; 2008</entry>

If you are using this trick regularly, I suggest that you download the entity file to your local web server, and change the url reference in the doctype header to point to your local copy, as this will speed up entity access.
For example, on my internal website I use the following line:

<!DOCTYPE dataset [<!ENTITY % w3centities PUBLIC "-//W3C//ENTITIES Combined Set//EN//XML" "http://localhost/entities.ent"> %w3centities;]> 

The latest information about these W3C XML Entity definitions for Characters can be found here.
All of the entity codes can be seen and tested on Dan Short's Page.