XPathBinder 類別

定義

提供對快速應用程式開發 (RAD) 設計工具的支援,以剖析使用 XPath 運算式的資料繫結運算式。Provides support for rapid application development (RAD) designers to parse data-binding expressions that use XPath expressions. 此類別無法獲得繼承。This class cannot be inherited.

public ref class XPathBinder sealed
public sealed class XPathBinder
type XPathBinder = class
Public NotInheritable Class XPathBinder
繼承
XPathBinder

範例

下列程式碼範例示範如何使用具有樣板 XmlDataSource 化控制項的控制項 Repeater 來顯示 XML 資料。The following code example demonstrates how to use an XmlDataSource control with a templated Repeater control to display XML data. 此範例有兩個部分:This example has two parts:

  • 顯示 XML 資料的 Web Form 頁面。A Web Forms page that displays XML data.

  • 包含資料的 XML 檔。An XML file that contains the data.

範例的第一個部分會顯示 Web Form 頁面,該頁面會顯示透過控制項存取的 XML 資料 XmlDataSourceThe first part of the example shows a Web Forms page that displays XML data accessed through an XmlDataSource control. Repeater控制項使用簡化 Eval(Object, String) 的方法語法,系結至所代表之 XML 檔中的資料項目 XmlDataSourceA Repeater control uses simplified Eval(Object, String) method syntax to bind to data items within the XML document that the XmlDataSource represents. 它會使用 Select(Object, String) 方法來取出 IEnumerable 清單,並將其指派為控制項的晚期繫結 DataSource 屬性 RepeaterIt uses the Select(Object, String) method to retrieve an IEnumerable list and assign it as a late-bound DataSource property for the 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>Order</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        XPath="orders/order"
        DataFile="order.xml" />

      <asp:Repeater ID="Repeater1"
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h2>Order</h2>
            <table>
              <tr>
                <td>Customer</td>
                <td><%#XPath("customer/@id")%></td>
                <td><%#XPath("customername/firstn")%></td>
                <td><%#XPath("customername/lastn")%></td>
              </tr>
              <tr>
                <td>Ship To</td>
                <td><%#XPath("shipaddress/address1")%></font></td>
                <td><%#XPath("shipaddress/city")%></td>
                <td><%#XPath("shipaddress/state")%>,
                    <%#XPath("shipaddress/zip")%></td>
              </tr>
            </table>
            <h3>Order Summary</h3>
            <asp:Repeater ID="Repeater2"
                 DataSource='<%#XPathSelect("summary/item")%>'
                 runat="server">
                <ItemTemplate>
                     <b><%#XPath("@dept")%></b> -
                         <%#XPath(".")%><br />
                </ItemTemplate>
            </asp:Repeater>
            <hr />
        </ItemTemplate>
    </asp:Repeater>

  </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 runat="server">
    <title>Order</title>
</head>
<body> 
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        XPath="orders/order"
        DataFile="order.xml" />

      <asp:Repeater ID="Repeater1"
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h2>Order</h2>
            <table>
              <tr>
                <td>Customer</td>
                <td><%#XPath("customer/@id")%></td>
                <td><%#XPath("customername/firstn")%></td>
                <td><%#XPath("customername/lastn")%></td>
              </tr>
              <tr>
                <td>Ship To</td>
                <td><%#XPath("shipaddress/address1")%></font></td>
                <td><%#XPath("shipaddress/city")%></td>
                <td><%#XPath("shipaddress/state")%>,
                    <%#XPath("shipaddress/zip")%></td>
              </tr>
            </table>
            <h3>Order Summary</h3>
            <asp:Repeater ID="Repeater2"
                 DataSource='<%#XPathSelect("summary/item")%>'
                 runat="server">
                <ItemTemplate>
                     <b><%#XPath("@dept")%></b> -
                         <%#XPath(".")%><br />
                </ItemTemplate>
            </asp:Repeater>
            <hr />
        </ItemTemplate>
    </asp:Repeater>

  </form>
  </body>
</html>

第二個範例會提供 XML 檔案(Order.xml),此檔案是用來做為上面所定義 Web Form 頁面中顯示的資料來源。The second example provides the XML file, Order.xml, that is used as the source of the data displayed in the Web Forms page defined above.

<?xml version="1.0" encoding="iso-8859-1"?>  
  <orders>  
    <order>  
      <customer id="12345" />  
      <customername>  
        <firstn>John</firstn>  
        <lastn>Doe</lastn>  
      </customername>  
      <transaction id="12345" />  
      <shipaddress>  
        <address1>1234 Tenth Avenue</address1>  
        <city>Bellevue</city>  
        <state>Washington</state>  
        <zip>98001</zip>  
      </shipaddress>  
      <summary>  
        <item dept="tools">screwdriver</item>  
        <item dept="tools">hammer</item>  
        <item dept="plumbing">fixture</item>  
      </summary>  
    </order>  
 </orders>  

備註

您可以使用這個類別的多載方法,系結至針對實作為介面(例如)的 Eval 物件所執行之 XPath 運算式的結果 IXPathNavigable XmlNodeYou can use the overloaded Eval method of this class to bind to the result of an XPath expression executed against an object that implements the IXPathNavigable interface, such as an XmlNode. 您可以使用 Select 方法,將對物件執行之 XPath 運算式的結果取出 IXPathNavigableIEnumerable 節點清單。You can use the Select method to retrieve the results of an XPath expression executed against an IXPathNavigable object as an IEnumerable list of nodes. 您可以直接列舉此節點清單,或將其指派給 DataSource 清單控制項的屬性,例如 RepeaterDataListThis list of nodes can be enumerated directly or assigned to the DataSource property of a list control, such as a Repeater or DataList.

以宣告方式使用方法時,您可以使用資料系結語法的簡化版本 XPathBinderYou can use a simplified version of data-binding syntax when using the XPathBinder methods declaratively. XPathBinder.Eval Container.DataItem xpath 您可以使用 XPath () ,而不是呼叫 (,) xpathInstead of calling XPathBinder.Eval(Container.DataItem, xpath) you can use XPath(xpath). 同樣地, XPathBinder.Select Container.DataItem xpath 您可以使用 XPathSelect (xpath) 來取得一 IEnumerable 組節點,而不是呼叫 (,) 。Similarly, instead of calling XPathBinder.Select(Container.DataItem,xpath), you can use XPathSelect(xpath) to retrieve an IEnumerable set of nodes. 使用這個簡化的語法時, EvalSelect 方法會採用預設的 Container.DataItem 內容物件。When using this simplified syntax, the Eval and Select methods assume a default Container.DataItem context object.

如需有關 ASP.NET 伺服器控制項之資料系結的詳細資訊,請參閱資料系結 運算式語法For more information about data binding to ASP.NET server controls, see Data-Binding Expression Syntax.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Eval(Object, String)

評估執行階段的 XPath 資料繫結運算式。Evaluates XPath data-binding expressions at run time.

Eval(Object, String, IXmlNamespaceResolver)

透過使用 IXmlNamespaceResolver 物件 (指定用於解析 XPath 運算式中的命名空間前置詞),在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於要求的瀏覽器中。Evaluates XPath data-binding expressions at run time and formats the result as text to be displayed in the requesting browser, using the IXmlNamespaceResolver object specified to resolve namespace prefixes in the XPath expression.

Eval(Object, String, String)

在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於提出要求的瀏覽器中。Evaluates XPath data-binding expressions at run time and formats the result as text to be displayed in the requesting browser.

Eval(Object, String, String, IXmlNamespaceResolver)

透過使用 IXmlNamespaceResolver 物件 (指定用於解析 XPath 運算式中的命名空間前置詞),在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於要求的瀏覽器中。Evaluates XPath data-binding expressions at run time and formats the result as text to be displayed in the requesting browser, using the IXmlNamespaceResolver object specified to resolve namespace prefixes in the XPath expression.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
Select(Object, String)

在執行階段使用 XPath 資料繫結運算式,以傳回節點清單。Uses an XPath data-binding expression at run time to return a list of nodes.

Select(Object, String, IXmlNamespaceResolver)

透過使用 IXmlNamespaceResolver 物件 (指定用於解析 XPath 運算式中的命名空間前置詞),在執行階段使用 XPath 資料繫結運算式,以傳回節點清單。Uses an XPath data-binding expression at run time to return a list of nodes, using the IXmlNamespaceResolver object specified to resolve namespace prefixes in the XPath expression.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於