@reiver

Making   work in XML, RSS, and Atom

If you came to XML, RSS, or Atom from an HTML background then you have probably already found that many of the entities you used in HTML don't work.

Although XML, by default, defines the following 5 entities:

XML Entity Description Symbol
& Ampersand &
&lt; Less Than Sign <
&gt; Greater Than Sign >
&quot; Double Quote "
&apos; Apostrophe '

Many of the entities you are probably familiar with do not by default exist in XML. Entities like &copy;, &middot;, and many others; including &nbsp;.

Probably the most frustrating to me at times is the lack of support for &nbsp;. Especially when embedding XHTML into an Atom <atom:content type="xhtml"> element.

Here's how to make &nbsp; work in XML, RSS, and Atom.

What is a &nbsp;

The &nbsp; entity is the HTML entity for a non-breaking space. A non-breaking space is a special space character that prevents a line break when a line wrapping algorithm is applied to render the text.

In HTML one of the common uses for the &nbsp; is to get multiple consecutive spaces in a row.

XML Entities and Unicode Code Points

In Unicode, each and every character has a numerical value. Here's some examples:

Character Description Decimal Value Hexadecimal Value
E Capital "E" 69 45
x Lowercase "x" 120 78
  Non-Breaking Space 160 A0
Interrobang 8253 203D
Heart 9829 2665

In XML, you can use any Unicode characters with a special type of entity. (Although your browser may or may not have a font glyph to render the character on screen.)

You can either use the Unicode numerical decimal value of a character. As in &#8253; for Interrobang.

Or you can use the Unicode numerical hexadecimal value of a character. As in &#x203D; for Interrobang.

Although the decimal form of these types of entities is better supported in the common web browsers. (So, for the Interrobang, it would be better to use &#8253; rather than &#x203D;.)

The Other Non-Breaking Space Entity

So to use &nbsp; in XML, RSS, and Atom, it's simple. Use the following entity:


&#160;

It's that simple.

--