我们可以将XML文件导入另一个XML文件吗? [英] Can we import XML file into another XML file?
问题描述
我的意思是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>
一些可能有帮助的参考文献:
- 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
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:
- 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屋!