XPathNavigator.Matches 메서드

정의

현재 노드가 지정된 System.Xml.XPath 식과 일치하는지 여부를 확인합니다.Determines whether the current node matches the specified System.Xml.XPath expression.

오버로드

Matches(String)

현재 노드가 지정된 XPath 식과 일치하는지를 확인합니다.Determines whether the current node matches the specified XPath expression.

Matches(XPathExpression)

현재 노드가 지정된 XPathExpression과 일치하는지 확인합니다.Determines whether the current node matches the specified XPathExpression.

Matches(String)

현재 노드가 지정된 XPath 식과 일치하는지를 확인합니다.Determines whether the current node matches the specified XPath expression.

public:
 virtual bool Matches(System::String ^ xpath);
public virtual bool Matches (string xpath);
abstract member Matches : string -> bool
override this.Matches : string -> bool
Public Overridable Function Matches (xpath As String) As Boolean

매개 변수

xpath
String

XPath 식입니다.The XPath expression.

반환

현재 노드가 지정된 XPath 식과 일치하면 true이고, 그렇지 않으면 false입니다.true if the current node matches the specified XPath expression; otherwise, false.

예외

XPath 식은 평가할 수 없습니다.The XPath expression cannot be evaluated.

XPath 식이 잘못되었습니다.The XPath expression is not valid.

예제

예는 Matches 메서드를 참조 합니다 XPathNavigator.Matches 메서드.For an example of the Matches method, see the XPathNavigator.Matches method.

설명

이 메서드 상태에 영향을 주지는 XPathNavigator합니다.This method has no affect on the state of the XPathNavigator.

Matches(XPathExpression)

현재 노드가 지정된 XPathExpression과 일치하는지 확인합니다.Determines whether the current node matches the specified XPathExpression.

public:
 virtual bool Matches(System::Xml::XPath::XPathExpression ^ expr);
public virtual bool Matches (System.Xml.XPath.XPathExpression expr);
abstract member Matches : System.Xml.XPath.XPathExpression -> bool
override this.Matches : System.Xml.XPath.XPathExpression -> bool
Public Overridable Function Matches (expr As XPathExpression) As Boolean

매개 변수

expr
XPathExpression

컴파일된 XPath 식을 포함하는 XPathExpression 개체입니다.An XPathExpression object containing the compiled XPath expression.

반환

현재 노드가 XPathExpression과 일치하면 true이고, 그러지 않으면 false입니다.true if the current node matches the XPathExpression; otherwise, false.

예외

XPath 식은 평가할 수 없습니다.The XPath expression cannot be evaluated.

XPath 식이 잘못되었습니다.The XPath expression is not valid.

예제

다음 예제에서는 모든 소설의 제목을 표시합니다.The following example displays the titles of all novels.

XPathDocument^ document = gcnew XPathDocument("books.xml");
XPathNavigator^ navigator = document->CreateNavigator();

// Select all book nodes.
XPathNodeIterator^ nodes = navigator->SelectDescendants("book", "", false);

// Select all book nodes that have the matching attribute value.
XPathExpression^ expr = navigator->Compile("book[@genre='novel']");
while (nodes->MoveNext())
{
    XPathNavigator^ navigator2 = nodes->Current->Clone();
    if (navigator2->Matches(expr))
    {
        navigator2->MoveToFirstChild();
        Console::WriteLine("Book title:  {0}", navigator2->Value);
    }
}
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

// Select all book nodes.
XPathNodeIterator nodes = navigator.SelectDescendants("book", "", false);

// Select all book nodes that have the matching attribute value.
XPathExpression expr = navigator.Compile("book[@genre='novel']");
while (nodes.MoveNext())
{
    XPathNavigator navigator2 = nodes.Current.Clone();
    if (navigator2.Matches(expr))
    {
        navigator2.MoveToFirstChild();
        Console.WriteLine("Book title:  {0}", navigator2.Value);
    }
}
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

' Select all book nodes.
Dim nodes As XPathNodeIterator = navigator.SelectDescendants("book", "", False)

' Select all book nodes that have the matching attribute value.
Dim expr As XPathExpression = navigator.Compile("book[@genre='novel']")
While nodes.MoveNext()
    Dim navigator2 As XPathNavigator = nodes.Current.Clone()
    If navigator2.Matches(expr) Then
        navigator2.MoveToFirstChild()
        Console.WriteLine("Book title:  {0}", navigator2.Value)
    End If
End While

이 예제에서는 파일을 사용 하 여 books.xml입력으로 합니다.The example uses the file, books.xml, as input.

  
<?xml version="1.0" encoding="utf-8" ?>   
<bookstore>  
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">  
        <title>The Autobiography of Benjamin Franklin</title>  
        <author>  
            <first-name>Benjamin</first-name>  
            <last-name>Franklin</last-name>  
        </author>  
        <price>8.99</price>  
    </book>  
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">  
        <title>The Confidence Man</title>  
        <author>  
            <first-name>Herman</first-name>  
            <last-name>Melville</last-name>  
        </author>  
        <price>11.99</price>  
    </book>  
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">  
        <title>The Gorgias</title>  
        <author>  
            <name>Plato</name>  
        </author>  
        <price>9.99</price>  
    </book>  
</bookstore>  
  

설명

이 메서드는 상태에 영향을 주지는 XPathNavigator합니다.This method has no effect on the state of the XPathNavigator. 이 메서드는 동일 합니다 XPathNavigator.Matches 메서드를 XPathExpression XPath 식을 대신 지정 된 컴파일된 XPath 식이 포함 된 개체 String합니다.This method is identical to the XPathNavigator.Matches method, except that a XPathExpression object containing the compiled XPath expression is specified, rather than an XPath expression String.

적용 대상