XmlDataSource Control in ASP.Net
XmlDataSource is usually used to display read only XML data.
<asp:XmlDataSource ID="XmlDataSource1"
runat="server">
</asp:XmlDataSource>
Important
properties of XmlDataSource Control
·
DataFile: This property allows specifying the
name of XML file that the XmlDataSource control binds to. You can specify either
absolute file path or relative file path of XML file.
·
Data: This property gets or sets the block of XML
data that the XmlDataSource control binds to. We can bind XML data inline using
this property. If both DataFile and Data properties are set, the DataFile
property takes precedence and the data in the XML file is used instead of XML
data specified in Data property.
·
XPath: This property specifies an XPath
expression which acts as filter the XML file contained by DataFile property or
XML data specified by Data property.
Binding XMLDataSource to GridView
<asp:GridView
ID="GridView1"
runat="server"
DataSourceID="XmlDataSource"
AutoGenerateColumns="False" ShowFooter="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%#XPath("@name")
%><br
/>
<%#XPath("State")%><br
/>
<%#XPath("city")%><br
/> </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource" runat="server"DataFile="~/XMLFile.xml"
XPath="IranHistoricalPlaces/Place">
</asp:XmlDataSource>


|