Read XML file into GridView

G

Guest

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>
<description> listeners 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:blush:wner>
<itunes:name>sss.com</itunes:name>
<itunes:email>[email protected]</itunes:email>
</itunes:blush:wner>
<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>
 
G

Guest

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.SelectSingleNode("enclosure").Attributes["url"].InnerText
, items.SelectSingleNode("title").InnerText
, items.SelectSingleNode("description").InnerText ) ) ;//"<br>"
+ items.SelectSingleNode("title").InnerText + "<br>" ) ;
}

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

Guest

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 said:
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.SelectSingleNode("enclosure").Attributes["url"].InnerText
, items.SelectSingleNode("title").InnerText
, items.SelectSingleNode("description").InnerText ) ) ;//"<br>"
+ items.SelectSingleNode("title").InnerText + "<br>" ) ;
}

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

--
dba123


dba123 said:
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>
<description> listeners 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:blush:wner>
<itunes:name>sss.com</itunes:name>
<itunes:email>[email protected]</itunes:email>
</itunes:blush:wner>
<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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top