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 / C++ / MFC
  4. How to copy One XMLdocument to another?

How to copy One XMLdocument to another?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhtmlxmltutorial
2 Posts 2 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.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    Hello Friends I am reading a xml file(suppose A.xml) using MSXML::IXMLDOMDocumentPtr and all related classes of MSXML. Now,I want to create another xml file with new data and want to replace with A.xml. Both xml will be having same Nodes but their child nodes can be different. Now,My question is Is there any way that I can store all the data in DomDocumentPtr object and then replace with it existing xml file Dom Pointer? Or do i need to create another xml on disc and then i have to replace one file with another file. Which way i can achieve this? Thanks and Regards Yogesh sikri

    A 1 Reply Last reply
    0
    • 0 002comp

      Hello Friends I am reading a xml file(suppose A.xml) using MSXML::IXMLDOMDocumentPtr and all related classes of MSXML. Now,I want to create another xml file with new data and want to replace with A.xml. Both xml will be having same Nodes but their child nodes can be different. Now,My question is Is there any way that I can store all the data in DomDocumentPtr object and then replace with it existing xml file Dom Pointer? Or do i need to create another xml on disc and then i have to replace one file with another file. Which way i can achieve this? Thanks and Regards Yogesh sikri

      A Offline
      A Offline
      App_
      wrote on last edited by
      #2

      XmlDocument::ImportNode does the job, It states and i quote: "The ImportNode method is the mechanism by which a node or entire node subtree is copied from one XmlDocument to another. The node returned from the call is a copy of the node from the source document, including attribute values, the node name, node type, and all namespace-related attributes such as the prefix, local name, and namespace Uniform Resource Identifier (URI). The source document is not changed. " more from MSDN.. Code from MSDN:

      #using <System.Xml.dll>

      using namespace System;
      using namespace System::IO;
      using namespace System::Xml;
      int main()
      {

      //Create the XmlDocument.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<bookstore><book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book></bookstore>" );

      //Create another XmlDocument which holds a list of books.
      XmlDocument^ doc2 = gcnew XmlDocument;
      doc2->Load( "books.xml" );

      //Import the last book node from doc2 into the original document.
      XmlNode^ newBook = doc->ImportNode( doc2->DocumentElement->LastChild, true );
      doc->DocumentElement->AppendChild( newBook );
      Console::WriteLine( "Display the modified XML..." );
      doc->Save( Console::Out );
      }

      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