|
-
Dec 27th, 2003, 10:19 AM
#1
Thread Starter
Hyperactive Member
XML Node Clone
I wrote a few lines of code to copy all the ndoes from one xml document to another and it was working fine on VB6. But when I tried to write the same code with a few modifications dealing with datatypes and a few methods, everything is working fine execpt for the appendChild line where I assign the new cloned node. It gives me an error that the node being appended belongs to another xml document. I am really out of ideas solving it. I would really appreciate if anybody could help. Thanks
-
Dec 27th, 2003, 10:37 AM
#2
Hyperactive Member
ya, that was frustrating for me as well when i was making the transition. Look at the ImportNode method of XmlDocument. Works something like this:
VB Code:
Imports System
Imports System.Xml
Module MainApp
Sub Main()
Dim deepCopy As Boolean = True
Dim doc1 As New XmlDocument
doc1.LoadXml("<Whatever/>")
Dim doc2 As New XmlDocument
doc2.LoadXml("<Blah/>")
Dim importedNode As XmlNode
importedNode = doc1.ImportNode(doc2.DocumentElement, deepCopy)
doc1.DocumentElement.AppendChild(importedNode)
Console.WriteLine(doc1.OuterXml)
Console.ReadLine()
End Sub
End Module
-
Dec 28th, 2003, 02:22 AM
#3
Thread Starter
Hyperactive Member
Thanks a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|