How to Add Node Values from external xml file
-
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
-
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
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
-
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