XmlDataSource.XPath Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
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
Valor de Propriedade
Uma cadeia que representa uma expressão XPath que pode ser usada para filtrar os dados contidos pela Data propriedade ou pelo ficheiro XML indicado pela DataFile propriedade. O valor predefinido é Empty.
Exceções
O documento está a carregar.
Exemplos
O exemplo de código seguinte demonstra como usar um XmlDataSource controlo com um controlo templateado Repeater para exibir dados XML que foram filtrados usando uma expressão XPath. Neste exemplo, a sintaxe XPath é usada para filtrar os dados XML quando a XPath propriedade do controlo de fonte de dados está definida, e também associa elementos do Repeater template de controlo aos dados 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>
O ficheiro XML no exemplo de código tem os seguintes dados:
<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>
Observações
Para mais informações sobre expressões de ligação de dados XPath, veja Ligar um Controlo Tabular ao Controlo XmlDataSource.