Forums » Saxon/C Help and Discussions »
Set XdmNode values
Added by Paul Greve about 1 month ago
Hi,
We're using SaxonC 12 to parse XML source documents. We have the need to be able to change (set) element, attribute and namespace URI values in the DOM so that the new values will appear in the serialized XML. Is there a way to set element, attribute or namspace URI values via the XdmNode class. The only function that looks promising is addXdmValueWithType() but it's unclear if that's the purpose of that function.
Replies (2)
RE: Set XdmNode values - Added by Michael Kay about 1 month ago
Generally speaking, XDM nodes are immutable, so the answer is no. (The fact that the tree is immutable is what enables Saxon's TinyTree to be so much faster than the DOM).
There's another significant problem with the mutable DOM in that it allows you to create inconsistent trees that Saxon can't cope with, for example where namespace URIs used for element names aren't backed by namespace declaration attributes.
In fact some implementations of the XDM tree do support mutation - notably the LinkedTree, used to support XQuery Update. But the API is really an internal one designed to reflect the quirks of XQuery Update and I wouldn't recommend using it outside that environment.
I would suggest not trying to "go against the grain" on this one, and do any updates you need through an XSLT transformation.
RE: Set XdmNode values - Added by Paul Greve about 1 month ago
Thanks for your response. Shortly after posting the question, I found a similar older question on the topic; so I apologize for that.
Please register to reply