Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. copy Xml to Xml files

copy Xml to Xml files

Scheduled Pinned Locked Moved C#
xmlhelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    ytubis
    wrote on last edited by
    #1

    Hi! i am trying to copy nodes from one xml to another, i am doing a simple action, appending the first xml the node that i want from the other xml using the XmlNodeList(specific node). I always get the error that this node belongs to another xml document: "the node to be inserted is from a diffrent document content" how should i do this copy?? Thanks :)

    C H 2 Replies Last reply
    0
    • Y ytubis

      Hi! i am trying to copy nodes from one xml to another, i am doing a simple action, appending the first xml the node that i want from the other xml using the XmlNodeList(specific node). I always get the error that this node belongs to another xml document: "the node to be inserted is from a diffrent document content" how should i do this copy?? Thanks :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You need to create a new node and copy it into the new document, otherwise, the same node ( as it's passed by reference ) is in two documents, and this is verboten.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • Y ytubis

        Hi! i am trying to copy nodes from one xml to another, i am doing a simple action, appending the first xml the node that i want from the other xml using the XmlNodeList(specific node). I always get the error that this node belongs to another xml document: "the node to be inserted is from a diffrent document content" how should i do this copy?? Thanks :)

        H Offline
        H Offline
        Hessam Jalali
        wrote on last edited by
        #3

        You must first Import the node from another doc to yours,you can do that using ImportNode method from from XmlDocumrent instance so it would be somewhat like this and if you want to create a whole new coy of your node pass deep argument as true otherwise just the selected node would be impoterd not the childs

        XmlDocument doc1 = new XmlDocument();
        doc1.AppendChild(doc1.CreateElement("MyElement"));
        doc1.Save(@"N:\doc1.xml");

        XmlDocument doc2 = new XmlDocument();
        XmlNode importedNode = doc2.ImportNode(doc1["MyElement"], true);
        doc2.AppendChild(importedNode);
        doc2.Save(@"N:\doc2.xml");

        good luck

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups