Character Entity References - numeric or not?

蹲街弑〆低调 提交于 2019-12-11 15:29:17

问题


So, i know that I can represent an apersand 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.

Can anyone provide any other insight as to which method to favor?


回答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.




回答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.



来源:https://stackoverflow.com/questions/5420190/character-entity-references-numeric-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!