I have a document structured like this:
<INVT_DATA xmlns="http://www.mrbook.com/InventoryData">
<AUTHOR>...</AUTHOR>
<TITLE>...</TITLE>
<PUBLISHER>...</PUBLISHER>
</INVT_DATA>
Subchildren of INVT_DATA are always elements and not text nodes. I would like to use XQuery to compare a new document with the same structure. If a subelement is present in the new and the original, it should be replaced. If a subelement is present in the new, but is not in the old, it should be appended to INVT_DATA.
This XQuery, I think, would work, but it always seems to just append nodes instead:
declare namespace invtdata="http://www.mrbook.com/InventoryData";
copy $oldInvtData := $oldXml
modify
(
for $mpf in $newXml/invtdata:INVT_DATA/*
let $oldMpf := $oldInvtData/invtdata:INVT_DATA/*[name()=name($mpf)]
return if(exists($oldMpf)) then
replace node $oldMpf with $mpf
else insert node $mpf into $oldInvtData
)
return $oldInvtData
I searched for other similar problems and found this, but that is quite a bit of overkill for what I want to do. Any suggestions? If it helps, I am using XmlQuery from the Oracle XML DB, version 11.2.0.3.
This turns out to be the correct code.... just one minor tweak.
Thanks for the help!