XPathNavigator.Evaluate 메서드

정의

지정된 XPath 식을 계산하고 형식화된 결과를 반환합니다.Evaluates the specified XPath expression and returns the typed result.

오버로드

Evaluate(String)

지정된 XPath 식을 계산하고 형식화된 결과를 반환합니다.Evaluates the specified XPath expression and returns the typed result.

Evaluate(XPathExpression)

XPathExpression을 계산하고 형식화된 결과를 반환합니다.Evaluates the XPathExpression and returns the typed result.

Evaluate(String, IXmlNamespaceResolver)

XPath 식에 있는 네임스페이스 접두사를 확인하기 위해 지정된 IXmlNamespaceResolver 개체를 사용하여 XPath 식을 계산한 후 형식화된 결과를 반환합니다.Evaluates the specified XPath expression and returns the typed result, using the IXmlNamespaceResolver object specified to resolve namespace prefixes in the XPath expression.

Evaluate(XPathExpression, XPathNodeIterator)

제공된 컨텍스트를 사용하여 XPathExpression을 계산한 후 형식화된 결과를 반환합니다.Uses the supplied context to evaluate the XPathExpression, and returns the typed result.

Evaluate(String)

지정된 XPath 식을 계산하고 형식화된 결과를 반환합니다.Evaluates the specified XPath expression and returns the typed result.

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

매개 변수

xpath
String

계산할 수 있는 XPath 식을 나타내는 문자열입니다.A string representing an XPath expression that can be evaluated.

반환

식의 결과(부울, 숫자, 문자열 또는 노드 집합)입니다.The result of the expression (Boolean, number, string, or node set). 각각 Boolean, Double, String 또는 XPathNodeIterator 개체에 매핑됩니다.This maps to Boolean, Double, String, or XPathNodeIterator objects respectively.

예외

XPath 식의 반환 형식은 노드 집합입니다.The return type of the XPath expression is a node set.

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

예제

다음 예제에서는 XPath 식을 계산 하 고 반환 된 Double합니다.The following example evaluates an XPath expression and returns a 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())

이 예제에서는 books.xml 파일을 입력으로 사용합니다.The example takes the books.xml file as an 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>  
  

설명

다음 C# 코드를 변환 합니다 Price/text() 숫자에 10을 곱한 노드와 결과 값을 반환 합니다.The following C# code converts the Price/text() node to a number, multiplies it by 10, and returns the resulting value.

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

참고

위치 단계에서 조건자로 사용 하지 않으면 XPath position () 및 last () 함수는 노드 평가 되려면 집합에 대 한 참조에 필요 합니다.The XPath position() and last() functions, unless used as a predicate in a location step, require a reference to a node set in order to be evaluated. 사용 하는 오버 로드를 사용 해야 하는 경우에 XPathNodeIterator 인수로;이 고, 그렇지 position () 및 last () 0을 반환 합니다.In this case, you must use the overload which takes an XPathNodeIterator as an argument; otherwise, position() and last() return 0.

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

추가 정보

Evaluate(XPathExpression)

XPathExpression을 계산하고 형식화된 결과를 반환합니다.Evaluates the XPathExpression and returns the typed result.

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

매개 변수

expr
XPathExpression

계산할 수 있는 XPathExpression입니다.An XPathExpression that can be evaluated.

반환

식의 결과(부울, 숫자, 문자열 또는 노드 집합)입니다.The result of the expression (Boolean, number, string, or node set). 각각 Boolean, Double, String 또는 XPathNodeIterator 개체에 매핑됩니다.This maps to Boolean, Double, String, or XPathNodeIterator objects respectively.

예외

XPath 식의 반환 형식은 노드 집합입니다.The return type of the XPath expression is a node set.

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

예제

다음 예제에서는 평가 XPathExpression 반환을 Double입니다.The following example evaluates an XPathExpression and returns a 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())

이 예제에서는 books.xml 파일을 입력으로 사용합니다.The example takes the books.xml file as an 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>  
  

설명

다음 C# 코드를 변환한 후 반환를 Price/text() 숫자로 노드가 10을 곱한 값입니다.The following C# code returns a number after converting the Price/text() node to a number and multiplying the value by 10.

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

참고

위치 단계에서 조건자로 사용 하지 않으면 XPath position () 및 last () 함수는 노드 평가 되려면 집합에 대 한 참조에 필요 합니다.The XPath position() and last() functions, unless used as a predicate in a location step, require a reference to a node set in order to be evaluated. 사용 하는 오버 로드를 사용 해야 하는 경우에 XPathNodeIterator 인수로;이 고, 그렇지 position () 및 last () 0을 반환 합니다.In this case, you must use the overload which takes an XPathNodeIterator as an argument; otherwise, position() and last() return 0.

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

추가 정보

Evaluate(String, IXmlNamespaceResolver)

XPath 식에 있는 네임스페이스 접두사를 확인하기 위해 지정된 IXmlNamespaceResolver 개체를 사용하여 XPath 식을 계산한 후 형식화된 결과를 반환합니다.Evaluates the specified XPath expression and returns the typed result, using the IXmlNamespaceResolver object specified to resolve namespace prefixes in the XPath expression.

public:
 virtual System::Object ^ Evaluate(System::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

매개 변수

xpath
String

계산할 수 있는 XPath 식을 나타내는 문자열입니다.A string representing an XPath expression that can be evaluated.

resolver
IXmlNamespaceResolver

XPath 식에 있는 네임스페이스 접두사를 확인하는 데 사용되는 IXmlNamespaceResolver 개체입니다.The IXmlNamespaceResolver object used to resolve namespace prefixes in the XPath expression.

반환

식의 결과(부울, 숫자, 문자열 또는 노드 집합)입니다.The result of the expression (Boolean, number, string, or node set). 각각 Boolean, Double, String 또는 XPathNodeIterator 개체에 매핑됩니다.This maps to Boolean, Double, String, or XPathNodeIterator objects respectively.

예외

XPath 식의 반환 형식은 노드 집합입니다.The return type of the XPath expression is a node set.

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

예제

다음 예제에서는 XPath 식을 계산 하 고 반환를 Double 를 사용 하 여를 XmlNamespaceManager XPath 식의 네임 스페이스 접두사를 확인 하기 위해 지정 하는 개체입니다.The following example evaluates an XPath expression and returns a Double using the XmlNamespaceManager object specified to resolve namespace prefixes in the XPath expression.

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())

이 예제에서는 contosoBooks.xml 파일을 입력으로 사용합니다.The example takes the contosoBooks.xml file as an input.

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

설명

다음 C# 코드를 변환한 후 반환를 Price/text() 숫자로 노드가 10을 곱한 값입니다.The following C# code returns a number after converting the Price/text() node to a number and multiplying the value by 10.

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

참고

위치 단계에서 조건자로 사용 하지 않으면 XPath position () 및 last () 함수는 노드 평가 되려면 집합에 대 한 참조에 필요 합니다.The XPath position() and last() functions, unless used as a predicate in a location step, require a reference to a node set in order to be evaluated. 사용 하는 오버 로드를 사용 해야 하는 경우에 XPathNodeIterator 인수로;이 고, 그렇지 position () 및 last () 0을 반환 합니다.In this case, you must use the overload which takes an XPathNodeIterator as an argument; otherwise, position() and last() return 0.

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

Evaluate(XPathExpression, XPathNodeIterator)

제공된 컨텍스트를 사용하여 XPathExpression을 계산한 후 형식화된 결과를 반환합니다.Uses the supplied context to evaluate the XPathExpression, and returns the typed result.

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);
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

매개 변수

expr
XPathExpression

계산할 수 있는 XPathExpression입니다.An XPathExpression that can be evaluated.

context
XPathNodeIterator

계산이 수행될 선택된 노드 집합을 가리키는 XPathNodeIterator입니다.An XPathNodeIterator that points to the selected node set that the evaluation is to be performed on.

반환

식의 결과(부울, 숫자, 문자열 또는 노드 집합)입니다.The result of the expression (Boolean, number, string, or node set). 각각 Boolean, Double, String 또는 XPathNodeIterator 개체에 매핑됩니다.This maps to Boolean, Double, String, or XPathNodeIterator objects respectively.

예외

XPath 식의 반환 형식은 노드 집합입니다.The return type of the XPath expression is a node set.

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

예제

다음 예제에서는 평가 XPathExpression 반환를 Double 를 사용 하 여를 Current 노드의 XPathNodeIterator 컨텍스트 노드로 서.The following example evaluates an XPathExpression and returns a Double using the Current node of the XPathNodeIterator as the context node.

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())

이 예제에서는 books.xml 파일을 입력으로 사용합니다.The example takes the books.xml file as an 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>  
  

설명

사용 하 여 식이 계산 되는 Current 의 노드는 XPathNodeIterator 컨텍스트 노드로 서입니다.The expression is evaluated using the Current node of the XPathNodeIterator as the context node. 경우 context 됩니다 null는 노드는 XPathNavigator 가 현재 위치한 컨텍스트 노드로 사용 됩니다.If context is null, the node on which the XPathNavigator is currently positioned is used as the context node.

Position () 및 last () 함수를 위치 단계에서 조건자로 사용 하지 않는 한 항상 다음과 같은 경우 0을 반환 합니다.The position() and last() functions, unless used as a predicate in a location step, always return 0 under the following conditions:

Position () 및 last () 함수를 현재 노드에서의 작업을 하기 때문에 사용해 서는 안 된 Current 속성을 선택된 된 노드 집합에서 이동 합니다.Because the position() and last() functions work on the current node, you should not use the Current property to move away from the selected node set. 상태를 무효화할 수 있습니다는 XPathNavigator합니다.This could invalidate the state of the XPathNavigator.

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

적용 대상