在另一个XML文件中包含一个XML文件 [英] including one XML file in another XML file

查看:65
本文介绍了在另一个XML文件中包含一个XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个XML文件包含到另一个XML文件中(在客户端上

方面,在Firefox中)?


我认为XInclude就是什么我需要,但Firefox并不支持它:
https://bugzilla.mozilla.org/show_bug.cgi?id=201754


看来我也可以使用外部实体参考,但是

取决于DTD,我正在使用XML Schema。是否也可以使用

架构,我该怎么做?


这正是我想要做的:


design.xml:

<?xml .....>

< root>

< design> ....< / design>

< library> ....< / library>

< / root>


目前''library''元素位于''design.xml''文件中。我想要将库元素放入一个单独的xml文件中,并在我的所有设计文件中包含

。 (我有很多设计,只有一些

的库)。


design.xml文件包含对
可视化设计。当您在Firefox中打开design.xml文件时,会立即创建一个

SVG(可缩放矢量图形)文件并显示为

you。


我还有一个XML Schema文件,它指定了design.xml文件中所有有效的

元素是什么。


可以有人给我看一个完成这个的例子?那将是

很棒。


谢谢,Johan。

How can I include one XML file into another XML file (on the client
side, in Firefox)?

I think XInclude is just what I need, but Firefox doesn''t support it:
https://bugzilla.mozilla.org/show_bug.cgi?id=201754

It seems I also can use an "external entity reference", but that
depends on a DTD and I''m using XML Schema. Is it also possible with a
Schema and how can I do it?

Here is exactly what I''m trying to do:

design.xml:
<?xml .....>
<root>
<design>....</design>
<library>....</library>
</root>

Currently the ''library'' element is inside the ''design.xml'' file. I
want to put the library element into a separate xml file and include
it in all my design files. (I have a lot of designs and only a couple
of libraries).

The design.xml file contains a reference to an XSLT file that
visualizes the design. When you open the design.xml file in Firefox a
SVG (scalable vector graphics) file is created on the fly and shown to
you.

I also have an XML Schema file that specifies what all the valid
elements in the design.xml file are.

Can someone show me an example that accomplishes this? That would be
great.

thanks, Johan.

推荐答案

如何将一个XML文件包含到另一个XML文件中(在客户端
How can I include one XML file into another XML file (on the client

side,在Firefox中)?
side, in Firefox)?



我是XML的新手,但让我来回答这个问题。

取决于你想要什么客户端要处理文档,它好像你可以在样式表级别完成这个工作

使用document()。


design.xml

<?xml ...>

< root>

< design ...< ; / design>

< library />

< / root>


library.xml

<?xml ...>

< library>

....

< / library>


stylesheet.xml

<?xml version =" 1.0">

< xsl:stylesheet。 ..>

< xsl:template match =" root">

< xsl:apply-templates select =" design" />

< xsl:apply-templates select =" document(library.xml)/" />

< / xsl:template>

< / xsl:stylesheet>


我可能没有正确的语法,但我希望你能理解。

当样式表应用于design.xml时,处理器将获得
访问并处理外部文件好像是源的一部分

文件。有关详细信息,请参阅处理多个

文档的XSL部分: http://www.w3.org/TR/xslt#document


祝你好运!

I''m kind of new to XML, but let me take a stab at answering this.
Depending on what you want the client to do with the document, it
seems you might be able to accomplish this at the stylesheet level
using document().

design.xml
<?xml ...>
<root>
<design... </design>
<library/>
</root>

library.xml
<?xml ...>
<library>
....
</library>

stylesheet.xml
<?xml version="1.0">
<xsl:stylesheet ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="document(library.xml)/"/>
</xsl:template>
</xsl:stylesheet>

I might not have the syntax quite right, but I hope you get the idea.
When the stylesheet is applied to design.xml, the processor will
access and handle the external file as if it were part of the source
document. For further info see the XSL section on handling multiple
documents: http://www.w3.org/TR/xslt#document

Good luck!


2月21日上午11:45,Johan < joh ... @ gmail.comwrote:
On Feb 21, 11:45 am, "Johan" <joh...@gmail.comwrote:

design.xml:

<?xml .....>

< root>

< design> ....< / design>

< library> ....< ; / library>

< / root>


目前''库''元素在

''里面design.xml''文件。我想将库元素放入

一个单独的xml文件中并将其包含在我的所有设计中。

文件。 (我有很多设计,只有几个

库)。


design.xml文件包含对XSLT文件的引用

可视化设计。
design.xml:
<?xml .....>
<root>
<design>....</design>
<library>....</library>
</root>

Currently the ''library'' element is inside the
''design.xml'' file. I want to put the library element into
a separate xml file and include it in all my design
files. (I have a lot of designs and only a couple of
libraries).

The design.xml file contains a reference to an XSLT file
that visualizes the design.



我不相信你想要的东西是可能的,但有其他解决方案可以解决这个问题; XSLT方面的document()

特别想到了。概念验证:


xform1.xml:


<?xml-stylesheet type =" text / xsl" href =" xform.xsl"?>

< root library =" 1">

< design> 1< / design>

< / root>


xform_lib_1.xml:


< library>

< design n =" 1"> A< / design>

< / library>


xform.xsl:


< xsl:stylesheet version =" 1.0"

xmlns:xsl =" http://www.w3.org/1999/XSL/Transform"> ;

< xsl:variable

name =" lib"

select =

"

文件(concat(''xform_lib _'',/ root / @ library,''。xml''))

" />

< xsl:template match =" root">

< result>

< xsl:apply-templates />

< / result>

< / xsl:template>

< xsl:template match =" design">

< xsl:value-of

select ="

I don''t believe what you want is possible, but there are
other solutions to the problem; document() on the XSLT side
in particular comes to mind. Proof-of-concept:

xform1.xml:

<?xml-stylesheet type="text/xsl" href="xform.xsl"?>
<root library="1">
<design>1</design>
</root>

xform_lib_1.xml:

<library>
<design n="1">A</design>
</library>

xform.xsl:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="lib"
select=
"
document(concat(''xform_lib_'',/root/@library,''.xml''))
"/>
<xsl:template match="root">
<result>
<xsl:apply-templates/>
</result>
</xsl:template>
<xsl:template match="design">
<xsl:value-of
select="


lib / library / design [@n = current()]" />

< / xsl:template>

< / xsl:stylesheet>


请注意,除非您非常了解自己在做什么,否则客户端转换通常应该避免
。所以,

除非你非常了解你在做什么,考虑

改变你的文件服务器端。


-

Pavel Lepin

lib/library/design[@n=current()]"/>
</xsl:template>
</xsl:stylesheet>

Note that client-side transformations in general should be
avoided, unless you know very well what you''re doing. So,
unless you know very well what you''re doing, consider
transforming your document server-side.

--
Pavel Lepin


这篇关于在另一个XML文件中包含一个XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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