XNode.DeepEquals(XNode, XNode) 方法

定義

比較兩個節點的值,包括所有子系節點的值。Compares the values of two nodes, including the values of all descendant nodes.

public:
 static bool DeepEquals(System::Xml::Linq::XNode ^ n1, System::Xml::Linq::XNode ^ n2);
public static bool DeepEquals (System.Xml.Linq.XNode n1, System.Xml.Linq.XNode n2);
static member DeepEquals : System.Xml.Linq.XNode * System.Xml.Linq.XNode -> bool
Public Shared Function DeepEquals (n1 As XNode, n2 As XNode) As Boolean

參數

n1
XNode

要比較的第一個 XNodeThe first XNode to compare.

n2
XNode

要比較的第二個 XNodeThe second XNode to compare.

傳回

如果兩個節點相等則為 true,否則為 falsetrue if the nodes are equal; otherwise false.

範例

下列範例會使用這個方法來比較兩個 XML 樹狀結構。The following example uses this method to compare two XML trees.

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));  
Dim xmlTree1 As XElement = _   
        <Root Att1="1" Att2="2">  
            <Child1>1</Child1>  
            <Child2>some content</Child2>  
        </Root>  
  
Dim xmlTree2 As XElement = _   
        <Root Att1="1" Att2="2">  
            <Child1>1</Child1>  
            <Child2>some content</Child2>  
        </Root>  
  
Console.WriteLine(XNode.DeepEquals(xmlTree1, xmlTree2))  

這個範例會產生下列輸出:This example produces the following output:

True  

備註

下列準則會判斷兩個節點是否相等:The following criteria determine whether two nodes are equal:

  • null 節點等於另一個 null 節點,但與非null 節點不相等。A null node is equal to another null node but unequal to a non-null node.

  • 不同類型的兩個 XNode 物件絕對不會相等。Two XNode objects of different types are never equal.

  • 如果兩個 XText 節點包含相同的文字,則相等。Two XText nodes are equal if they contain the same text.

  • 如果兩個 XElement 節點具有相同的標記名稱、相同的屬性集(具有相同的值),以及(忽略批註和處理指示)包含相等內容節點的兩個相等長度序列,則兩者相等。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.

  • 如果兩個 XDocument 節點的根節點相等,則兩者相等。Two XDocument nodes are equal if their root nodes are equal.

  • 如果兩個 XComment 節點包含相同的註解文字,則相等。Two XComment nodes are equal if they contain the same comment text.

  • 如果兩個 XProcessingInstruction 節點具有相同的目標和資料,則相等。Two XProcessingInstruction nodes are equal if they have the same target and data.

  • 如果具有相同的名稱、公用識別碼、系統識別碼和內部子集,兩個 XDocumentType 節點相等。Two XDocumentType nodes are equal if the have the same name, public ID, system ID, and internal subset.

適用於

另請參閱