Прочитај на енглеском Уреди

Делите путем


XNode.DeepEquals(XNode, XNode) Method

Definition

Compares the values of two nodes, including the values of all descendant nodes.

C#
public static bool DeepEquals(System.Xml.Linq.XNode n1, System.Xml.Linq.XNode n2);
C#
public static bool DeepEquals(System.Xml.Linq.XNode? n1, System.Xml.Linq.XNode? n2);

Parameters

n1
XNode

The first XNode to compare.

n2
XNode

The second XNode to compare.

Returns

true if the nodes are equal; otherwise false.

Examples

The following example uses this method to compare two XML trees.

C#
XElement xmlTree1 = new XElement("Root",  
    new XAttribute("Att1", 1),  
    new XAttribute("Att2", 2),  
    new XElement("Child1", 1),  
    new XElement("Child2", "some content")  
);  
XElement xmlTree2 = new XElement("Root",  
    new XAttribute("Att1", 1),  
    new XAttribute("Att2", 2),  
    new XElement("Child1", 1),  
    new XElement("Child2", "some content")  
);  
Console.WriteLine(XNode.DeepEquals(xmlTree1, xmlTree2));  

This example produces the following output:

True  

Remarks

The following criteria determine whether two nodes are equal:

  • A null node is equal to another null node but unequal to a non-null node.

  • Two XNode objects of different types are never equal.

  • Two XText nodes are equal if they contain the same text.

  • Two XElement nodes are equal if they have the same tag name, the same set of attributes with the same values, and (ignoring comments and processing instructions) contain two equal length sequences of equal content nodes.

  • Two XDocument nodes are equal if their root nodes are equal.

  • Two XComment nodes are equal if they contain the same comment text.

  • Two XProcessingInstruction nodes are equal if they have the same target and data.

  • Two XDocumentType nodes are equal if the have the same name, public ID, system ID, and internal subset.

Applies to

Производ Верзије
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also