How to solve this? The headache is growing.

Discussion in 'ASP .Net' started by Shapper, Jun 17, 2005.

  1. Shapper

    Shapper Guest

    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
    Shapper, Jun 17, 2005
    #1
    1. Advertising

  2. Shapper

    Ryan Ternier Guest

    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
    >
    Ryan Ternier, Jun 17, 2005
    #2
    1. Advertising

  3. Shapper

    Shapper Guest

    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" <> wrote in message
    news::

    > 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
    > >
    Shapper, Jun 17, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mahesh Prasad
    Replies:
    1
    Views:
    706
    Tom Wells
    Feb 22, 2004
  2. seabass

    reading a growing log file

    seabass, Oct 5, 2003, in forum: Perl
    Replies:
    1
    Views:
    483
    seabass
    Oct 5, 2003
  3. Clement
    Replies:
    7
    Views:
    1,619
    Kevin Spencer
    Jul 3, 2003
  4. Hoon
    Replies:
    1
    Views:
    487
    John Timney \(Microsoft MVP\)
    Jul 3, 2003
  5. Suhail A, Salman
    Replies:
    0
    Views:
    352
    Suhail A, Salman
    Aug 13, 2003
Loading...

Share This Page