如何在外部文件中将转义字符声明为 DTD 实体并在 XML 文件中导入 [英] How to declare escape character as DTD Entities in external file and import in XML files

查看:17
本文介绍了如何在外部文件中将转义字符声明为 DTD 实体并在 XML 文件中导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个 web 项目中,我有很多带有非转义字符的 XML 文件.我将这些字符声明为 DTD 实体,并在每个 XML 文件内部包含声明列表,如下所示:

In a web project, I have a lot of XML files with non-escaped characters. I declare these characters as DTD Entities and include the list of declaration internally in each XML file, like so:

!DOCTYPE article SYSTEM "../../pubmedref/archivearticle.dtd" [
   <!ENTITY bull "&#8226;">
   <!ENTITY copy "&#169;">
   ... a long list ...
]>

有什么办法可以将这些声明放在外部文件中并将其导入 XML 文件中?XML 文件使用 XSLT 呈现给浏览器.

Is there any way I can have these declarations in an external file and import it in the XML files? The XML files are rendered to the browser using XSLT.

FWIW,我试过引用 .ent 文件,但它在任何浏览器上都不起作用.

FWIW, I've tried referencing a .ent file but it does not work on any of the browsers.

推荐答案

通常你会使用参数实体...

Normally you would use a parameter entity...

XML 文件

<!DOCTYPE article SYSTEM "../../pubmedref/archivearticle.dtd" [
<!ENTITY % ents SYSTEM "../../pubmedref/entities.ent">
%ents;
]>
<article>...</article>

实体文件(您可以有多个文件)

<!ENTITY bull "&#8226;">
<!ENTITY copy "&#169;">

但是,大多数浏览器不会解析外部实体引用,因此您只能将实体声明直接放在内部子集中(在 [] 之间)文档类型声明).

However, most browsers will not resolve an external entity reference so you're stuck with having the entity declarations directly in the internal subset (between [ and ] in your doctype declaration).

这篇关于如何在外部文件中将转义字符声明为 DTD 实体并在 XML 文件中导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆