Mega Code Archive

 
Categories / C# Tutorial / XML
 

Create XNodeEqualityComparer

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; using System.Xml.Linq; using System.IO; public class MainClass{    public static void Main(string[] args){          XDocument NewDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),new XElement("Root", "MyDoc"));         NewDoc.Element("Root").Add(             new XElement("One", "Hello"),             new XElement("Two", "Hello"),             new XElement("Three", "Goodbye"));       XNodeEqualityComparer Comp = new XNodeEqualityComparer();       XElement First = NewDoc.Element("Root").Element("One");       XElement Second = NewDoc.Element("Root").Element("One");       bool Result = Comp.Equals(First, Second);       Console.WriteLine("Result");         XElement Third = NewDoc.Element("Root").Element("Two");       Result = Comp.Equals(First, Third);       Console.WriteLine("Result");          } }