我们可以将 XML 文件导入另一个 XML 文件吗? [英] Can we import XML file into another XML file?
问题描述
我们可以将一个 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:
- http://www.xml.com/pub/a/98/08/xmlqna2.html
- http://xmlwriter.net/xml_guide/entity_declaration.shtml
- http://www.javacommerce.com/displaypage.jsp?name=entities.sql&id=18238
这篇关于我们可以将 XML 文件导入另一个 XML 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!