Michael
Michael

Reputation: 406

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 numeric. Is there a best-practice? I want to instruct my team to use the numeric versions because of my experience, but one instance hardly seems like enough reason to convince them.

Which method should we favor?

Upvotes: 0

Views: 203

Answers (2)

ndp
ndp

Reputation: 22016

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.

Upvotes: 1

Brett Zamir
Brett Zamir

Reputation: 14375

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.

Upvotes: 0

Related Questions