TemplateControl.XPath Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides support for parsing and evaluating an XPath data-binding expression against an object at run time.
Overloads
XPath(String, String, IXmlNamespaceResolver) |
Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution and the specified format string to display the result. |
XPath(String, IXmlNamespaceResolver) |
Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution. |
XPath(String) |
Evaluates an XPath data-binding expression. |
XPath(String, String) |
Evaluates an XPath data-binding expression using the specified format string to display the result. |
XPath(String, String, IXmlNamespaceResolver)
Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution and the specified format string to display the result.
protected public:
System::String ^ XPath(System::String ^ xPathExpression, System::String ^ format, System::Xml::IXmlNamespaceResolver ^ resolver);
protected internal string XPath (string xPathExpression, string format, System.Xml.IXmlNamespaceResolver resolver);
member this.XPath : string * string * System.Xml.IXmlNamespaceResolver -> string
Protected Friend Function XPath (xPathExpression As String, format As String, resolver As IXmlNamespaceResolver) As String
Parameters
- xPathExpression
- String
The XPath expression to evaluate. For more information, see XPathBinder.
- format
- String
A .NET Framework format string to apply to the result.
- resolver
- IXmlNamespaceResolver
A set of prefix and namespace mappings used for namespace resolution.
Returns
A string that results from the evaluation of the data-binding expression and conversion to a string type.
Exceptions
The data-binding method can be used only for controls contained on a Page.
Remarks
The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.
See also
Applies to
XPath(String, IXmlNamespaceResolver)
Evaluates an XPath data-binding expression using the specified prefix and namespace mappings for namespace resolution.
protected public:
System::Object ^ XPath(System::String ^ xPathExpression, System::Xml::IXmlNamespaceResolver ^ resolver);
protected internal object XPath (string xPathExpression, System.Xml.IXmlNamespaceResolver resolver);
member this.XPath : string * System.Xml.IXmlNamespaceResolver -> obj
Protected Friend Function XPath (xPathExpression As String, resolver As IXmlNamespaceResolver) As Object
Parameters
- xPathExpression
- String
The XPath expression to evaluate. For more information, see XPathBinder.
- resolver
- IXmlNamespaceResolver
A set of prefix and namespace mappings used for namespace resolution.
Returns
An object that results from the evaluation of the data-binding expression.
Exceptions
The data-binding method can be used only for controls contained on a Page.
Remarks
The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.
See also
Applies to
XPath(String)
Evaluates an XPath data-binding expression.
protected public:
System::Object ^ XPath(System::String ^ xPathExpression);
protected internal object XPath (string xPathExpression);
member this.XPath : string -> obj
Protected Friend Function XPath (xPathExpression As String) As Object
Parameters
- xPathExpression
- String
The XPath expression to evaluate. For more information, see XPathBinder.
Returns
An object that results from the evaluation of the data-binding expression.
Exceptions
The data-binding method can be used only for controls contained on a Page.
Examples
The following code example demonstrates how to use the XPath method in a 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>TemplateControl XPath and XPathSelect Example</title>
</head>
<body>
<h3>TemplateControl XPath Example</h3>
<form id="form1" runat="server">
<div>
<asp:XmlDataSource
id="XmlDataSource1"
runat="server"
XPath="contacts"
DataFile="contacts.xml" />
<asp:FormView
id="FormView1"
runat="server"
DataSourceID="XmlDataSource1">
<ItemTemplate>
<hr />
<asp:Repeater
id="Repeater1"
runat="server"
DataSource='<%# XPathSelect("contact") %>' >
<ItemTemplate>
Name: <%# XPath("name") %> <br />
Note: <%# XPath("note") %> <br />
<hr />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:FormView>
</div>
</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 id="Head1" runat="server">
<title>TemplateControl XPath Example</title>
</head>
<body>
<h3>TemplateControl XPath and XPathSelect Example</h3>
<form id="form1" runat="server">
<div>
<asp:XmlDataSource
id="XmlDataSource1"
runat="server"
XPath="contacts"
DataFile="contacts.xml" />
<asp:FormView
id="FormView1"
runat="server"
DataSourceID="XmlDataSource1">
<ItemTemplate>
<hr />
<asp:Repeater
id="Repeater1"
runat="server"
DataSource='<%# XPathSelect("contact") %>' >
<ItemTemplate>
Name: <%# XPath("name") %> <br />
Note: <%# XPath("note") %> <br />
<hr />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
The following test XML data can be used in the preceding code example.
<contacts>
<contact id="1">
<name>contact name 1</name>
<note>contact note 1</note>
</contact>
<contact id="2">
<name>contact name 2</name>
<note>contact note 2</note>
</contact>
</contacts>
Remarks
The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.
See also
Applies to
XPath(String, String)
Evaluates an XPath data-binding expression using the specified format string to display the result.
protected public:
System::String ^ XPath(System::String ^ xPathExpression, System::String ^ format);
protected internal string XPath (string xPathExpression, string format);
member this.XPath : string * string -> string
Protected Friend Function XPath (xPathExpression As String, format As String) As String
Parameters
- xPathExpression
- String
The XPath expression to evaluate. For more information, see XPathBinder.
- format
- String
A .NET Framework format string to apply to the result.
Returns
A string that results from the evaluation of the data-binding expression and conversion to a string type.
Exceptions
The data-binding method can be used only for controls contained on a Page.
Remarks
The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.
See also
Applies to
.NET