Problem description: Read an xml file, traverse to a particular node (element), if it does not have a particular namespace declaration, add the required namespace declaration, and write out the file.
I need to do this in C++ using Microsoft's MSXML DOM APIs. The namespaceURI property on IXMLDOMNode COM object is read-only according to this msdn reference. Appreciate any workarounds.
Edit: I spent quite some time on a workaround: Create a new sibling node in the same document with the namespace I need, then move all the child elements of the original node to this new node, then delete the original node. Well, this does not work, because the child nodes are going to keep whatever default namespace they had before.
And then this simple idea hit me and it works but I am not sure if it will bite me in the future: just create an "xmlns" attribute on the element, giving it the desired namespace value! Any comments?