Changing Namespace Declarations in an XML Document
The XmlDocument exposes namespace declarations and xmlns attributes as part of the document object model. These are stored in the XmlDocument, so when you save the document, it can preserve the location of those attributes. Changing these attributes has no affect on the Name, NamespaceURI, and Prefix properties of other nodes already in the tree. For example, if you load the following document, then the test
element has NamespaceURI 123.
<test xmlns="123"/>
If you remove the xmlns
attribute as follows, then the test
element still has the NamespaceURI of 123
.
doc.documentElement.RemoveAttribute("xmlns")
doc.documentElement.RemoveAttribute("xmlns");
Likewise, if you add a different xmlns
attribute to the doc
element as follows, then the test
element still has NamespaceURI 123
.
doc.documentElement.SetAttribute("xmlns","456")
doc.documentElement.SetAttribute("xmlns","456");
Therefore, changing xmlns
attributes will have no affect until you save and reload the XmlDocument object.
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for