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. XML / XSL
  4. How to Add Node Values from external xml file

How to Add Node Values from external xml file

Scheduled Pinned Locked Moved XML / XSL
xmltutorial
3 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.
  • S Offline
    S Offline
    srieen
    wrote on last edited by
    #1

    i need to add node values in a xml file like <country> <india> <states>1</states> <states>2</states> </india> <America> <value>xxx</value> <value>xxx</value> <value>xxx</value> </America> <Canada> i need to add an xml node from other xml file .... </Canada> </country> i need to add xmlnode value in Canada. it can be a nested node values and the source for canada is from other xmlfile i tryed with ImportRow method, but it appends in Root, (ie from i want to append data to <canada> .....</canada> Pls suggest

    G 1 Reply Last reply
    0
    • S srieen

      i need to add node values in a xml file like <country> <india> <states>1</states> <states>2</states> </india> <America> <value>xxx</value> <value>xxx</value> <value>xxx</value> </America> <Canada> i need to add an xml node from other xml file .... </Canada> </country> i need to add xmlnode value in Canada. it can be a nested node values and the source for canada is from other xmlfile i tryed with ImportRow method, but it appends in Root, (ie from i want to append data to <canada> .....</canada> Pls suggest

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      ImportRow is a DataTable method. If you are talking about XmlDocument, you can use the ImportNode method: using namespace System; using namespace System::Xml; int main(array ^args) { String^ srcXml = L"" L"" L"yyyy" L"" L""; XmlDocument^ srcDoc = gcnew XmlDocument(); srcDoc->LoadXml(srcXml); XmlNode^ srcNode = srcDoc->SelectSingleNode( L"/country/canada/lakes"); if (srcNode == nullptr) { Console::WriteLine(L"'lakes' node not found!"); return -1; } String^ destXml = L"" L"" L"1" L"2" L"" L"" L"xxx" L"xxx" L"xxx" L"" L"" L""; XmlDocument^ destDoc = gcnew XmlDocument(); destDoc->LoadXml(destXml); XmlNode^ importedNode = destDoc->ImportNode(srcNode, true); XmlNode^ destNode = destDoc->SelectSingleNode( L"/country/canada"); if (srcNode == nullptr) { Console::WriteLine(L"'canada' node not found!"); return -1; } destNode->AppendChild(importedNode); Console::WriteLine(destDoc->OuterXml); return 0; } "We make a living by what we get, we make a life by what we give." --Winston Churchill

      S 1 Reply Last reply
      0
      • G George L Jackson

        ImportRow is a DataTable method. If you are talking about XmlDocument, you can use the ImportNode method: using namespace System; using namespace System::Xml; int main(array ^args) { String^ srcXml = L"" L"" L"yyyy" L"" L""; XmlDocument^ srcDoc = gcnew XmlDocument(); srcDoc->LoadXml(srcXml); XmlNode^ srcNode = srcDoc->SelectSingleNode( L"/country/canada/lakes"); if (srcNode == nullptr) { Console::WriteLine(L"'lakes' node not found!"); return -1; } String^ destXml = L"" L"" L"1" L"2" L"" L"" L"xxx" L"xxx" L"xxx" L"" L"" L""; XmlDocument^ destDoc = gcnew XmlDocument(); destDoc->LoadXml(destXml); XmlNode^ importedNode = destDoc->ImportNode(srcNode, true); XmlNode^ destNode = destDoc->SelectSingleNode( L"/country/canada"); if (srcNode == nullptr) { Console::WriteLine(L"'canada' node not found!"); return -1; } destNode->AppendChild(importedNode); Console::WriteLine(destDoc->OuterXml); return 0; } "We make a living by what we get, we make a life by what we give." --Winston Churchill

        S Offline
        S Offline
        srieen
        wrote on last edited by
        #3

        thanks....

        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