Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to solve this? The headache is growing.

Reply
Thread Tools

How to solve this? The headache is growing.

 
 
Shapper
Guest
Posts: n/a
 
      06-17-2005
Hello,

I have a XML file (RSS 2.0 format). Something as follows:

<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>News</title>
<description>Latest News</description>
<item>
<title>Title</title>
<link>Url</link>
<description>Description</description>
<pubDate>Fri, 20 May 2005 12:30:00 GMT</pubDate>
</item>
...

I need to do the following:

1. Load the 10 most recent items (using pubDate as reference).

2. Place the loaded items in a dataset.

3. pubDate must be a valid ASP.Net date/time format.
I think the standard XML pubDate format is not:
Fri, 20 May 2005 12:30:00 GMT

Well, at least I am getting a string in my dataset [pubDate] field.

I am having huge problems with (1) and (3).

Here is my code:

Dim news As New XmlDocument()
news.Load("http://www.domain.com/news.rss")
Dim x As Integer
Dim xNodeList As XmlNodeList =
news.SelectNodes("/rss[@version='2.0']/channel/item")
Dim dsNews As DataSet = New DataSet()
Dim xReader As XmlTextReader
For x = 0 To xNodeList.Count-1
xReader = New XmlTextReader(xNodeList.item(x).OuterXml,
XmlNodeType.Element, new XmlParserContext(Nothing, Nothing, Nothing,
XmlSpace.None))
dsNews.ReadXml(xReader, XmlReadMode.InferSchema)
Next x

Could someone help me with this?

It's making me crazy. I have been looking for the solution for past 2
days.

Thank You,
Miguel

 
Reply With Quote
 
 
 
 
Ryan Ternier
Guest
Posts: n/a
 
      06-17-2005
To my knowledge you can't use xPath with an XML text reader.
XPath only works with XmlDocument.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(XML_FILE_HERE);


string xPath = "/rss[@version='2.0']/channel/item";
XmlElement xmlRoot = xmlDoc.DocumentElement;
XmlNodeList nodes = xmlRoot.SelectNodes(xPath);

foreach(XmlNode node in nodes)
{
ListBox1.Items.Add(new ListItem("Item - " + node["title"]));
}

/RT

Shapper wrote:
> Hello,
>
> I have a XML file (RSS 2.0 format). Something as follows:
>
> <?xml version="1.0"?>
> <rss version="2.0">
> <channel>
> <title>News</title>
> <description>Latest News</description>
> <item>
> <title>Title</title>
> <link>Url</link>
> <description>Description</description>
> <pubDate>Fri, 20 May 2005 12:30:00 GMT</pubDate>
> </item>
> ...
>
> I need to do the following:
>
> 1. Load the 10 most recent items (using pubDate as reference).
>
> 2. Place the loaded items in a dataset.
>
> 3. pubDate must be a valid ASP.Net date/time format.
> I think the standard XML pubDate format is not:
> Fri, 20 May 2005 12:30:00 GMT
>
> Well, at least I am getting a string in my dataset [pubDate] field.
>
> I am having huge problems with (1) and (3).
>
> Here is my code:
>
> Dim news As New XmlDocument()
> news.Load("http://www.domain.com/news.rss")
> Dim x As Integer
> Dim xNodeList As XmlNodeList =
> news.SelectNodes("/rss[@version='2.0']/channel/item")
> Dim dsNews As DataSet = New DataSet()
> Dim xReader As XmlTextReader
> For x = 0 To xNodeList.Count-1
> xReader = New XmlTextReader(xNodeList.item(x).OuterXml,
> XmlNodeType.Element, new XmlParserContext(Nothing, Nothing, Nothing,
> XmlSpace.None))
> dsNews.ReadXml(xReader, XmlReadMode.InferSchema)
> Next x
>
> Could someone help me with this?
>
> It's making me crazy. I have been looking for the solution for past 2 days.
>
> Thank You,
> Miguel
>

 
Reply With Quote
 
 
 
 
Shapper
Guest
Posts: n/a
 
      06-17-2005
Hi Ryan,

Now I got lost. The code I sent you is working.
In fact all item data is loaded, binded to the dataset and later
displayed in a datagrid.

The problems are:
1. My pubDate is returned as string and not as Date/Time format.
2. I don't know how to Load only the last 10 items ordered by pubDate.

I don't know if to get this I need to make some changes or just recreate
the code in other way.

Any suggestion?

I am not very good in XML so some help would be appreciated.

Thanks,
Miguel



"Ryan Ternier" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed):

> To my knowledge you can't use xPath with an XML text reader.
> XPath only works with XmlDocument.
>
> XmlDocument xmlDoc = new XmlDocument();
> xmlDoc.Load(XML_FILE_HERE);
>
>
> string xPath = "/rss[@version='2.0']/channel/item";
> XmlElement xmlRoot = xmlDoc.DocumentElement;
> XmlNodeList nodes = xmlRoot.SelectNodes(xPath);
>
> foreach(XmlNode node in nodes)
> {
> ListBox1.Items.Add(new ListItem("Item - " + node["title"]));
> }
>
> /RT
>
> Shapper wrote:
>
> > Hello,
> >
> > I have a XML file (RSS 2.0 format). Something as follows:
> >
> > <?xml version="1.0"?>
> > <rss version="2.0">
> > <channel>
> > <title>News</title>
> > <description>Latest News</description>
> > <item>
> > <title>Title</title>
> > <link>Url</link>
> > <description>Description</description>
> > <pubDate>Fri, 20 May 2005 12:30:00 GMT</pubDate>
> > </item>
> > ...
> >
> > I need to do the following:
> >
> > 1. Load the 10 most recent items (using pubDate as reference).
> >
> > 2. Place the loaded items in a dataset.
> >
> > 3. pubDate must be a valid ASP.Net date/time format.
> > I think the standard XML pubDate format is not:
> > Fri, 20 May 2005 12:30:00 GMT
> >
> > Well, at least I am getting a string in my dataset [pubDate] field.
> >
> > I am having huge problems with (1) and (3).
> >
> > Here is my code:
> >
> > Dim news As New XmlDocument()
> > news.Load("http://www.domain.com/news.rss")
> > Dim x As Integer
> > Dim xNodeList As XmlNodeList =
> > news.SelectNodes("/rss[@version='2.0']/channel/item")
> > Dim dsNews As DataSet = New DataSet()
> > Dim xReader As XmlTextReader
> > For x = 0 To xNodeList.Count-1
> > xReader = New XmlTextReader(xNodeList.item(x).OuterXml,
> > XmlNodeType.Element, new XmlParserContext(Nothing, Nothing, Nothing,
> > XmlSpace.None))
> > dsNews.ReadXml(xReader, XmlReadMode.InferSchema)
> > Next x
> >
> > Could someone help me with this?
> >
> > It's making me crazy. I have been looking for the solution for past 2 days.
> >
> > Thank You,
> > Miguel
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ACL Headache 05hammer Cisco 5 05-17-2005 07:14 PM
Sp2 + wifi: new headache Tin Ngo-Minh Wireless Networking 2 11-19-2004 04:03 PM
Interbase, ASP.net, C#, and a serious headache Jay Douglas ASP .Net 3 06-08-2004 07:03 PM
Re: PIX 501 configuration headache Shawn Westerhoff Cisco 0 10-14-2003 11:30 PM
HtmlSelect control is not helping and client side coding became a real headache Suhail A, Salman ASP .Net 0 08-13-2003 10:38 AM



Advertisments