我有一个如下的 XML 树:
<root>
<a>
<a1>A1</a1>
<a2>A2</a2>
...
...
<an>An</an>
</a>
<b>
<b1>B1</b1>
<b2>B2</b2>
...
...
<bm>Bm</bm>
</b>
<x>
<x1>X1</x1>
<x2>X2</x2>
...
...
</x>
<y>
...
...
</y>
...
...
</root>
使用 Oracle XMLQuery 和 XQuery,我想将此 XML 更改为:
<root>
<a>
<a1>A1</a1>
<a2>A2</a2>
...
...
<an>An</an>
<b>
<b1>B1</b1>
<b2>B2</b2>
...
...
<bm>Bm</bm>
</b>
</a>
<x> <!-- This x node and all its siblings have to stay where they are. -->
<x1>X1</x1>
<x2>X2</x2>
...
...
</x>
<y>
...
...
</y>
...
...
</root>
简而言之,我想通过附加将整个b
节点及其后代放在下面。a
到目前为止,我尝试过的是:
WITH xdata AS (
SELECT XMLTYPE('<root>
<a>
<a1>A1</a1>
<a2>A2</a2>
</a>
<b>
<b1>B1</b1>
<b2>B2</b2>
</b>
<x>
<x1>X1</x1>
<x2>X2</x2>
</x>
</root>') AS xmldata
FROM dual
)
SELECT XMLQuery ('for $a in $x1/root/a, $b in $x1/root/b
return <root>{$a}{$b}</root>'
PASSING x.xmldata AS "x1" RETURNING CONTENT) AS output
FROM xdata x;
这显然给了我一个非常错误的结果。也许我正在尝试的是完全错误的。请帮忙。