如何在有效的 XML 文档中定义 HTML 实体引用?
我需要能够在 XML 文档中引用命名的 HTML 实体,例如 •
,而不是 Unicode 替代 •
。我可以控制 XML 文档的某些部分,例如定义 DOCTYPE
,但在实际 XML 中执行查找和替换不是一个选项。我可以通过包含 XHTML 过渡 DOCTYPE 来获取一些元素,例如
和 &
,但我需要更多手动定义。我该怎么做?
-- 编辑 --
感谢吉姆的回答,这就是我的最终结果。这很棒,因为我可以利用 XHTML 过渡实体,还可以添加我自己的:
<!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 ...
]
>
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?
-- EDIT --
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 ...
]
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以修改 XML 以包含内联 DTD,则可以在其中定义实体:
If you can modify the the XML to include an inline DTD you can define the entities there:
我不确定,但我认为 XHTML DTD 应该为您提供相当多的实体 (253):
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Entities_representing_special_characters_in_XHTML
另外,在 w3 规范中,还提到了特殊字符等的附加 DTD。
http://www.w3.org/TR/xhtml-modularization/dtd_module_defs .html#a_dtd_xhtml_character_entities
但是我还没有找到实现示例特殊字符 DTD。
由 DevNull 编辑
这是实体 DTD 模块之一的极其通用的示例实现。实现时只需要添加一个指向模块的参数实体即可。
I'm not cetain, but I think the XHTML DTD's should give you quite a few entities (253):
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Entities_representing_special_characters_in_XHTML
Also in the w3 spec, there is a mention of additional DTD's for special characters etc.
http://www.w3.org/TR/xhtml-modularization/dtd_module_defs.html#a_dtd_xhtml_character_entities
However I haven't been able to find an implementation example of the special character DTDs.
Edit by DevNull
Here is an extremely generic example implementation of one of the entity DTD modules. To implement, you only need to add a parameter entity pointing to the module.