XmlDataSource and XPath : XmlDataSource « XML « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:XmlDataSource ID="sourceDVD" 
                           runat="server" 
                           DataFile="~/Data.xml" 
                           XPath="/DvdList/DVD/Starring/Star"/>
           <asp:GridView ID="GridView1" 
                         runat="server" 
                         DataSourceID="sourceDVD" 
                         AutoGenerateColumns="False">
              <Columns>
                <asp:TemplateField HeaderText="DVD">
                  <ItemTemplate>
                    <%# XPath(".")%><br />
                  </ItemTemplate>
                </asp:TemplateField>
              </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>

File: Data.xml

<?xml version="1.0"?>
<DvdList>
   <DVD ID="1" Category="Category 1">
      <Title>title 1</Title>
      <Director>directory 2</Director>
      <Price>1</Price>
      <Starring>
         <Star>star 1</Star>
         <Star>star 2</Star>
      </Starring>
   </DVD>
   <DVD ID="2" Category="Category 2">
      <Title>title 2</Title>
      <Director>directory 2</Director>
      <Price>2</Price>
      <Starring>
         <Star>star 3</Star>
         <Star>star 4</Star>
      </Starring>
   </DVD>
</DvdList>








25.9.XmlDataSource
25.9.1.Create XmlDataSource
25.9.2.Displaying an XML document with the Menu control.
25.9.3.XmlDataSource and XPath
25.9.4.Transform XmlDataSource with XSLT