在 Xquery 中创建具有两个属性的节点 [英] create a node with two attributes in Xquery

查看:25
本文介绍了在 Xquery 中创建具有两个属性的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下所示的 XML:

I have XML as given below:

<test>
<a>Hello</a>
</test>

我需要在 XQuery 中添加一个具有两个属性的新节点,预期输出为:

I need to add a new node with two attributes in XQuery and the expected output is:

<test>
<a>Hello</a>
<b att1="1" att2="2">World</b>
</test>

你能帮我解决这个问题吗?

Can you help me out with the XQquery for this?

推荐答案

使用 XQuery Update 和 BaseX,以下是解决方案 -

Using XQuery Update and BaseX, following will be the solution -

let $i := <b att1="1" att2="2">World</b>
for $x in doc('document1')/test
   return insert node $i after $x/a

这里我假设您已经在 BaseX 中创建了一个 XML 文档.

Here I have assumed that you have created a XML Doc in BaseX.

这篇关于在 Xquery 中创建具有两个属性的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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