Wrap XML tags (insert around existing xml data) in xquery for eXist
Can anyone please help me with this xquery for eXist database. I have the following xml s开发者_如何学JAVAtructure
<A>
<B>
<D/>
<D/>
<D/>
<E/>
</B>
</A>
I'm trying to get the following structure
<A>
<B>
<C>
<D/>
<D/>
<D/>
<E/>
</C>
</B>
</A>
How do I insert the <C>
tag?
Thanks
--SDI can't verify, but it should be so:
let $x := doc('namedocument.xml')/A/B
update insert <C>$x</C> into doc('namedocument.xml')/A/B
You don't need XQuery Update to do this kind of operations.
This XQuery application:
<A>
<B>
<C>
{for $n in /A/B/node()
return $n}
</C>
</B>
</A>
when applied on the provided XML document:
<A>
<B>
<D/>
<D/>
<D/>
<E/>
</B>
</A>
produces exactly the wanted, correct result:
<A>
<B>
<C>
<D/>
<D/>
<D/>
<E/>
</C>
</B>
</A>
精彩评论