how to read custom element from RSSFeed XML

Total Post:135

 1695  View(s)
Rate this:

I want to read data from a XMl file which is in a predefined format as given

<?xml version="1.0"
 <rss version="2.0" xmlns:Poll="">
 <title>Please Enter Title</title>
 <category>Please Enter Today's Voting Poll</category>
<description>Please Enter Description</description>
<lastBuildDate>Fri, 09 Mar 2012 10:30:55 UT</lastBuildDate>
  <title>Topic Title</title>
  <Poll:ID>Poll Id</Poll:ID>

I an not able to read data that has Poll in the prefix of the element tag.

foreach (XmlNode RSSNode in RSSChannelItemList)
            XmlNode RSSSubNode;
            RSSSubNode = RSSNode.SelectSingleNode("title");
            string title = RSSSubNode != null ? RSSSubNode.InnerText : "";
            XNamespace Tips = "";
            RSSSubNode = RSSNode.SelectSingleNode("ID");
            string link = RSSSubNode != null ? RSSSubNode.InnerText : "";
            link = RSSSubNode!=null ? RSSSubNode.InnerXml : "";

I get the title value perfectly but I am unable to get the value of ID This is a custom tag in the XMl

Can anyone suggest me How to do this?

  1. Post:378

    Re: how to read custom element from RSSFeed XML

    Hi Chintoo, 

    try this:

    XmlNamespaceManager nameSpace = new XmlNamespaceManager(doc.NameTable);

         nameSpace.AddNamespace("Tips", "");

         RSSSubNode = RSSNode.SelectSingleNode("Tips:ID",nameSpace);

         string link = RSSSubNode != null ? RSSSubNode.InnerText : "";


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.