Reputation: 19
I have been trying to replace one element (and it's sub elements) with the content from another XML file with the same element.
Example:
FileA:
<A>
<B id="1">
// more sub elements
</B>
<B id="2">
// more sub elements
</B>
</A>
FileB
<A>
<B id="1">
// other sub elements than FileA has
</B>
</A>
From this source: http://docs.basex.org/wiki/XQuery_Update
I tried the following:
copy $c := doc('FileA')
modifiy (
replace node $c/A/B[@id='1'] with element doc('FileB')/A/B[@id='1']
)
return $c
This is not supported bye Qt's xmlpatterns. I have tried different versions of the code above, but without luck. I am already using XQuery for getting parts of XML files, but I have not found a solution on how to do this.
Maybe Qt's tools dosent support it? I can't find anything on Qt's pages on how to do something similar (xmlprocessing).
Upvotes: 1
Views: 501
Reputation: 38702
XQuery Update is an addition to XQuery. From what the Qt 5 XQuery documentation describes, XQuery Update is not supported.
As there is no support for modifying elements without XQuery Update, you'll have to reconstruct the whole tree applying some modifications. For general usage, this can be achieved with a common XQuery pattern with a kind of copy
function, but for the rather simple structure without nested elements you can do easier without a function by hard-coding the structure.
<A>{
for $B-fileA in doc('/tmp/a.xml')/A/B
let $B-fileB := doc('/tmp/b.xml')/A/B[@id = $B-fileA/@id]
return
if ( $B-fileB )
then $B-fileB
else $B-fileA
}</A>
Alternatively, you could rely on an XQuery implementation with support for XQuery Update. Both Saxon, BaseX and probably others provide C++ language bindings or implementations.
Upvotes: 1