473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Read XML file into GridView

I need help in coding the following or if you can just point me in the right
direction:

1) Reading the follwoing XML document
2) Hook up a GridView to the data received from the XML document. The Grid
should read lke this:

Title
Description
Title
Descripti0n

....and so on

Here's the XML document format (I replaced our stuff with fake text for
privacy p urposes...so ignore the weirdness of the text values):

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>Ken Smith<title>
<link>http://www.sss.com</link>
<language>en-us</language>
<itunes:subtitle>Rroundtable for a lively discussion of the week's
news.</itunes:subtitle>
<itunes:author>sss.com</itunes:author>
<descriptionlisteners turn to the Editors Roundtable for...
</description>
<image>
<url>http://localhost/images/header/sss_logo.jpg</url>
<title>Roundtable</title>
<link>http://www.sss.com</link>
</image>
<itunes:owner>
<itunes:name>sss.com</itunes:name>
<itunes:email>in**@csss.com</itunes:email>
</itunes:owner>
<itunes:image href="http://www.sss.com/images/header/sss_logo.jpg"
/>
<itunes:category text="sdfdfsd" />
<item>
<title>Recent trip to Chiapas</title>
<link>http://localhost/interact/podcasts/mp3s</link>
<description>Retrip to Chiapas, Mexico. This award-winning
author, and Mexican...</description>
<enclosure
url="http://localhost/interact/podcasts/mp3s/ss_Final.mp3" type="audio/mp3" />
<pubDate>Wed, 16 Aug 2006 13:00:00 GMT</pubDate>
<itunes:author>sss</itunes:author>
<itunes:duration>12:33</itunes:duration>
</item>
<item>
<title>Adam Smith</title>
<link>http://localhost/interact/podcasts/mp3s</link>
<description>Ken from ssscom discusses....</description>
<enclosure
url="http://localhost/interact/podcasts/mp3s/Seger2FINAL.mp3"
type="audio/mp3" />
<pubDate>Wed, 09 Aug 2006 13:00:00 GMT</pubDate>
<itunes:author>Ken Smoth</itunes:author>
<itunes:duration>8:27</itunes:duration>
</item>
--
dba123
Aug 28 '06 #1
2 13284
This is the code we had before when we were reading it into a texbox. I want
to instead read this into a GridView

try
{
StringBuilder sb = new StringBuilder();
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("/interact/podcasts/rss/podcast.xml"));

XmlNodeList items = doc.SelectNodes("//item");

for (int i=0; i<items.Count ; i++)
{

sb.Append( string.Format( "<tr valign='top'><td><a href={0}><img
src='/images/interact/icon_podcast.gif' border=0></a></td><td><a
href={0}>{1}</a></td></tr><tr><td></td><td>{2}</td></tr><tr><td><img
src='/images/spacer.gif' width=1 height=3 border=0 alt=''></td></tr>"
, items[i].SelectSingleNode("enclosure").Attributes["url"].InnerText
, items[i].SelectSingleNode("title").InnerText
, items[i].SelectSingleNode("description").InnerText ) ) ;//"<br>"
+ items[i].SelectSingleNode("title").InnerText + "<br>" ) ;
}

Now I want to read teh sb.ToString to GridView...

--
dba123
"dba123" wrote:
I need help in coding the following or if you can just point me in the right
direction:

1) Reading the follwoing XML document
2) Hook up a GridView to the data received from the XML document. The Grid
should read lke this:

Title
Description
Title
Descripti0n

...and so on

Here's the XML document format (I replaced our stuff with fake text for
privacy p urposes...so ignore the weirdness of the text values):

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>Ken Smith<title>
<link>http://www.sss.com</link>
<language>en-us</language>
<itunes:subtitle>Rroundtable for a lively discussion of the week's
news.</itunes:subtitle>
<itunes:author>sss.com</itunes:author>
<descriptionlisteners turn to the Editors Roundtable for...
</description>
<image>
<url>http://localhost/images/header/sss_logo.jpg</url>
<title>Roundtable</title>
<link>http://www.sss.com</link>
</image>
<itunes:owner>
<itunes:name>sss.com</itunes:name>
<itunes:email>in**@csss.com</itunes:email>
</itunes:owner>
<itunes:image href="http://www.sss.com/images/header/sss_logo.jpg"
/>
<itunes:category text="sdfdfsd" />
<item>
<title>Recent trip to Chiapas</title>
<link>http://localhost/interact/podcasts/mp3s</link>
<description>Retrip to Chiapas, Mexico. This award-winning
author, and Mexican...</description>
<enclosure
url="http://localhost/interact/podcasts/mp3s/ss_Final.mp3" type="audio/mp3" />
<pubDate>Wed, 16 Aug 2006 13:00:00 GMT</pubDate>
<itunes:author>sss</itunes:author>
<itunes:duration>12:33</itunes:duration>
</item>
<item>
<title>Adam Smith</title>
<link>http://localhost/interact/podcasts/mp3s</link>
<description>Ken from ssscom discusses....</description>
<enclosure
url="http://localhost/interact/podcasts/mp3s/Seger2FINAL.mp3"
type="audio/mp3" />
<pubDate>Wed, 09 Aug 2006 13:00:00 GMT</pubDate>
<itunes:author>Ken Smoth</itunes:author>
<itunes:duration>8:27</itunes:duration>
</item>
--
dba123
Aug 28 '06 #2
Hi

Not sure about this approach, but a try ..

Why don't u read the xml in a dataset, using the ReadXML method and once you
have the info in dataset, you could bind the necessary columns in the
Gridview.

Prem

"dba123" wrote:
This is the code we had before when we were reading it into a texbox. I want
to instead read this into a GridView

try
{
StringBuilder sb = new StringBuilder();
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("/interact/podcasts/rss/podcast.xml"));

XmlNodeList items = doc.SelectNodes("//item");

for (int i=0; i<items.Count ; i++)
{

sb.Append( string.Format( "<tr valign='top'><td><a href={0}><img
src='/images/interact/icon_podcast.gif' border=0></a></td><td><a
href={0}>{1}</a></td></tr><tr><td></td><td>{2}</td></tr><tr><td><img
src='/images/spacer.gif' width=1 height=3 border=0 alt=''></td></tr>"
, items[i].SelectSingleNode("enclosure").Attributes["url"].InnerText
, items[i].SelectSingleNode("title").InnerText
, items[i].SelectSingleNode("description").InnerText ) ) ;//"<br>"
+ items[i].SelectSingleNode("title").InnerText + "<br>" ) ;
}

Now I want to read teh sb.ToString to GridView...

--
dba123
"dba123" wrote:
I need help in coding the following or if you can just point me in the right
direction:

1) Reading the follwoing XML document
2) Hook up a GridView to the data received from the XML document. The Grid
should read lke this:

Title
Description
Title
Descripti0n

...and so on

Here's the XML document format (I replaced our stuff with fake text for
privacy p urposes...so ignore the weirdness of the text values):

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>Ken Smith<title>
<link>http://www.sss.com</link>
<language>en-us</language>
<itunes:subtitle>Rroundtable for a lively discussion of the week's
news.</itunes:subtitle>
<itunes:author>sss.com</itunes:author>
<descriptionlisteners turn to the Editors Roundtable for...
</description>
<image>
<url>http://localhost/images/header/sss_logo.jpg</url>
<title>Roundtable</title>
<link>http://www.sss.com</link>
</image>
<itunes:owner>
<itunes:name>sss.com</itunes:name>
<itunes:email>in**@csss.com</itunes:email>
</itunes:owner>
<itunes:image href="http://www.sss.com/images/header/sss_logo.jpg"
/>
<itunes:category text="sdfdfsd" />
<item>
<title>Recent trip to Chiapas</title>
<link>http://localhost/interact/podcasts/mp3s</link>
<description>Retrip to Chiapas, Mexico. This award-winning
author, and Mexican...</description>
<enclosure
url="http://localhost/interact/podcasts/mp3s/ss_Final.mp3" type="audio/mp3" />
<pubDate>Wed, 16 Aug 2006 13:00:00 GMT</pubDate>
<itunes:author>sss</itunes:author>
<itunes:duration>12:33</itunes:duration>
</item>
<item>
<title>Adam Smith</title>
<link>http://localhost/interact/podcasts/mp3s</link>
<description>Ken from ssscom discusses....</description>
<enclosure
url="http://localhost/interact/podcasts/mp3s/Seger2FINAL.mp3"
type="audio/mp3" />
<pubDate>Wed, 09 Aug 2006 13:00:00 GMT</pubDate>
<itunes:author>Ken Smoth</itunes:author>
<itunes:duration>8:27</itunes:duration>
</item>
--
dba123
Aug 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lelle | last post by:
hello! how can i read a csv file with this syntax into my gridview? SSN","First Name","Last Name","Salary","Department 111-11-1111","Ann","Adams","60000.00","Accounting...
0
by: Hongbo | last post by:
Hi, I have a GridView like this one: == <asp:gridview runat="server" id="gvCategory" allowpaging="true" allowsorting="true" alternatingrowstyle-backcolor="#B9DFC7" autogeneratecolumns="false" ...
0
by: Michael Kellogg | last post by:
I have a problem wherein a query that updates a GridView doesn't seem to really stay in sync with a label I have above the GridView. I have a GridView object that I'm updating with information...
1
by: hal | last post by:
Hello All, I have a windows form with a gridview control and i'm trying to get the gridview to read the entire XML file. Anyone have any ideas on how to do this? Below is some code so you can...
2
by: cartmann | last post by:
Hi, I have a gridview with a template column. In the template column i have two commandbuttons. When clicking the buttons I enter the cmd_click event - but how do I read in which row the button...
0
by: ntuyen01 | last post by:
Hi All, I try to read the data from the excel, but I ran into this problem I have two excel files. file one.xls data inside like this: 1234 1234 1234 1234 abc-123 ...
0
gchq
by: gchq | last post by:
Hi there It is required that some XML data be read by DataTable - this seems to require the xs:element layout :- <XmlDemo> <id>0</id> <Status>Single</Status> <Lower>0</Lower> ...
0
by: mohaaron | last post by:
I am finding that when a GridView is export to Excel by changing the ContentType of the page the Excel file is not readable by OleDb or SQL Server DTS. I also tried using a Excel Reader that I...
3
by: Mel | last post by:
How do I open an Excel file as a read only document? It would be okay if it opened in the browser window but I don't want the user to save any changes and stomp over my original file on the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.