XNodeDocumentOrderComparer.Compare(XNode, XNode) 메서드

정의

두 노드를 비교하여 상대적인 문서 순서를 확인합니다.

public:
 virtual int Compare(System::Xml::Linq::XNode ^ x, System::Xml::Linq::XNode ^ y);
public int Compare (System.Xml.Linq.XNode x, System.Xml.Linq.XNode y);
public int Compare (System.Xml.Linq.XNode? x, System.Xml.Linq.XNode? y);
abstract member Compare : System.Xml.Linq.XNode * System.Xml.Linq.XNode -> int
override this.Compare : System.Xml.Linq.XNode * System.Xml.Linq.XNode -> int
Public Function Compare (x As XNode, y As XNode) As Integer

매개 변수

x
XNode

비교할 첫 번째 XNode입니다.

y
XNode

비교할 두 번째 XNode입니다.

반환

Int32

노드가 서로 같으면 0, xy보다 앞에 나오면 -1, xy보다 뒤에 나오면 1이 들어 있는 Int32입니다.

구현

예외

두 노드가 공통 상위 노드를 공유하지 않는 경우

예제

다음 예제에서는 이 클래스를 사용하여 두 노드의 문서 순서를 비교합니다.

XElement xmlTree = new XElement("Root",  
    new XText("Text content."),  
    new XElement("Child1", "child1 content"),  
    new XElement("Child2", "child2 content"),  
    new XElement("Child3", "child3 content"),  
    new XText("More text content."),  
    new XElement("Child4", "child4 content"),  
    new XElement("Child5", "child5 content")  
);  
XElement child3 = xmlTree.Element("Child3");  
XElement child5 = xmlTree.Element("Child5");  
XNodeDocumentOrderComparer documentOrderComparer = new XNodeDocumentOrderComparer();  
int val = documentOrderComparer.Compare(child3, child5);  
if (val == 0)  
    Console.WriteLine("Child3 is same as Child5");  
else if (val < 0)  
    Console.WriteLine("Child3 is before Child5");  
else  
    Console.WriteLine("Child3 is after Child5");  

이 예제는 다음과 같은 출력을 생성합니다.

Child3 is before Child5  

설명

이 클래스를 직접 사용하는 대신 메서드를 InDocumentOrder 사용하는 것이 좋습니다. 이 클래스는 해당 메서드에서 내부적으로 사용됩니다.

적용 대상

추가 정보