Saturday, 27 December 2014

moving elemnts from XML FILE to Another XML file



I Have two XML files which have the following elements insite them (the item element and its child only) :



<cat id="computer">
<item>
<SN>value</SN>
<name>value</name>
<quantity>value</quantity>
<description>value </description>
<price>value </price>
</item>
</cat>
<cat id="Stationery">
<item>
<SN>value</SN>
<name>value</name>
<quantity>value</quantity>
<description>value </description>
<price>value </price>
</item>
</cat>


//I have here the following code which delete those elements (the item element and its child only).



xmlDoc.Root.Descendants("cat").Where(x => x.Attribute("id").Value == "computer")
.Descendants("item").Where(x => x.Element("SN").Value.Trim() == Dropdownlist.Text)
.Remove();
xmlDoc.Save(@"YourXML.xml");


what I want is to copy these elements from first xml file to the second xml file before deleting them. how can I do such process using LINQ ?


No comments:

Post a Comment