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

查看:136
本文介绍了如何在外部文件中将转义字符声明为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 File (you could have multiple files)

<!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天全站免登陆