是否应通过 <!ENTITY ... SYSTEM ...> 包含 XML 文件?有一个 <?xml?>宣言? [英] Should an XML file included via <!ENTITY ... SYSTEM ...> have an <?xml?> declaration?

查看:37
本文介绍了是否应通过 <!ENTITY ... SYSTEM ...> 包含 XML 文件?有一个 <?xml?>宣言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML 文件 file1.xml,我试图在其中包含 file2.xml 中的一个片段,如下所示:

I have an XML file, file1.xml, and I'm trying to include in it a snippet from file2.xml, like so:

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<!DOCTYPE Context [
    <!ENTITY File2Contents SYSTEM "file2.xml">
]>

<Context>
    &File2Contents;
</Context>

file2.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<Manager path=""/>

问题

我不断收到有关 file2.xml 中伪属性"的奇怪的解析器投诉,所以我的问题是该 XML 声明是否应该在 file2.xml 中,或者 file2.xml 是否真的是格式正确的 XML 文档或更多的独立片段文件...

Problem

I keep getting odd parser complaints regarding "pseudo attributes" in my file2.xml, so my question is whether that XML declaration is supposed to be in file2.xml, or whether file2.xml is really a properly-formed XML document or more of a standalone snippet file...

推荐答案

规范说明,XML 声明很好,它甚至应该在那里:

The spec says, that the XML declaration is just fine, it even SHOULD be there:

外部解析的实体都应该以文本声明开头.

External parsed entities SHOULD each begin with a text declaration.

Text Declaration
[77]      TextDecl       ::=      '<?xml' VersionInfo? EncodingDecl S? '?>'

文本声明必须按字面提供,而不是通过引用解析的实体.文本声明不得出现在外部解析实体的开头以外的任何位置.外部解析实体中的文本声明不被视为其替换文本的一部分.

The text declaration MUST be provided literally, not by reference to a parsed entity. The text declaration MUST NOT appear at any position other than the beginning of an external parsed entity. The text declaration in an external parsed entity is not considered part of its replacement text.

看来,问题出在解析器上.

So it seems, the problem is with the parser.

这篇关于是否应通过 &lt;!ENTITY ... SYSTEM ...&gt; 包含 XML 文件?有一个 &lt;?xml?&gt;宣言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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