我们可以将 XML 文件导入另一个 XML 文件吗? [英] Can we import XML file into another XML file?

查看:53
本文介绍了我们可以将 XML 文件导入另一个 XML 文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以将一个 XML 文件导入另一个 XML 文件吗?

Can we import an XML file into another XML file?

我的意思是在 XML 中是否有任何导入标记将 XML 路径作为参数并导入 XML(为其提供路径).

I mean is there any import tag in XML that takes XML path as parameter and imports XML (for which path is provided).

推荐答案

您可以使用 外部(解析)一般实体.

您像这样声明实体:

You could use an external (parsed) general entity.

You declare the entity like this:

<!ENTITY otherFile SYSTEM "otherFile.xml">

然后你像这样引用它:

&otherFile;

一个完整的例子:

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE doc [
<!ENTITY otherFile SYSTEM "otherFile.xml">
]>
<doc>
  <foo>
    <bar>&otherFile;</bar>
  </foo>
</doc>

当 XML 解析器读取文件时,它会展开实体引用并将引用的 XML 文件包含为内容的一部分.

When the XML parser reads the file, it will expand the entity reference and include the referenced XML file as part of the content.

如果otherFile.xml"包含:<baz>这是我的内容</baz>

If the "otherFile.xml" contained: <baz>this is my content</baz>

然后 XML 将被 XML 解析器评估并看到"为:

Then the XML would be evaluated and "seen" by an XML parser as:

<?xml version="1.0" standalone="no" ?>
<doc>
  <foo>
    <bar><baz>this is my content</baz></bar>
  </foo>
</doc>

一些可能有用的参考资料:

A few references that might be helpful:

这篇关于我们可以将 XML 文件导入另一个 XML 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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