Reader Level:
ARTICLE

How to Use XMLDataSource and How to Append XML in a File

Posted by Biswa Pujarini Mohapatra Articles | XML December 15, 2010
XML is an important format for storing and retrieving data on the web and the reason is it can be moved between firewalls.
  • 0
  • 0
  • 7688

Introduction

XML is an important format for storing and retrieving data on the web and the reason is it can be moved between firewalls. We see many websites with RSS and XML output. Many visitors use them to save their time and increase their speed for viewing their favorite websites and web logs.

<Categories>
  <
Category>
    <
ID>2</ID>
    <Name>xxx</Name>
  </Category>
  <
Category>
    <
ID>3</ID>
    <Name>XYZ</Name>
  </Category>
  <
Category>
    <
ID>4</ID>
    <Name>ABC</Name>
  </Category>
</
Categories>

Bind XMLDataSource to a Repeater

   <asp:Repeater ID="rpt1" runat="server" DataSourceID="XmlDataSource1">
            <HeaderTemplate>
                <table>
                    <tr style="background-color: #000; color: #fff; width: 50%">
                        <td>
                            ID
                        </td>
                        <td>
                            Name
                        </td>
                    </tr>
                </table>
            </HeaderTemplate>
            <ItemTemplate>
                <table>
                    <tr>
                        <td>
                            <%# XPath("ID") %>
                        </td>
                        <td>
                            <%#XPath("Name")%>
                        </td>
                    </tr>
                </table>
                </strong>
            </ItemTemplate>
        </asp:Repeater>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XML/XMLFile.xml"
            XPath="Categories/Category"></asp:XmlDataSource>

I am using XLinq to append xml data to a file. By using XLinq we can modify an xml document very easily. Please download the source code to see the example.

COMMENT USING

Trending up