XPathBinder XPathBinder XPathBinder XPathBinder Class

定義

提供對快速應用程式開發 (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
繼承
XPathBinderXPathBinderXPathBinderXPathBinder

範例

下列程式碼範例示範如何使用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 Forms 頁面。A Web Forms page that displays XML data.

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

範例的第一個部分顯示 Web form 頁面, 其中顯示透過XmlDataSource控制項存取的 XML 資料。The first part of the example shows a Web Forms page that displays XML data accessed through an XmlDataSource control. 控制項使用簡化Eval(Object, String)的方法語法, 系結至所XmlDataSource代表的 XML 檔中的資料項目。 RepeaterA 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取出清單, 並將它指派為Repeater控制項的晚期DataSource綁定屬性。It 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 檔案, 也就是 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的多載方法, 針對執行IXPathNavigable XmlNode介面的物件 (例如), 系結至 XPath 運算式的結果。You 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方法, 將IXPathNavigable針對物件執行之 XPath 運算式的結果, 抓取為IEnumerable節點清單。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.

以宣告方式使用XPathBinder方法時, 您可以使用資料系結語法的簡化版本。You can use a simplified version of data-binding syntax when using the XPathBinder methods declaratively. 您可以使用XPathBinder.Eval xpath Container.DataItem ()xpath, 而不是呼叫 (,)。 XPathInstead of calling XPathBinder.Eval(Container.DataItem, xpath) you can use XPath(xpath). 同樣XPathBinder.Select地,xpath Container.DataItem您可以XPathSelect使用 ()xpath來抓取節點集,而不是呼叫IEnumerable (,)。Similarly, instead of calling XPathBinder.Select(Container.DataItem,xpath), you can use XPathSelect(xpath) to retrieve an IEnumerable set of nodes. 使用這個簡化的Eval語法時, 和Select方法會採用預設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) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
Eval(Object, String) Eval(Object, String) Eval(Object, String) Eval(Object, String)

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

Eval(Object, String, IXmlNamespaceResolver) Eval(Object, String, IXmlNamespaceResolver) Eval(Object, String, IXmlNamespaceResolver) 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) Eval(Object, String, String) Eval(Object, String, String) 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) Eval(Object, String, String, IXmlNamespaceResolver) Eval(Object, String, String, IXmlNamespaceResolver) 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() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Select(Object, String) Select(Object, String) Select(Object, String) Select(Object, String)

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

Select(Object, String, IXmlNamespaceResolver) Select(Object, String, IXmlNamespaceResolver) Select(Object, String, IXmlNamespaceResolver) 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() ToString() ToString() ToString()

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

(Inherited from Object)

適用於