XPathBinder.Select メソッド

定義

実行時に XPath データ バインディング式を使用してノードのリストを返します。

オーバーロード

Select(Object, String)

実行時に XPath データ バインディング式を使用してノードのリストを返します。

Select(Object, String, IXmlNamespaceResolver)

XPath 式の名前空間プレフィックスを解決するために指定される IXmlNamespaceResolver オブジェクトを使用し、実行時に XPath データ バインディング式を使用してノードのリストを返します。

注釈

XPath クエリを使用して一連のノードの取得を簡略化する場合は、宣言によってオーバーロードされた Select メソッドを使用できます。 そのためには、標準の <%# and %> ASP.NET データ バインディングでも使用されるタグを XPath クエリの周囲に配置する必要があります。

Select(Object, String)

実行時に XPath データ バインディング式を使用してノードのリストを返します。

public:
 static System::Collections::IEnumerable ^ Select(System::Object ^ container, System::String ^ xPath);
public static System.Collections.IEnumerable Select (object container, string xPath);
static member Select : obj * string -> System.Collections.IEnumerable
Public Shared Function Select (container As Object, xPath As String) As IEnumerable

パラメーター

container
Object

式の評価に使用する IXPathNavigable オブジェクト参照。 これは、ページの指定された言語による有効なオブジェクト識別子である必要があります。

xPath
String

ノードのリストを取得する XPath クエリ。

戻り値

IEnumerable

ノードの IEnumerable リスト。

例外

container パラメーターまたは xpath パラメーターが null です。

container で指定されたオブジェクトが IXPathNavigable ではありません。

XPathNodeIterator の現在のノードに関連付けられた XML ノードがありません。

次のコード例は、テンプレート 化されたRepeaterコントロールでコントロールをXmlDataSource使用して XML データを表示する方法を示しています。 この例には、次の 2 つの部分があります。

  • XML データを表示するWeb Forms ページ。

  • データを含む XML ファイル。

この例の最初の部分は、コントロールを介してアクセスされる XML データを表示するWeb Forms ページをXmlDataSource示しています。 コントロールは Repeater 、簡略化された Eval(Object, String) メソッド構文を使用して、表す XML ドキュメント内のデータ項目に XmlDataSource バインドします。 このメソッドを Select(Object, String) 使用してリストを IEnumerable 取得し、コントロールの遅延バインディング DataSource プロパティ Repeater として割り当てます。

<%@ 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>

2 番目の例では、上で定義したWeb Forms ページに表示されるデータのソースとして使用される XML ファイルOrder.xmlを提供します。

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

注釈

XPath クエリを Select(Object, String) 使用してノードのセットの取得を簡略化する場合は、宣言によってこのメソッドを使用できます。 そのためには、標準の <%# and %> ASP.NET データ バインディングでも使用されるタグを XPath クエリの周囲に配置する必要があります。

サーバー コントロール DataListcontainer DataGridRepeaterASP.NET 一覧 (、 など) の場合、パラメーターは 〗 にするContainer.DataItem必要があります。

適用対象

Select(Object, String, IXmlNamespaceResolver)

XPath 式の名前空間プレフィックスを解決するために指定される IXmlNamespaceResolver オブジェクトを使用し、実行時に XPath データ バインディング式を使用してノードのリストを返します。

public:
 static System::Collections::IEnumerable ^ Select(System::Object ^ container, System::String ^ xPath, System::Xml::IXmlNamespaceResolver ^ resolver);
public static System.Collections.IEnumerable Select (object container, string xPath, System.Xml.IXmlNamespaceResolver resolver);
static member Select : obj * string * System.Xml.IXmlNamespaceResolver -> System.Collections.IEnumerable
Public Shared Function Select (container As Object, xPath As String, resolver As IXmlNamespaceResolver) As IEnumerable

パラメーター

container
Object

式の評価に使用する IXPathNavigable オブジェクト参照。 これは、ページの指定された言語による有効なオブジェクト識別子である必要があります。

xPath
String

ノードのリストを取得する XPath クエリ。

resolver
IXmlNamespaceResolver

XPath 式の名前空間プレフィックスの解決に使用する IXmlNamespaceResolver オブジェクト。

戻り値

IEnumerable

ノードの IEnumerable リスト。

注釈

XPath クエリを Select 使用して一連のノードの取得を簡略化する場合は、宣言によってこのメソッドを使用できます。 そのためには、XPath クエリとIXmlNamespaceResolver名前空間参照を<%# and %>解決するオブジェクトの周囲に、標準の ASP.NET データ バインディングでも使用されるタグを配置する必要があります。

サーバー コントロール DataListDataGridRepeaterASP.NET リスト (、など) の場合は、パラメーターをcontainer指定する必要があります。Container.DataItem

適用対象