XNode.IsAfter(XNode) メソッド

定義

ドキュメント順に基づいて、現在のノードを指定したノードの後に表示するかどうかを決定します。

public:
 bool IsAfter(System::Xml::Linq::XNode ^ node);
public bool IsAfter (System.Xml.Linq.XNode node);
public bool IsAfter (System.Xml.Linq.XNode? node);
member this.IsAfter : System.Xml.Linq.XNode -> bool
Public Function IsAfter (node As XNode) As Boolean

パラメーター

node
XNode

ドキュメント順を比較する XNode

戻り値

Boolean

指定したノードの後にこのノードを表示する場合は true。それ以外の場合は false

次の例では、このメソッドを使用します。

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");  
if (child5.IsAfter(child3))  
    Console.WriteLine("Child5 is after Child3");  
else  
    Console.WriteLine("Child5 is not after Child3");  
Dim xmlTree As XElement = _   
        <Root>Text content.  
            <Child1>child1 content</Child1>  
            <Child2>child2 content</Child2>  
            <Child3>child3 content</Child3>More text content.  
            <Child4>child4 content</Child4>  
            <Child5>child5 content</Child5>  
        </Root>  

Dim child3 As XElement = xmlTree.<Child3>(0)  
Dim child5 As XElement = xmlTree.<Child5>(0)  
If (child5.IsAfter(child3)) Then  
    Console.WriteLine("Child5 is after Child3")  
Else  
    Console.WriteLine("Child5 is not after Child3")  
End If  

この例を実行すると、次の出力が生成されます。

Child5 is after Child3  

注釈

子ノードは XContainer 、1 つのリンクされたオブジェクトの XNode リストとして格納されます。 つまり、メソッドは CompareDocumentOrder 、共通の親が見つかるまで、比較対象の 2 つのノードの先祖を走査する必要があります。 次に、共通の親の子ノードの一覧をスキャンして、比較する 2 つのノードの順序を決定する必要があります。 したがって、この方法を使用すると、パフォーマンスに影響する可能性があります。

適用対象

こちらもご覧ください