I have Oracle12 and two XML and want to merge them into one preferably using xQuery.
If 2nd XML have new nodes then they must be added.
In addition, if possible, if the node matches then change its value.
If this cannot be done with a XML of any kind, let's limit to comparing the contents of only the top-level nodes.
Something like
with t as (select
XMLType(
'<root>
<node1>
<data1>1</data1>
</node1>
<node2>
<data2>2</data2>
</node2>
<node3>
<data3>3</data3>
</node3>
</root>) oldx,
XMLType(
'<root>
<node1>
<data1>11</data1>
<data12>12</data2>
</node1>
<node3>
<data33>33</data33>
<data34>34</data34>
</node3>
</root>) newx from dual)
select oldx, newx
--,xmlquery('copy $t := $x1 modify (for $i in $t when matched replace value of node $i with $x2 when not matched return insert node $x2 into $i) return $t' passing oldx as "x1", newx as "x2" returning content)
from t
the result must be
<root>
<node1>
<data1>11</data1>
<data12>12</data2>
</node1>
<node2>
<data2>2</data2>
</node2>
<node3>
<data3>3</data3>
<data33>33</data33>
<data34>34</data34>
</node3>
</root>