Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reading CDATA text from RSS Feed using LINQ to xml

Reading CDATA text from RSS Feed using LINQ to xml

Scheduled Pinned Locked Moved C#
csharphtmllinqcomxml
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    faheemnadeem
    wrote on last edited by
    #1

    Hi, I have the following RSS Feed containing a CDATA Tag. I wish to get the "img src" attribute information, but i am unable to get it. Can anybody help please !!!. I am using LINQ to XML. Please give LINQ solutions only...

    <description><![CDATA[

    <img src="http://l.yimg.com/a/i/us/we/52/30.gif"/><br />
    <b>Current Conditions:</b><br />
    Partly Cloudy, 37 C<BR />
    <BR /><b>Forecast:</b><BR />
    Fri - Sunny/Wind. High: 39 Low: 25<br />
    Sat - Sunny/Wind. High: 42 Low: 26<br />
    <br />
    <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
    (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
    ]]></description>

    Thank you in advance...

    I 1 Reply Last reply
    0
    • F faheemnadeem

      Hi, I have the following RSS Feed containing a CDATA Tag. I wish to get the "img src" attribute information, but i am unable to get it. Can anybody help please !!!. I am using LINQ to XML. Please give LINQ solutions only...

      <description><![CDATA[

      <img src="http://l.yimg.com/a/i/us/we/52/30.gif"/><br />
      <b>Current Conditions:</b><br />
      Partly Cloudy, 37 C<BR />
      <BR /><b>Forecast:</b><BR />
      Fri - Sunny/Wind. High: 39 Low: 25<br />
      Sat - Sunny/Wind. High: 42 Low: 26<br />
      <br />
      <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
      (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
      ]]></description>

      Thank you in advance...

      I Offline
      I Offline
      i gr8
      wrote on last edited by
      #2

      Just access the RSS feed(XML content) in your dataset , after getting in your dataset you can do wat ever you want.

      F 1 Reply Last reply
      0
      • I i gr8

        Just access the RSS feed(XML content) in your dataset , after getting in your dataset you can do wat ever you want.

        F Offline
        F Offline
        faheemnadeem
        wrote on last edited by
        #3

        If you guide me a bit further... 1. I have loaded the document as follows.

        XDocument rssFeed = XDocument.Load(sForecastUrl);

        2. Now i get the descendant nodes as follows

        var desc = from e in rssFeed.Descendants("channel").Descendants("item").Descendants("description")
        select e;

                    foreach (var element in desc)
                    {
                        element.Value;
                    }
        

        I am able to get description element value which contains the cdata tag. Dont know what to do next to get "Img Src" attribute directly rather than from string manipulation. Some code in the foreach loop should help please.

        I 1 Reply Last reply
        0
        • F faheemnadeem

          If you guide me a bit further... 1. I have loaded the document as follows.

          XDocument rssFeed = XDocument.Load(sForecastUrl);

          2. Now i get the descendant nodes as follows

          var desc = from e in rssFeed.Descendants("channel").Descendants("item").Descendants("description")
          select e;

                      foreach (var element in desc)
                      {
                          element.Value;
                      }
          

          I am able to get description element value which contains the cdata tag. Dont know what to do next to get "Img Src" attribute directly rather than from string manipulation. Some code in the foreach loop should help please.

          I Offline
          I Offline
          i gr8
          wrote on last edited by
          #4

          No No... Get the XML and convert the XML to DATASET using dataset.readxml() you will get all tags as columns and its attributes , so you can easily get the attribute value.

          F 1 Reply Last reply
          0
          • I i gr8

            No No... Get the XML and convert the XML to DATASET using dataset.readxml() you will get all tags as columns and its attributes , so you can easily get the attribute value.

            F Offline
            F Offline
            faheemnadeem
            wrote on last edited by
            #5

            Oh!!! I understood your point on using datasets, but i have written all my work using linq to xml. i have successfully parsed whole of the xml document already, only part missing was this cdata tag, so i was asking for finding a solution to that using linq as well. i don't want to load the complete document as dataset again, i have already loaded the webresponse into xDocument. So any solution relating to that... Even though i can get the url out from the attribute using string manipulation but clearly that is not the right method. P.s. Thanks for the dataset option though....

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups