XML:如何将一个xml文件的内容加载到另一个 [英] XML: How to load the contents of one xml file into another

查看:485
本文介绍了XML:如何将一个xml文件的内容加载到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从另一个xml文件动态写入xml文件的内容。

I would just like to be able to dynamically write the contents of an xml file from another xml file.

A.XML包含:

<?xml version="1.0"?>
<node>
-Include Contents of b.xml
</node>

B.XML包含:

<anode>
a
</anode>

有没有办法在xml中执行此操作?

is there any way to do this in xml?

最终产品如下:

<?xml version="1.0"?>
<node>
  <anode>
    a
  </anode>
</node>

评论更新


仅在xml中。这样,当我在浏览器中查看
xml文件时,它会正确呈现

In xml alone. so that when i view the xml file in a browser it renders correctly


推荐答案

使用外部(已分析)常规实体引用 a.xml b.xml >。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE node [
<!ENTITY b SYSTEM "b.xml">
]>
<node>
    &b;
</node>

XML解析器将动态包含 b.xml 解析为 a.xml 并生成所需的XML。

The XML parser will dynamically include the content of b.xml as it parsees a.xml and will produce the XML that you want.

如果在IE中加载 a.xml ,它将正确呈现。

If you load a.xml in IE, it will render correctly.

注意:某些浏览器具有非常严格的安全策略,会导致从文件系统加载引用的XML文件和扩展实体引用时出现问题,因此可能不会如果从文件系统加载 a.xml ,则可以在所有浏览器中使用,但是如果从URL加载,则可以在更多浏览器中使用。

Note: Some browsers have very strict security policies that cause problems loading referenced XML files from the filesystem and expanding entity references, so it may not work in all browsers if you load a.xml from the filesystem, but may work in more browsers if you load from a URL.

这篇关于XML:如何将一个xml文件的内容加载到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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