By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

Read XML file into GridView

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.