First, the way I understand it, it’s more appropriate to use numeric entities in an XHTML document, such as " instead of ", is that right?
Second, for my RSS XML feed, which entity type is correct? Named or numeric? I believe it’s numeric, but see examples of both in my searches.
Third, which of the following is correct for entities inside inline JavaScript?
<span onmouseover="tooltip_on( '<strong>Tooltip inside a span</strong>
<br />Lorem ipsum dolor sit amet.<span>Lorem ipsum <code>dolor sit</code>
amet, consectetur adipisicing elit.</span>' );"
onmouseout="tooltip_off();">tooltip inside a span</span>
OR… (the tags inside the JS function are converted to named entities):
<span onmouseover="tooltip_on( '<strong>Tooltip inside a
span</strong><br />Lorem ipsum dolor sit amet.
<span>Lorem ipsum <code>dolor sit</code>
amet, consectetur adipisicing elit.</span>' );"
onmouseout="tooltip_off();">tooltip inside a span</span>
EDIT 1:
Great answers below, but maybe I should have worded my question differently.
Disregarding the JavaScript question, which would YOU use for YOUR website and RSS feed:
(1) All numeric entities, (2) all named entities, (3) a mixture of both: & " < >, with the rest being numeric.
I am leaning towards 3 because my site already has & " < > ' deeply embedded, plus htmlspecialchars() used in quite a few places.
EDIT 2:
All good answers below, folks. Had to pick just one, unfortunately.
"is also defined for XHTML. So you can use both.Again,
"is also defined for XML. So you can use both.The second one is correct since a plain
<is not allowed inside an attribute value declaration (but>is).Edit Now that you refined your question:
I would use a charset that contains all characters I need. So if you want to be able to use almost any character, use Unicode and encode the characters with UTF-8.
Thereby you can encode any character with UTF-8 directly and have no need to use character references for characters other than the special characters of XML (at least
&,>,"and').And here you have the free choice between the named or numeric character references. Use what you like better or what your programming language uses/prefers.