Reader Level:
Articles

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

By Biswa Pujarini Mohapatra on 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
  • 7804

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.

Biswa Pujarini Mohapatra

Biswa Pujarini has over 9 years of experience in Microsoft technologies. She is working at Microsoft R&D India as Development lead. She has worked on various domains. She is a active blogger, developer, consultant an... Read more

COMMENT USING

Trending up