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

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

问题描述

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



我的意思是XML中有任何导入标记,以XML路径为参数,并导入XML(为其提供路径)。

解决方案

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



您声明了这样的实体:

 <!ENTITY otherFile SYSTEMotherFile.xml> 

然后你可以这样引用:

 &安培; otherFile; 

一个完整的例子:

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

当XML解析器读取文件时,它将扩展实体引用并将引用的XML文件包含为



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



然后XML将被XML解析器评估和看到:

 <?xml version =1.0standalone =no?> 
< doc>
< foo>
< bar>< baz>这是我的内容< / baz>< / bar>
< / foo>
< / doc>

一些可能有帮助的参考文献:




Can we import an XML file into another XML file?

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">

Then you reference it like this:

&otherFile;

A complete example:

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

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

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

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