Wednesday, 10th March 2010     Good Afternoon Register | Login  
MODULES
MODULES
SKINS
SKINS
NEWS
NEWS
FORUMS
FORUMS
FEEDBACK
FEEDBACK

View Article
 
 

Current Articles | Categories | Search | Syndication

Sunday, March 12, 2006
XML createElement inserting xmlns="" on child elements. How do I stop this?
By SuperUser Account @ 2:39 AM :: 1263 Views ::

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="".

Comments
Currently, there are no comments. Be the first to post one!
Click here to post a comment
   

     
Copyright 2005 - 2009 24DNN.com   |  Terms of Use  |  Privacy Statement
Page generated in 0.65625 seconds.