XPathNavigator.Evaluate Yöntem

Tanım

Belirtilen XPath ifadesini değerlendirir ve yazılan sonucu döndürür.

Aşırı Yüklemeler

Evaluate(String)

Belirtilen XPath ifadesini değerlendirir ve yazılan sonucu döndürür.

Evaluate(XPathExpression)

XPathExpression değerini değerlendirir ve yazılan sonucu döndürür.

Evaluate(String, IXmlNamespaceResolver)

Belirtilen XPath ifadesini değerlendirir ve XPath ifadesindeki ad alanı ön eklerini çözümlemek için belirtilen nesneyi kullanarak IXmlNamespaceResolver yazılan sonucu döndürür.

Evaluate(XPathExpression, XPathNodeIterator)

sağlanan bağlamı kullanarak değerini değerlendirir XPathExpressionve yazılan sonucu döndürür.

Evaluate(String)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

Belirtilen XPath ifadesini değerlendirir ve yazılan sonucu döndürür.

public:
 virtual System::Object ^ Evaluate(System::String ^ xpath);
public virtual object Evaluate (string xpath);
abstract member Evaluate : string -> obj
override this.Evaluate : string -> obj
Public Overridable Function Evaluate (xpath As String) As Object

Parametreler

xpath
String

Değerlendirilebilecek bir XPath ifadesini temsil eden dize.

Döndürülenler

İfadenin sonucu (Boole, sayı, dize veya düğüm kümesi). Bu, sırasıyla , , veya XPathNodeIterator nesneleriyle eşlerBoolean. StringDouble

Özel durumlar

XPath ifadesinin dönüş türü bir düğüm kümesidir.

XPath ifadesi geçerli değil.

Örnekler

Aşağıdaki örnek bir XPath ifadesini değerlendirir ve döndürür Double.

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

Double total = (double)navigator->Evaluate("sum(descendant::book/price)");
Console::WriteLine("Total price for all books: {0}", total.ToString());
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

Double total = (double)navigator.Evaluate("sum(descendant::book/price)");
Console.WriteLine("Total price for all books: {0}", total.ToString());
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim total As Double = CType(navigator.Evaluate("sum(descendant::book/price)"), Double)
Console.WriteLine("Total price for all books: {0}", total.ToString())

Örnek, dosyayı giriş olarak alır books.xml .

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

Açıklamalar

Aşağıdaki C# kodu düğümü sayıya dönüştürür Price/text() , 10 ile çarpar ve sonuçta elde edilen değeri döndürür.

nav.Evaluate("Price/text()*10");  

Not

Bir konum adımında koşul olarak kullanılmadığı sürece XPath position() ve last() işlevleri, değerlendirilebilmesi için bir düğüm kümesi başvurusu gerektirir. Bu durumda, bağımsız değişken olarak bir XPathNodeIterator alan aşırı yüklemeyi kullanmanız gerekir; aksi takdirde position() ve last() 0 döndürür.

Bu yöntemin durumunu etkilemesi XPathNavigatorgerekmez.

Ayrıca bkz.

Şunlara uygulanır

Evaluate(XPathExpression)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

XPathExpression değerini değerlendirir ve yazılan sonucu döndürür.

public:
 virtual System::Object ^ Evaluate(System::Xml::XPath::XPathExpression ^ expr);
public virtual object Evaluate (System.Xml.XPath.XPathExpression expr);
abstract member Evaluate : System.Xml.XPath.XPathExpression -> obj
override this.Evaluate : System.Xml.XPath.XPathExpression -> obj
Public Overridable Function Evaluate (expr As XPathExpression) As Object

Parametreler

expr
XPathExpression

XPathExpression Değerlendirilebilecek bir.

Döndürülenler

İfadenin sonucu (Boole, sayı, dize veya düğüm kümesi). Bu, sırasıyla , , veya XPathNodeIterator nesneleriyle eşlerBoolean. StringDouble

Özel durumlar

XPath ifadesinin dönüş türü bir düğüm kümesidir.

XPath ifadesi geçerli değil.

Örnekler

Aşağıdaki örnek bir XPathExpression değerini değerlendirir ve döndürür Double.

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

XPathExpression^ query = navigator->Compile("sum(descendant::book/price)");

Double total = (double)navigator->Evaluate(query);
Console::WriteLine("Total price for all books: {0}", total.ToString());
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

XPathExpression query = navigator.Compile("sum(descendant::book/price)");

Double total = (double)navigator.Evaluate(query);
Console.WriteLine("Total price for all books: {0}", total.ToString());
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim query As XPathExpression = navigator.Compile("sum(descendant::book/price)")

Dim total As Double = CType(navigator.Evaluate(query), Double)
Console.WriteLine("Total price for all books: {0}", total.ToString())

Örnek, dosyayı giriş olarak alır books.xml .

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

Açıklamalar

Aşağıdaki C# kodu, düğümü sayıya Price/text() dönüştürdükten ve değeri 10 ile çarpdıktan sonra bir sayı döndürür.

XPathExpression expr = nav.Compile("Price/text()*10");  
nav.Evaluate(expr);  

Not

Bir konum adımında koşul olarak kullanılmadığı sürece XPath position() ve last() işlevleri, değerlendirilebilmesi için bir düğüm kümesi başvurusu gerektirir. Bu durumda, bağımsız değişken olarak bir XPathNodeIterator alan aşırı yüklemeyi kullanmanız gerekir; aksi takdirde position() ve last() 0 döndürür.

Bu yöntemin durumunu etkilemesi XPathNavigatorgerekmez.

Ayrıca bkz.

Şunlara uygulanır

Evaluate(String, IXmlNamespaceResolver)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

Belirtilen XPath ifadesini değerlendirir ve XPath ifadesindeki ad alanı ön eklerini çözümlemek için belirtilen nesneyi kullanarak IXmlNamespaceResolver yazılan sonucu döndürür.

public:
 virtual System::Object ^ Evaluate(System::String ^ xpath, System::Xml::IXmlNamespaceResolver ^ resolver);
public virtual object Evaluate (string xpath, System.Xml.IXmlNamespaceResolver? resolver);
public virtual object Evaluate (string xpath, System.Xml.IXmlNamespaceResolver resolver);
abstract member Evaluate : string * System.Xml.IXmlNamespaceResolver -> obj
override this.Evaluate : string * System.Xml.IXmlNamespaceResolver -> obj
Public Overridable Function Evaluate (xpath As String, resolver As IXmlNamespaceResolver) As Object

Parametreler

xpath
String

Değerlendirilebilecek bir XPath ifadesini temsil eden dize.

resolver
IXmlNamespaceResolver

IXmlNamespaceResolver XPath ifadesindeki ad alanı ön eklerini çözümlemek için kullanılan nesne.

Döndürülenler

İfadenin sonucu (Boole, sayı, dize veya düğüm kümesi). Bu, sırasıyla , , veya XPathNodeIterator nesneleriyle eşlerBoolean. StringDouble

Özel durumlar

XPath ifadesinin dönüş türü bir düğüm kümesidir.

XPath ifadesi geçerli değil.

Örnekler

Aşağıdaki örnek bir XPath ifadesini değerlendirir ve XPath ifadesindeki XmlNamespaceManager ad alanı ön eklerini çözümlemek için belirtilen nesneyi kullanarak bir Double döndürür.

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

XmlNamespaceManager^ manager = gcnew XmlNamespaceManager(navigator->NameTable);
manager->AddNamespace("bk", "http://www.contoso.com/books");

Double total = (double)navigator->Evaluate("sum(descendant::bk:book/bk:price)", manager);
Console::WriteLine("Total price for all books: {0}", total.ToString());
XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
manager.AddNamespace("bk", "http://www.contoso.com/books");

Double total = (double)navigator.Evaluate("sum(descendant::bk:book/bk:price)", manager);
Console.WriteLine("Total price for all books: {0}", total.ToString());
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim manager As XmlNamespaceManager = New XmlNamespaceManager(navigator.NameTable)
manager.AddNamespace("bk", "http://www.contoso.com/books")

Dim total As Double = CType(navigator.Evaluate("sum(descendant::bk:book/bk:price)", manager), Double)
Console.WriteLine("Total price for all books: {0}", total.ToString())

Örnek, dosyayı giriş olarak alır contosoBooks.xml .

<?xml version="1.0" encoding="utf-8" ?>  
<bookstore xmlns="http://www.contoso.com/books">  
    <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>  

Açıklamalar

Aşağıdaki C# kodu, düğümü sayıya Price/text() dönüştürdükten ve değeri 10 ile çarpdıktan sonra bir sayı döndürür.

XPathExpression expr = nav.Compile("Price/text()*10");  
nav.Evaluate(expr);  

Not

Bir konum adımında koşul olarak kullanılmadığı sürece XPath position() ve last() işlevleri, değerlendirilebilmesi için bir düğüm kümesi başvurusu gerektirir. Bu durumda, bağımsız değişken olarak bir XPathNodeIterator alan aşırı yüklemeyi kullanmanız gerekir; aksi takdirde position() ve last() 0 döndürür.

Bu yöntemin durumunu etkilemesi XPathNavigatorgerekmez.

Şunlara uygulanır

Evaluate(XPathExpression, XPathNodeIterator)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

sağlanan bağlamı kullanarak değerini değerlendirir XPathExpressionve yazılan sonucu döndürür.

public:
 virtual System::Object ^ Evaluate(System::Xml::XPath::XPathExpression ^ expr, System::Xml::XPath::XPathNodeIterator ^ context);
public virtual object Evaluate (System.Xml.XPath.XPathExpression expr, System.Xml.XPath.XPathNodeIterator? context);
public virtual object Evaluate (System.Xml.XPath.XPathExpression expr, System.Xml.XPath.XPathNodeIterator context);
abstract member Evaluate : System.Xml.XPath.XPathExpression * System.Xml.XPath.XPathNodeIterator -> obj
override this.Evaluate : System.Xml.XPath.XPathExpression * System.Xml.XPath.XPathNodeIterator -> obj
Public Overridable Function Evaluate (expr As XPathExpression, context As XPathNodeIterator) As Object

Parametreler

expr
XPathExpression

XPathExpression Değerlendirilebilecek bir.

context
XPathNodeIterator

XPathNodeIterator Değerlendirmenin gerçekleştirileceği seçili düğüm kümesine işaret eden bir.

Döndürülenler

İfadenin sonucu (Boole, sayı, dize veya düğüm kümesi). Bu, sırasıyla , , veya XPathNodeIterator nesneleriyle eşlerBoolean. StringDouble

Özel durumlar

XPath ifadesinin dönüş türü bir düğüm kümesidir.

XPath ifadesi geçerli değil.

Örnekler

Aşağıdaki örnek, bağlam düğümü olarak düğümünü CurrentXPathNodeIterator kullanarak bir XPathExpressionDouble değerini değerlendirir ve döndürür.

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

XPathNodeIterator^ nodes = navigator->Select("//book");
XPathExpression^ query = nodes->Current->Compile("sum(descendant::price)");

Double total = (double)navigator->Evaluate(query, nodes);
Console::WriteLine("Total price for all books: {0}", total.ToString());
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

XPathNodeIterator nodes = navigator.Select("//book");
XPathExpression query = nodes.Current.Compile("sum(descendant::price)");

Double total = (double)navigator.Evaluate(query, nodes);
Console.WriteLine("Total price for all books: {0}", total.ToString());
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim nodes As XPathNodeIterator = navigator.Select("//book")
Dim query As XPathExpression = nodes.Current.Compile("sum(descendant::price)")

Dim total As Double = CType(navigator.Evaluate(query, nodes), Double)
Console.WriteLine("Total price for all books: {0}", total.ToString())

Örnek, dosyayı giriş olarak alır books.xml .

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

Açıklamalar

İfade, bağlam düğümü olarak düğümünü XPathNodeIterator kullanarak Current değerlendirilir. ise contextnull, öğesinin XPathNavigator şu anda konumlandırıldığı düğüm bağlam düğümü olarak kullanılır.

Konum adımında koşul olarak kullanılmadığı sürece position() ve last() işlevleri aşağıdaki koşullarda her zaman 0 döndürür:

position() ve last() işlevleri geçerli düğümde çalıştığından Current , seçili düğüm kümesinden uzaklaşmak için özelliğini kullanmamalısınız. Bu, durumunu XPathNavigatorgeçersiz kılabilir.

Bu yöntemin durumunu etkilemesi XPathNavigatorgerekmez.

Şunlara uygulanır