Since XML documents and nodes are almost always handled 'by-reference' if you want to keep an original untouched when adding nodes etc, you need to make an unlinked copy of it.

xml_duplicate(x)

Arguments

x

xml document

Value

new, unlinked xml document