First we define the root document:
val root = <root> <sub> <keep /> <replace /> <keeptoo /> </sub> </root>.convert val inserted = <inserted key="value"> <foo>foo</foo> <bar>bar</bar> </inserted>.convert
then we get the element:
val replace = root \\ 'replace
and finally we get xml with the updated <replace/> node:
replace.updated(0, inserted).unselect
if we get multiple <replace/> nodes, we can iterate over replace to update each node.
David source share