XPathNavigator.Matches Metoda

Definice

Určuje, zda aktuální uzel odpovídá zadanému System.Xml.XPath výrazu.

Přetížení

Matches(String)

Určuje, zda aktuální uzel odpovídá zadanému výrazu XPath.

Matches(XPathExpression)

Určuje, zda aktuální uzel odpovídá zadanému XPathExpressionuzlu .

Matches(String)

Určuje, zda aktuální uzel odpovídá zadanému výrazu XPath.

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

Parametry

xpath
String

Výraz XPath.

Návraty

Boolean

truepokud aktuální uzel odpovídá zadanému výrazu XPath; v opačném případě . false

Výjimky

Výraz XPath nelze vyhodnotit.

Výraz XPath není platný.

Příklady

Matches Příklad metody najdete v metoděXPathNavigator.Matches.

Poznámky

Tato metoda nemá žádný vliv na stav XPathNavigator.

Platí pro

Matches(XPathExpression)

Určuje, zda aktuální uzel odpovídá zadanému XPathExpressionuzlu .

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

Parametry

expr
XPathExpression

Objekt XPathExpression obsahující zkompilovaný výraz XPath.

Návraty

Boolean

true pokud aktuální uzel odpovídá hodnotě XPathExpression; v opačném případě false.

Výjimky

Výraz XPath nelze vyhodnotit.

Výraz XPath není platný.

Příklady

Následující příklad zobrazuje názvy všech románů.

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

Příklad používá soubor , books.xmljako vstup.

<?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>  

Poznámky

Tato metoda nemá žádný vliv na stav XPathNavigator. Tato metoda je identická s metodou XPathNavigator.Matches , s výjimkou toho, že XPathExpression objekt obsahující zkompilovaný výraz XPath je zadán, nikoli výraz StringXPath .

Platí pro