public static void Main()
XElement xmlTree = new XElement("Root",
new XElement("GrandChild1", 1),
new XElement("GrandChild2", 2),
new XElement("GrandChild3", 3)),
new XElement("GrandChild1", 1),
new XElement("GrandChild2", 2),
new XElement("GrandChild3", 3)));
Console.WriteLine(AreEqual(xmlTree.Element("Child1"), xmlTree.Element("Child2")));
Console.WriteLine(AreEqual(xmlTree.Element("Child1"), xmlTree.XPathSelectElement("Child1")));
private static bool AreEqual(XElement element, XElement another)
return element.AncestorsAndSelf().All(another.AncestorsAndSelf().Contains);