XQuery:将一个 XML 文档插入到第二个 XML 文档中



我有 2 个单独的 XML 文件,如下所示。第一个 XML 文档仅包含一个标记。

<office>HeadOffice</office>

第二份文件:

<Data>
<location>
<city>London</city>
<country>England</country>
<region>Europe</region>
</location>
<services>
<consulting>SAP</consulting>
<industry>Oil</industry>
</services>
</Data>

我想做的是将第一个文档(单个标签(插入到第二个 XML 文档中,以便结果如下。请注意,第一个文档仅插入标签内。

<Data>
<location>
<city>London</city>
<country>England</country>
<region>Europe</region>
<office>HeadOffice</office>
</location>
<services>
<consulting>SAP</consulting>
<industry>Oil</industry>
</services>
</Data>

不幸的是,我不能为此使用 XQuery 更新工具规范,即我不能使用:

insert node<office>HeadOffice</office> into $data/location

我将如何做到这一点?除了使用"插入节点"方法之外,我似乎找不到任何东西。任何帮助将不胜感激。

干杯 杰

您可以编写一个 typeswitch 转换,它将以您想要的方式将两者组合成一个新文档。有关示例,请查看: https://en.wikibooks.org/wiki/XQuery/Typeswitch_Transformations

最新更新