Compare two XElement in CSharp

Description

The following code shows how to compare two XElement.

Example


    /*w ww  .  ja v  a 2s.co m*/
using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;


public class MainClass{
   public static void Main(){
   
        XElement xmlTree = new XElement("Root",
            new XAttribute("Att1", 1),
            new XElement("Child1", 1),
            new XElement("Child2", 2)
        );
        XElement treeClone = new XElement(xmlTree);
        Console.WriteLine("xmlTree = treeClone: {0}", XNode.DeepEquals(xmlTree, treeClone));
        xmlTree.Add(new XElement("Child3", 3));
        Console.WriteLine("xmlTree = treeClone: {0}", XNode.DeepEquals(xmlTree, treeClone));
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style