I've seen some articles on this forum on binding a gridview to an xml document. I'm looking to bind a gridview to a local xml file so that items in the file can be updated, added, and deleted via the gridview control. The XML file is in RSS format:
I've seen and tried many examples that can read an RSS format XML file, with code such as:
Dim ds as New DataSet
ds.ReadXML(Server.Mappath("myfile.xml"))
grid1.DataSource = ds.Tables(2)
grid1.Databind()
But I'm having trouble with the code for adding an item to the file. Code such as:
dim dr as datarow
dr = ds.Tables("item").NewRow()
dr(0) = text1.text
...
dr(3) = text4.text
ds.tables("item").rows.add(dr)
ds.writeXML(Server.Mappath("myfile.xml"))
fails with: "Token StartElement in state Epilog would result in an invalid XML document"
I think the problem might be because of the rss format with additional <rss> and <channel> tags
Sorry but I don't think a good idea to load rss feeds in the DataTable,maybe you should create a DataTable mapping to a certain physical table in a specific database,and then read this things out and output it in the form of XML.
Please read this:http://www.dotnettutorials.com/tutorials/advanced/rss-feed-asp-net-vb.aspx (You can read data with the help of SqlDataReader and then use this torturial to output xml contents)
Joef44
0 Points
2 Posts
Question on binding datagrid to rss XML file
Sep 07, 2012 03:37 PM|LINK
I've seen some articles on this forum on binding a gridview to an xml document. I'm looking to bind a gridview to a local xml file so that items in the file can be updated, added, and deleted via the gridview control. The XML file is in RSS format:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>xx</title>
<link>xx</link>
<description>xx</description>
<item>
<title>xx</title>
<link>xx</link>
<description>xx</description>
</item>
</channel>
</rss>
Any help would be appreciated.
urenjoy
Star
12255 Points
1841 Posts
Re: Question on binding datagrid to rss XML file
Sep 08, 2012 10:08 AM|LINK
To display RSS file in Gridview, check following and give xml file path:
http://www.codeproject.com/Articles/16283/How-to-bind-RSS-feeds-to-a-GridView
To add/edit/delete, check following:
http://forums.asp.net/t/1230594.aspx
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Question on binding datagrid to rss XML file
Sep 09, 2012 12:58 AM|LINK
Hello
:)I think you can make sure that your xml contents that can be converted to that of a DataTable type,and then bind to the GridView directly.
In fact you can download the sample:http://www.codeproject.com/Articles/18280/Edit-XML-files-using-a-GridView
Reguards!
Joef44
0 Points
2 Posts
Re: Question on binding datagrid to rss XML file
Sep 11, 2012 06:41 PM|LINK
I've seen and tried many examples that can read an RSS format XML file, with code such as:
Dim ds as New DataSet
ds.ReadXML(Server.Mappath("myfile.xml"))
grid1.DataSource = ds.Tables(2)
grid1.Databind()
But I'm having trouble with the code for adding an item to the file. Code such as:
dim dr as datarow
dr = ds.Tables("item").NewRow()
dr(0) = text1.text
...
dr(3) = text4.text
ds.tables("item").rows.add(dr)
ds.writeXML(Server.Mappath("myfile.xml"))
fails with: "Token StartElement in state Epilog would result in an invalid XML document"
I think the problem might be because of the rss format with additional <rss> and <channel> tags
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Question on binding datagrid to rss XML file
Sep 12, 2012 12:21 AM|LINK
Joef44:)
Sorry but I don't think a good idea to load rss feeds in the DataTable,maybe you should create a DataTable mapping to a certain physical table in a specific database,and then read this things out and output it in the form of XML.
Please read this:http://www.dotnettutorials.com/tutorials/advanced/rss-feed-asp-net-vb.aspx (You can read data with the help of SqlDataReader and then use this torturial to output xml contents)
Hope this helps & Reguards!