XmlDataSource.XPath Proprietà

Definizione

Specifica un'espressione XPath da applicare ai dati XML contenuti dalla proprietà Data o dal file XML indicato dalla proprietà DataFile.

public:
 virtual property System::String ^ XPath { System::String ^ get(); void set(System::String ^ value); };
public virtual string XPath { get; set; }
member this.XPath : string with get, set
Public Overridable Property XPath As String

Valore della proprietà

Stringa che rappresenta un'espressione XPath che può essere utilizzata per filtrare i dati contenuti dalla proprietà Data o dal file XML indicato dalla proprietà DataFile. Il valore predefinito è Empty.

Eccezioni

È in corso il caricamento del documento.

Esempio

Nell'esempio di codice seguente viene illustrato come usare un controllo con un XmlDataSource controllo modello per visualizzare i dati XML filtrati Repeater usando un'espressione XPath. In questo esempio, la sintassi XPath viene usata per filtrare i dati XML quando viene impostata la XPath proprietà del controllo origine dati e associa anche gli elementi del Repeater modello di controllo ai dati XML.

<%@ 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>ASP.NET Example</title>
</head>
<body>

    <form id="form1" runat="server">
      <asp:XmlDataSource
        id="XmlSource"
        DataFile="bookstore.xml"
        runat="server"
        XPath="bookstore/genre[@name='fiction']"/>

      <asp:Repeater
        DataSourceID="XmlSource"
        runat="server">
          <ItemTemplate>
              <h1><%# XPath ("book/title") %></h1>
              <b>Price:</b>
              <%# XPath ("book/price") %>
          </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>ASP.NET Example</title>
</head>
<body>

    <form id="form1" runat="server">
      <asp:XmlDataSource
        id="XmlSource"
        DataFile="bookstore.xml"
        runat="server"
        XPath="bookstore/genre[@name='fiction']"/>

      <asp:Repeater
        DataSourceID="XmlSource"
        runat="server">
          <ItemTemplate>
              <h1><%# XPath ("book/title") %></h1>
              <b>Price:</b>
              <%# XPath ("book/price") %>
          </ItemTemplate>
      </asp:Repeater>
    </form>

  </body>
</html>

Il file XML nell'esempio di codice contiene i dati seguenti:

<bookstore>  
   <genre name="fiction">  
     <book ISBN="0000000000">  
       <title>Secrets of Silicon Valley</title>  
       <price>12.95</price>  
       <chapters>  
         <chapter num="1" name="Introduction" />             
         <chapter num="2" name="Body" />            
         <chapter num="3" name="Conclusion" />  
       </chapters>  
     </book>  
   </genre>  
   <genre name="novel">  
     <book genre="novel" ISBN="1111111111">  
       <title>Straight Talk About Computers</title>  
       <price>24.95</price>  
       <chapters>  
         <chapter num="1" name="Introduction" />   
         <chapter num="2" name="Body" />  
         <chapter num="3" name="Conclusion" />  
       </chapters>  
     </book>  
   </genre>  
</bookstore>  

Commenti

Per altre informazioni sulle espressioni di data binding XPath, vedere Associazione di un controllo tabulare al controllo XmlDataSource.

Si applica a