|
This happens when the document you are working is using namespaces, but new nodes are being created using the non namespace-aware DOM level 1 functions.
In this case DOM assumes they are in the "empty" namespace, and correctly inserts this namespace declararation. Use createNode instead, specifying the proper namespaceURI for the new element (it knows about namespace handling).
For example if you need to add a new node to the system.web of our portals web.config file.
VB Example Code: Private Sub buildNode(ByRef InnerNode As XmlNode) Dim xmlDoc As New XmlDocument Dim attribute1 As XmlAttribute = Me.xmlDoc.CreateAttribute("name") attribute1.Value = "HTTPHandler_MyModule" Dim attribute2 As XmlAttribute = Me. xmlDoc.CreateAttribute("type") attribute2.Value = "MyCompany.DNN.Modules.ModuleName" Dim node1 As XmlNode = Me. xmlDoc.CreateNode(XmlNodeType.Element, "add", "http://schemas.microsoft.com/.NetConfiguration/v2.0") node1.Attributes.Append(attribute1) node1.Attributes.Append(attribute2) InnerNode.AppendChild(node1)
End Sub
This will take care of any empty and unneeded xmlns="". |