问题描述
我需要能够引用诸如& bull;
之类的命名HTML实体,而不是Unicode替代•
在XML文档中。我可以控制XML文档的某些部分,例如定义 DOCTYPE
,但是不能在实际XML中进行查找和替换。通过包含XHTML过渡DOCTYPE,我可以获得诸如& nbsp;
和&
之类的一些元素,但是我需要手动定义。我该怎么做?
I need to be able to reference named HTML entities like •
instead of the Unicode alternative •
in an XML document. I have control over some parts of the XML document, such as defining the DOCTYPE
, but doing a find-and-replace in the actual XML is not an option. I can get some elements like
and &
by including the XHTML transitional DOCTYPE, but I need to define more manually. How do I do this?
-编辑-
感谢吉姆的回答,这就是我结束的内容跟上。这很棒,因为我可以利用XHTML过渡实体,还可以添加自己的实体:
Thanks to Jim's answer, here's what I ended up with. This is great because I can utilize the XHTML transitional entities, and also add my own:
<!DOCTYPE
html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[
<!ENTITY bull "•">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
... etc ...
]
>
推荐答案
如果可以修改XML以包括内联DTD,您可以在此处定义实体:
If you can modify the the XML to include an inline DTD you can define the entities there:
<!DOCTYPE yourRootElement [
<!ENTITY bull "•">
....
]>
这篇关于如何在有效的XML文档中定义HTML实体引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!