XML - 引用其他 XML 文件 [英] XML - Referencing Other XML Files

查看:70
本文介绍了XML - 引用其他 XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 XML 的新手,所以这可能是一个相当容易回答的问题.我想知道是否有从其他 XML 文件中引用外部 XML 文件的标准方法.让我举个例子吧.假设您有一个文件,它定义了一个包含大量数据的对象:

I'm new to XML, so this may be a fairly easy question to answer. I was wondering if there is a standard way of referencing external XML files from within other XML files. Let me give an example. Say you have a file which defines a single object that holds a large amount of data:

<person>
    <name>John</name>
    <age>18</age>
    <hair>Brown</hair>
    <eyes>Blue</eyes>
</person>

为了这个问题,假设这个人拥有大量其他信息.假设文件大小为 10 MB.

For the sake of this question, pretend that person holds loads of other information. Pretend the file is like 10 MB.

现在,假设您有另一个定义组的 XML 文件:

Now, let's say you have another XML file which defines a group:

<group>
    <person>
        <name>John</name>
        <age>18</age>
        <hair>Brown</hair>
        <eyes>Blue</eyes>
    </person>
    <person>
        <name>Kim</name>
        <age>21</age>
        <hair>Blue</hair>
        <eyes>Green</eyes>
    </person>
    <person>
        <name>Sean</name>
        <age>22</age>
        <hair>Black</hair>
        <eyes>Brown</eyes>
    </person>
</group>

如您所见,如果 Person 非常大,Group 文件将非常大.所以,如果我们有像 John.xml 这样的东西,是否有一种 标准 方法可以在 Group.xml 中引用它,而无需明确定义 John 的所有内容?数据?我确定这是一个非常广泛的主题,因此请随时将我链接到任何相关网页.谢谢!

As you can see, if Person's were very large, the Group file would be extremely large. So, if we have something like John.xml, is there a standard way to reference it in Group.xml without explicitly defining all of John's data? I'm sure this is a very broad topic, so feel free to link me to any relevant web pages. Thanks!

推荐答案

标准

XInclude 是具有任何级别支持的唯一标准.

Standards

XInclude is the only standard with any level of support.

  • 几个 XML 编辑器,包括 Oxygenxmlspy 支持它.
  • 几个 XML 解析器,包括 Xerces,也支持它,并且还有 .net 端口.
  • 多种 XML 工具,例如 Saxon 支持 Java 和 .net.
  • Several XML editors, including Oxygen and xmlspy support it.
  • Several XML parsers, including Xerces, also support it, and there are .net ports too.
  • Several XML tools, such as Saxon support it, both for Java and .net.

维基百科关于 XInclude 的文章中有一些很好的使用示例.

There are some good examples of use in the Wikipedia article on XInclude.

XLink 是一个切线相关的标准,并不是真正用于包含文档,而是更多用于引用其他文件中的部分.它没有得到很好的支持.

XLink is a tangentially-related standard, not really for including documents, but more for citing portions within other documents. It's not well supported.

如果您担心尺寸,有以下几种方法:

If you are worried about size, there are several ways to go:

  • 使用流式 XML 处理器,例如 DataDirect XQuery(或较小的范围,Saxon 9.3 EE,它只在内存中保留尽可能多的信息来解决查询.
  • 使用 XML 数据库,例如 MarkLogiceXist.
  • 使用一个 XML 文件列出其他 XML 文件的名称,一些用 XQuery 或 XSLT 编写的程序然后使用 doc() 函数读取并处理这些文件.(除非您的处理器正在流式传输或有办法处理它完成的文档,如 DDXQSaxon 这样做,您仍然会遇到相同大小的问题.)
  • Use a streaming XML processor, such as DataDirect XQuery (or to a lesser extent, Saxon 9.3 EE, which only keeps as much information in memory as necessary to solve the query.
  • Use an XML database, such as MarkLogic or eXist.
  • Use one XML file to list the names of other XML files, which some program written in XQuery or XSLT then reads using the doc() function and processes. (Unless your processor is streaming or has a way to dispose of documents it is finished with, as DDXQ or Saxon do, you will still run into the same size problem through.)

这篇关于XML - 引用其他 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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