Results 1 to 3 of 3

Thread: XML Node Clone

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274

    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

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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:
    1. Imports System
    2. Imports System.Xml
    3. Module MainApp
    4.  
    5.     Sub Main()
    6.         Dim deepCopy As Boolean = True
    7.         Dim doc1 As New XmlDocument
    8.         doc1.LoadXml("<Whatever/>")
    9.         Dim doc2 As New XmlDocument
    10.         doc2.LoadXml("<Blah/>")
    11.         Dim importedNode As XmlNode
    12.         importedNode = doc1.ImportNode(doc2.DocumentElement, deepCopy)
    13.         doc1.DocumentElement.AppendChild(importedNode)
    14.         Console.WriteLine(doc1.OuterXml)
    15.         Console.ReadLine()
    16.     End Sub
    17.  
    18. End Module

  3. #3

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    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
  •  



Click Here to Expand Forum to Full Width