TemplateControl.XPath 方法

定義

提供在執行階段時對物件剖析並評估 XPath 資料繫結運算式的支援。Provides support for parsing and evaluating an XPath data-binding expression against an object at run time.

多載

XPath(String, String, IXmlNamespaceResolver)

使用命名空間解析所需之指定的前置詞和命名空間對應,以及指定的格式字串,評估 XPath 資料繫結運算式以顯示結果。Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution and the specified format string to display the result.

XPath(String, IXmlNamespaceResolver)

使用命名空間解析所需之指定的前置詞和命名空間對應,評估 XPath 資料繫結運算式。Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution.

XPath(String)

評估 XPath 資料繫結運算式。Evaluates an XPath data-binding expression.

XPath(String, String)

使用指定的格式字串評估 XPath 資料繫結運算式以顯示結果。Evaluates an XPath data-binding expression using the specified format string to display the result.

XPath(String, String, IXmlNamespaceResolver)

使用命名空間解析所需之指定的前置詞和命名空間對應,以及指定的格式字串,評估 XPath 資料繫結運算式以顯示結果。Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution and the specified format string to display the result.

protected public:
 System::String ^ XPath(System::String ^ xPathExpression, System::String ^ format, System::Xml::IXmlNamespaceResolver ^ resolver);
protected internal string XPath (string xPathExpression, string format, System.Xml.IXmlNamespaceResolver resolver);
member this.XPath : string * string * System.Xml.IXmlNamespaceResolver -> string
Protected Friend Function XPath (xPathExpression As String, format As String, resolver As IXmlNamespaceResolver) As String

參數

xPathExpression
String

要評估的 XPath 運算式。The XPath expression to evaluate. 如需詳細資訊,請參閱XPathBinderFor more information, see XPathBinder.

format
String

要套用到結果的 .NET Framework 格式字串。A .NET Framework format string to apply to the result.

resolver
IXmlNamespaceResolver

用來解析命名空間的前置詞和命名空間的對應集合。A set of prefix and namespace mappings used for namespace resolution.

傳回

從資料繫結運算式評估和字串型別轉換所產生的字串。A string that results from the evaluation of the data-binding expression and conversion to a string type.

例外狀況

資料繫結方法只能用於 Page 包含的控制項。The data-binding method can be used only for controls contained on a Page.

備註

XPath 方法會使用 GetDataItem 方法來呼叫 XPathBinder.Eval 方法,以解析運算式評估所針對的 IXPathNavigable 物件參考。The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.

另請參閱

XPath(String, IXmlNamespaceResolver)

使用命名空間解析所需之指定的前置詞和命名空間對應,評估 XPath 資料繫結運算式。Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution.

protected public:
 System::Object ^ XPath(System::String ^ xPathExpression, System::Xml::IXmlNamespaceResolver ^ resolver);
protected internal object XPath (string xPathExpression, System.Xml.IXmlNamespaceResolver resolver);
member this.XPath : string * System.Xml.IXmlNamespaceResolver -> obj
Protected Friend Function XPath (xPathExpression As String, resolver As IXmlNamespaceResolver) As Object

參數

xPathExpression
String

要評估的 XPath 運算式。The XPath expression to evaluate. 如需詳細資訊,請參閱XPathBinderFor more information, see XPathBinder.

resolver
IXmlNamespaceResolver

用來解析命名空間的前置詞和命名空間的對應集合。A set of prefix and namespace mappings used for namespace resolution.

傳回

從資料繫結運算式的評估產生的物件。An object that results from the evaluation of the data-binding expression.

例外狀況

資料繫結方法只能用於 Page 包含的控制項。The data-binding method can be used only for controls contained on a Page.

備註

XPath 方法會使用 GetDataItem 方法來呼叫 XPathBinder.Eval 方法,以解析運算式評估所針對的 IXPathNavigable 物件參考。The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.

另請參閱

XPath(String)

評估 XPath 資料繫結運算式。Evaluates an XPath data-binding expression.

protected public:
 System::Object ^ XPath(System::String ^ xPathExpression);
protected internal object XPath (string xPathExpression);
member this.XPath : string -> obj
Protected Friend Function XPath (xPathExpression As String) As Object

參數

xPathExpression
String

要評估的 XPath 運算式。The XPath expression to evaluate. 如需詳細資訊,請參閱XPathBinderFor more information, see XPathBinder.

傳回

從資料繫結運算式的評估產生的物件。An object that results from the evaluation of the data-binding expression.

例外狀況

資料繫結方法只能用於 Page 包含的控制項。The data-binding method can be used only for controls contained on a Page.

範例

下列程式碼範例示範如何在 Repeater 控制項中使用 XPath 方法。The following code example demonstrates how to use the XPath method in a Repeater control.

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TemplateControl XPath and XPathSelect Example</title>
</head>
<body>
    <h3>TemplateControl XPath Example</h3>
    <form id="form1" runat="server">
    <div>
      <asp:XmlDataSource
        id="XmlDataSource1" 
        runat="server"
        XPath="contacts" 
        DataFile="contacts.xml" />    
      <asp:FormView 
        id="FormView1" 
        runat="server" 
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
          <hr />
          <asp:Repeater 
            id="Repeater1" 
            runat="server" 
            DataSource='<%# XPathSelect("contact") %>' >
            <ItemTemplate>
              Name: <%# XPath("name") %> <br />
              Note: <%# XPath("note") %> <br />
              <hr />
            </ItemTemplate>
          </asp:Repeater>
        </ItemTemplate>
      </asp:FormView>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>TemplateControl XPath Example</title>
</head>
<body>
    <h3>TemplateControl XPath and XPathSelect Example</h3>
    <form id="form1" runat="server">
    <div>
      <asp:XmlDataSource
        id="XmlDataSource1" 
        runat="server"
        XPath="contacts" 
        DataFile="contacts.xml" />    
      <asp:FormView 
        id="FormView1" 
        runat="server" 
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
          <hr />
          <asp:Repeater 
            id="Repeater1" 
            runat="server" 
            DataSource='<%# XPathSelect("contact") %>' >
            <ItemTemplate>
              Name: <%# XPath("name") %> <br />
              Note: <%# XPath("note") %> <br />
              <hr />
            </ItemTemplate>
          </asp:Repeater>
        </ItemTemplate>
      </asp:FormView>
    </div>
    </form>
</body>
</html>

在上述程式碼範例中,可以使用下列測試 XML 資料。The following test XML data can be used in the preceding code example.

<contacts>  
   <contact id="1">  
     <name>contact name 1</name>  
     <note>contact note 1</note>  
   </contact>  
   <contact id="2">  
     <name>contact name 2</name>  
     <note>contact note 2</note>  
   </contact>  
</contacts>  

備註

XPath 方法會使用 GetDataItem 方法來呼叫 XPathBinder.Eval 方法,以解析運算式評估所針對的 IXPathNavigable 物件參考。The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.

另請參閱

XPath(String, String)

使用指定的格式字串評估 XPath 資料繫結運算式以顯示結果。Evaluates an XPath data-binding expression using the specified format string to display the result.

protected public:
 System::String ^ XPath(System::String ^ xPathExpression, System::String ^ format);
protected internal string XPath (string xPathExpression, string format);
member this.XPath : string * string -> string
Protected Friend Function XPath (xPathExpression As String, format As String) As String

參數

xPathExpression
String

要評估的 XPath 運算式。The XPath expression to evaluate. 如需詳細資訊,請參閱XPathBinderFor more information, see XPathBinder.

format
String

要套用到結果的 .NET Framework 格式字串。A .NET Framework format string to apply to the result.

傳回

從資料繫結運算式評估和字串型別轉換所產生的字串。A string that results from the evaluation of the data-binding expression and conversion to a string type.

例外狀況

資料繫結方法只能用於 Page 包含的控制項。The data-binding method can be used only for controls contained on a Page.

備註

XPath 方法會使用 GetDataItem 方法來呼叫 XPathBinder.Eval 方法,以解析運算式評估所針對的 IXPathNavigable 物件參考。The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.

另請參閱

適用於