<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Don't call me DOM &#187; Dessine moi un ML</title>
	<atom:link href="http://people.w3.org/~dom/archives/category/qa/dessine-moi-un-ml/feed/" rel="self" type="application/rss+xml" />
	<link>http://people.w3.org/~dom</link>
	<description>W3C has the DOM, and the Dom ; pick the one you prefer.</description>
	<lastBuildDate>Sat, 07 Nov 2009 11:02:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Named versus Numeric Entities</title>
		<link>http://people.w3.org/~dom/archives/2005/04/named-versus-numeric-entities/</link>
		<comments>http://people.w3.org/~dom/archives/2005/04/named-versus-numeric-entities/#comments</comments>
		<pubDate>Tue, 26 Apr 2005 12:19:02 +0000</pubDate>
		<dc:creator>Dom</dc:creator>
				<category><![CDATA[Dessine moi un ML]]></category>

		<guid isPermaLink="false">http://people.w3.org/~dom/archives/2005/04/named-versus-numeric-entities/</guid>
		<description><![CDATA[I was kindly notified that my RSS feed was ill-formed for the past few days, because of an &#38;mdash; entity in one of my previous posts. While I have fixed manually the issue, I was asked in return why this entity made my feed invalid. I&#8217;m taking this question as an opportunity to start a [...]]]></description>
			<content:encoded><![CDATA[<p>I was kindly notified that <a href="http://people.w3.org/~dom/feed/rdf/">my RSS feed</a> was ill-formed for the past few days, because of an <code>&amp;mdash;</code> entity in one of my previous posts. While I have fixed manually the issue, I was asked in return why this entity made my feed invalid. I&#8217;m taking this question as an opportunity to start a <a href="http://people.w3.org/~dom/archives/category/qa/dessine-moi-un-ml/">new category on tutorials about markup languages</a>; it may end up being only one article only, but I&#8217;m interested in getting more questions for this category if people find it useful (let me know through comments or mail).</p>

<p>So, why would this <code>&amp;mdash;</code> entity make my RSS feed ill-formed and not my XHTML post?</p>
<p>XML (and SGML before it) allows authors to include any character from the Unicode character set (also known as ISO/IEC 10646) either directly as a character encoded as defined in the encoding set in the XML declaration, or as a so called <a href="http://www.w3.org/TR/REC-xml/#sec-references">character references</a> of the form <code>&amp;#<var>characterCode</var>;</code>, often called <dfn>numeric entities</dfn>.</p>
<p>Why two ways of inserting a character? There are two main situations where entering directly the character is not possible or practical:</p>
<ul>
<li>the input device doesn&#8217;t allow to enter the given character, or not in an easy way (try entering a Japanese character in a Western keyboard!)</li>
<li>the encoding declared for the given XML document only encodes a reduced character set that doesn&#8217;t include the targeted character &#8212; as a matter of fact, most encodings maps a reduced character set; the beauty of UTF-8 and other UTF-* is to map the full Unicode character set</li>
</ul>
<p>For instance, the character e with an acute accent can be directly entered as &#8220;é&#8221; if your input device allows it and if &#8220;é&#8221; is available in the declared encoding; otherwise, you can insert it as <code>&amp;#233;</code>, since 233 is the code for &#8220;é&#8221; in Unicode.</p>

<p>In a syntax similar to character references, SGML and XML also define <dfn>named entities</dfn>, of the form <code>&amp;<var>name</var>;</code>. These named entities can stand for (almost) any type of content, but their most well-known usage is to serve as replacement for character references. HTML defines three set of named entities (<a href="http://www.w3.org/TR/html401/HTMLlat1.ent">one mapping the ISO Latin 1 character set</a>, <a href="http://www.w3.org/TR/html401/HTMLsymbol.ent">another mapping a set of symbols</a>, and <a href="http://www.w3.org/TR/html401/HTMLspecial.ent">one mapping a set of &#8220;special&#8221; characters</a> such as quotes, euro sign, etc). For instance, in HTML, you can use <code>&amp;mdash;</code> to insert a middle dash (not easily available on any keyboard I know) instead of <code>&amp;#8212;</code>; both are correct of course, but the former is much easier to remember than the latter for most people.</p>
<p>But the important thing to remember with regard to <strong>named entities</strong> is that they are <strong>bound to a <abbr title="Document Type Declaration">DTD</abbr></strong>; more precisely, one can only use a named entity in a document that explicitly refers to a DTD that defines the given entity; otherwise, in the best case, the parser will simply not make sense of the said entity, and in the worst case (depending on the parser type), the parser will completely reject the full document.</p>
<p>In other words, one can only use <code>&amp;mdash;</code> in an XML document that declares that this named entity is equivalent to &#8220;&#8212;&#8221;; any valid (X)HTML document has a doctype that references the named entities declarations, so this isn&#8217;t a problem. But for most other XML documents (e.g. my RSS feed),  this entity does not represent anything and makes the document as a whole invalid. For my own case, my <a href="http://wordpress.org/">blogging tool</a> should have replaced the named entity with either the actual character or a numeric entity when generating the RSS feed; I haven&#8217;t fully explored yet why it doesn&#8217;t, but that&#8217;s definitely a bug.</p>
<p>Note that named entities are one of the reasons why DTD are still used in XHTML or MathML; there is no other schema technology that defines a way to create named entities, and while there has been a lot of discussion on how to get rid of DTDs in XML, named entities are still one of requirements that are hard to get around, due to their popularity for hand-authored documents.</p>
<p>(As an authoring shortcut, numeric and named entities are so useful that some have <a href="http://www.tbray.org/tag/utf-8+names.html">proposed to extend their usage</a> for any kind of text, relying on a predefined set of useful names).</p>]]></content:encoded>
			<wfw:commentRss>http://people.w3.org/~dom/archives/2005/04/named-versus-numeric-entities/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
