Skip to content Skip to sidebar Skip to footer

Character Entity References - Numeric Or Not?

So, I know that I can represent an ampersand as & or &. I have found that at least one method of parsing XML does not allow for the abbreviation-based style - only

Solution 1:

XML only has a small set of these symbolic entities, for amp, quot, gt and lt.

The symbolic names we're familiar with for ©, etc. for entities exist because of their appearance in the HTML DTD, here http://www.w3.org/TR/html4/sgml/entities.html (although I think most browsers have this baked in).

Therefore, if you are using (X)HTML, get your doctype right, and then follow the links on w3.org to XHTML to see the entities available.

As far as best practices, most people find the symbolic names easier to understand and will use them when available. I would recommend that.

The only reason not to is that there used to be cases in very old browsers when entities wouldn't work-- but I don't believe this is the case any more.

Solution 2:

If you mean other HTML entities, with pure XML, only the entities amp, lt, gt, quot, and apos are pre-defined (apos is not available in HTML, but amp indeed should be).

However, all other HTML entities (such as nbsp) will not be available unless defined in the DOCTYPE, so in such a case, using numeric entities may indeed be preferable.

Post a Comment for "Character Entity References - Numeric Or Not?"