<?xml version="1.0" encoding="utf-8"?> <wpassetd> <Main> <data> <machinename><![CDATA[zomy]]></machinename> <scandate><![CDATA[03/23/2014 10:56:34]]></scandate> <guid><![CDATA[31c0841e-f7bf-4de1-9d75-7e9080498e6b-20141216020243430495]]></guid> <regid><![CDATA[2853611]]></regid> </data> </Main> </wpassetd> test2.xml: <?xml version="1.0" encoding="utf-8"?> <wpassetd> <Main> <data> <machinename><![CDATA[zomy]]></machinename> <scandate><![CDATA[03/23/2015 18:56:34]]></scandate> <guid><![CDATA[31c0841e-f7bf-4de1-9d75-7e9080498e6b-20141216020243430495]]></guid> <regid><![CDATA[2853622]]></regid> </data> </Main> </wpassetd> output.xml should be difference of test1.xml and test2.xml: <?xml version="1.0" encoding="utf-8"?> <wpassetd> <Main> <data> <scandate><![CDATA[03/23/2015 18:56:34]]></scandate> <regid><![CDATA[2853622]]></regid> </data> </Main> </wpassetd> using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Xml.Linq; namespace ConsoleApplication15 { class Program { static void Main(string[] args) { var doc1 = XDocument.Load(@"tanu1.xml"); var doc2 = XDocument.Load(@"tanu2.xml"); var dict = doc1.Root.Elements("parent").ToDictionary(el => el.Attribute("children").Value); doc2.Root.Elements("parent").ToList().ForEach(el => { XElement el2; if (dict.TryGetValue(el.Attribute("children").Value, out el2) && !el.Attributes().Select(a => new { a.Name, a.Value }).Except( el2.Attributes().Select(a => new { a.Name, a.Value })).Any()) el.Remove(); }); doc2.Save(@"file3.xml"); } } } it doesnot work well or i think i am somewhere wrong in accepting values as i am not that good coder. does any one has alternate to this?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)