XNodeEqualityComparer.Equals(XNode, XNode) 方法

定義

比較兩個節點的值。

public:
 virtual bool Equals(System::Xml::Linq::XNode ^ x, System::Xml::Linq::XNode ^ y);
public bool Equals (System.Xml.Linq.XNode x, System.Xml.Linq.XNode y);
public bool Equals (System.Xml.Linq.XNode? x, System.Xml.Linq.XNode? y);
override this.Equals : System.Xml.Linq.XNode * System.Xml.Linq.XNode -> bool
Public Function Equals (x As XNode, y As XNode) As Boolean

參數

x
XNode

要比較的第一個 XNode

y
XNode

要比較的第二個 XNode

傳回

Boolean,指示節點是否相等。

實作

範例

下列範例會使用此類別來比較兩個節點。

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")  
);  
XNodeEqualityComparer equalityComparer = new XNodeEqualityComparer();  
Console.WriteLine(equalityComparer.Equals(xmlTree1, xmlTree2));  
xmlTree2.Add(new XElement("NewChild", "new content"));  
Console.WriteLine(equalityComparer.Equals(xmlTree1, xmlTree2));  

這個範例會產生下列輸出:

True  
False  

備註

下列準則會判斷兩個節點是否相等:

  • 節點 null 等於另一個 null 節點,但不等於非 null 節點。

  • 不同類型的兩 XNode 個物件永遠不相等。

  • 如果兩 XText 個節點包含相同的文字,則兩個節點相等。

  • 如果兩 XElement 個節點具有相同的標籤名稱、具有相同值的屬性集,而且 (忽略批註和處理指示) ,則兩個節點會包含兩個相同長度的同長度內容節點序列。

  • 如果兩 XDocument 個物件的根節點相等,則兩個物件相等。

  • 如果兩 XComment 個節點包含相同的註解文字,則兩個節點相等。

  • 如果兩 XProcessingInstruction 個節點具有相同的目標和資料,則兩個節點相等。

  • 如果 具有相同的名稱、公用識別碼、系統識別碼和內部子集,則兩 XDocumentType 個節點相等。

適用於

另請參閱