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

노드가 서로 같은지 여부를 나타내는 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 노드의 대상과 데이터가 같으면 동일합니다.

  • 이름, 공용 ID, 시스템 ID 및 내부 하위 집합이 같으면 두 XDocumentType 노드가 동일합니다.

적용 대상

추가 정보