string xml1 = @"<NewDataSet><Table1 Email=""admin @domain.com"" Application=""SKREPO"" /> <Table1 Email = ""Test@domain.com"" Application = ""SKREPO"" /></NewDataSet>";
XDocument xdoc1 = new XDocument();
xdoc1 = XDocument.Parse(xml1);// load xml string
string xml2 = @"<OutParamDataSet><OutputParameters Result1=""Test12"" /> </OutParamDataSet> ";
XDocument xdoc2 = new XDocument();
xdoc2 = XDocument.Parse(xml2);// load xml string
foreach (XElement element in xdoc2.Descendants("OutParamDataSet"))
{
if (element.Name.LocalName.ToString() == "OutParamDataSet")
{
foreach (XElement elementn in element.Nodes())
{
if (elementn.Name.LocalName.ToString() == "OutputParameters")
{
XElement nxel = new XElement("OutputParameters",
new XAttribute("Result1", elementn.Attributes("Result1").First().Value));
XElement root = xdoc1.Element("NewDataSet");
root.Add(nxel);
}
}
}
TextBox3.Text = xdoc1.ToString();
}
Best Regards,
Yohann Lu
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
186 Points
357 Posts
Merge two xml elements
Jun 22, 2016 01:13 PM|maheshvishnu|LINK
What is the best way to merge the below two elements
<NewDataSet>
<Table1 Email="admin@domain.com" Application="SKREPO" />
<Table1 Email="Test@domain.com" Application="SKREPO" />
</NewDataSet>
<OutParamDataSet>
<OutputParameters Result1="Test12" />
</OutParamDataSet>
My output should be like
<NewDataSet>
<Table1 Email="admin@domain.com" Application="SKREPO" />
<Table1 Email="Test@domain.com" Application="SKREPO" />
<OutputParameters Result1="Test12" />
</NewDataSet>
Star
11464 Points
2439 Posts
Re: Merge two xml elements
Jun 23, 2016 08:03 AM|Yohann Lu|LINK
Hi maheshvishnu,
You can try the following code.
Best Regards,
Yohann Lu
Member
186 Points
357 Posts
Re: Merge two xml elements
Jun 24, 2016 04:42 AM|maheshvishnu|LINK