Tip of the day: AppendChildCopy
Sub AppendChildCopy(extends parent as XmlNode, other as XmlNode)
// parent document for creating new objects
dim doc as XmlDocument = parent.OwnerDocument
dim neu as XmlNode
// create matching type of node in new document
if other isa XmlTextNode then
neu = doc.CreateTextNode(other.Value)
elseif other isa XmlComment then
neu = doc.CreateComment(other.Value)
else
neu = doc.CreateElement(other.Name)
end if
// now copy all attributes
dim u as integer = other.AttributeCount-1
for i as integer = 0 to u
dim a as XmlAttribute = other.GetAttributeNode(i)
neu.SetAttribute(a.Name, a.Value)
next
// copy all children
dim c as XmlNode = other.FirstChild
while c <> nil
neu.AppendChildCopy c
c = c.NextSibling
wend
// and store new child
parent.AppendChild neu
End Sub
Useful? Comments? Problems? Your feedback is welcome!