Create asp XmlDataSource : XmlDataSource « XML « ASP.Net






Create asp XmlDataSource

<%--
Code Revised from
       
Professional ASP.NET 2.0 XML (Programmer to Programmer) (Paperback)
by Thiru Thangarathinam 

# Publisher: Wrox (January 18, 2006)
# Language: English
# ISBN: 0764596772
--%>       
                   
       
       
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Binding XML Data from an XmlDataSource Control</title>
</head>
<body>    
    <form id="form1" runat="server">
    <div>
        <asp:TreeView ID="TreeView1" Runat="server" DataSourceID="XmlDataSource1">
            <DataBindings>
                <asp:TreeNodeBinding ImageUrl="openbook.gif" TextField="Title" DataMember="book"></asp:TreeNodeBinding>
                <asp:TreeNodeBinding ImageUrl="notepad.gif" TextField="name" DataMember="chapter"></asp:TreeNodeBinding>
            </DataBindings>
        </asp:TreeView>    
    </div>
        <div>
            <asp:XmlDataSource ID="XmlDataSource1" Runat="server" DataFile="Bookstore.xml"
                XPath="bookstore/genre[@name='Fiction']/book">
            </asp:XmlDataSource>
        </div>
    </form>

XPath="bookstore/genre[@name='Fiction']/book"</body>
</html>


<%-- Bookstore.xml
<bookstore>
  <genre name="Fiction">
    <book ISBN="10-861003-324" Title="title 1" Price="19.99">
      <chapter num="1" name="Introduction">
        A
      </chapter>
      <chapter num="2" name="Body">
        B
      </chapter>
      <chapter num="3" name="Conclusion">
        C
      </chapter>
    </book>
    <book ISBN="1-861001-57-5" Title="title " Price="24.95">
      <chapter num="1" name="Introduction">
        D
      </chapter>
      <chapter num="2" name="Body">
        E
      </chapter>
      <chapter num="3" name="Conclusion">
        F
      </chapter>
    </book>   
  </genre>
  <genre name="NonFiction">
    <book ISBN="10-861003-324" Title="title 2" Price="19.99">
      <chapter num="1" name="Introduction">
        G
      </chapter>
      <chapter num="2" name="Body">
        H
      </chapter>
      <chapter num="3" name="Conclusion">
        I
      </chapter>
    </book>   
    <book ISBN="1-861001-57-6" Title="title 3" Price="27.95">
      <chapter num="1" name="Introduction">
        J
      </chapter>
      <chapter num="2" name="Body">
        K
      </chapter>
      <chapter num="3" name="Conclusion">
        L
      </chapter>
    </book>
  </genre>
</bookstore>
--%>
           
       








Related examples in the same category

1.asp:Xml datasource
2.Caching XML Data in an XmlDataSource Control
3.Binding XML Data from an XmlDataSource Control
4.Using Inline XML Data in an XmlDataSource Control
5.Binding XML Data from Other Sources
6.Updating Data through XmlDataSource Control
7.Programmatically Creating an XmlDataSource Control
8.Handling XmlDataSource Events
9.Fill XmlDataSource with your code
10.XmlDataSource and XML document
11.Use ItemTemplate and XPath to display data from XmlDataSource
12.Using the XmlDataSource control to consume an RSS feed
13.Enter an XML filename or raw XML starting with