SourceForge Logo

xmlchar - XML Named Character Entity Library

Anthony B. Coates

Zarella Rendon

| Download xmlchar from SourceForge |

What is "xmlchar"?

xmlchar is an XSLT library that provides XML elements for all of the special characters defined in HTML 4.

Why would I want to use XML elements for special characters?

HTML provides many named character entities, such as " " for non-breaking spaces. XML provides very few, unless you define them in a DTD or in the XML document's local DTD subset. This is inconvenient when you just want to use well-formed XML, without any need for a DTD or DOCTYPE declaration.

The xmlchar stylesheets allow you to write "<ch:nbsp/>" for a non-breaking space, for example, so that if you know the HTML name, you know the xmlchar name.


Elements are the natural way to define names for special characters in XML, but they do have the limitation that they can only be used in element content. You cannot use xmlchar elements in attribute values.

Using xmlchar

The easiest way is just to use <xsl:import> to call htm4-all.xsl from within your own stylesheet. This will convert the xmlchar elements into the correct character entities. For example,

<html xmlns:ch="">
    <p>My sandwich cost <ch:pound/>2.</p>
    <p>Really?<ch:nbsp/> You were cheated.<ch:nbsp/>
       My sandwich only cost <ch:euro/>2.</p>
is converted to
    <p>My sandwich cost &pound;2.</p>
    <p>Really?&nbsp; You were cheated.&nbsp;
       My sandwich only cost &euro;2.</p>

where the correct HTML entities have been inserted. See the examples which come with the stylesheets for details.

How to get xmlchar

xmlchar is available from SourceForge, and is released under the Lesser GNU Public License, version 2.1.


  1. HTML 4 character entities.

Last updated: 1st November, 2002.

SourceForge Logo