how to read custom element from RSSFeed XML

Total Post:135

Points:947
XML 
XML
 1518  View(s)
Ratings:
Rate this:

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

<?xml version="1.0"
encoding="utf-8"?>
 <rss version="2.0" xmlns:Poll="http://www.example.com">
 <channel>
 <title>Please Enter Title</title>
 <category>Please Enter Today's Voting Poll</category>
 <link>http://www.WebsiteURL.com</link>
<description>Please Enter Description</description>
<lastBuildDate>Fri, 09 Mar 2012 10:30:55 UT</lastBuildDate>
<item>
  <title>Topic Title</title>
  <Poll:ID>Poll Id</Poll:ID>
  <Poll:Answer1>answer</Poll:Answer1>
  <Poll:Date>Date</Poll:Date>
</item>

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 = "http://www.example.com";
            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

    Points:2694
    Re: how to read custom element from RSSFeed XML

    Hi Chintoo, 


    try this:

    XmlNamespaceManager nameSpace = new XmlNamespaceManager(doc.NameTable);

         nameSpace.AddNamespace("Tips", "http://www.example.com");

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

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

Answer