Click here to Skip to main content
15,559,682 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, please i am trying to parse this rss feed image url and thumbnail url but everything i have tried is not working and that is really annoying.
i tried getting it from the media enclose... <media> even tried <media:content> still tried <content> but it did nothing. please help me with this...

<channel>
<title>this is title 1</title>
<link>https://www.website1.com</link>
<description>description of number1</description>
<image>
<title>title one</title>
<url>https://site1.png</url>
<link>https://www.website.com</link>
</image>
<pubDate>Fri, 14 Oct 2022 08:12:43 +0000</pubDate>
<ttl>180</ttl>
<language>en-us</language>
<atom:link href="https://website.com"/>
<atom:link rel="hub" href="https://websitethank.com"/>
<item>
<title>
<![CDATA[ this is title2 ]]>
</title>
<link>https://www.website.com</link>
<guid>https://www.AnotherWebsite.com</guid>
<category>New category</category>
<description>
<![CDATA[ description of 2. ]]>
</description>
<pubDate>Thu, 13 Oct 2022 20:57:22 -0700</pubDate>
<media:content url="https://MediaWebsite.jpg" expression="full" type="image/jpg" width="1167" height="656">
<media:thumbnail url="https://thumbNailWebsite.com.jpg" width="128" height="72"/>
</media:content>
</item>


What I have tried:

XmlDocument rssXmlDoc = new XmlDocument();
rssXmlDoc.Load("https://website.com");
XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");
StringBuilder rssContent = new StringBuilder();
// Iterate through the items in the RSS file
foreach (XmlNode rssNode in rssNodes)
{
XmlNode rssSubNode = rssNode.SelectSingleNode("title");
string title = rssSubNode != null ? rssSubNode.InnerText : "";

rssSubNode = rssNode.SelectSingleNode("link");
string link = rssSubNode != null ? rssSubNode.InnerText : "";

rssSubNode = rssNode.SelectSingleNode("pubDate");
string dateP = rssSubNode != null ? rssSubNode.InnerText : "";

rssSubNode = rssNode.SelectSingleNode("description");
string description = rssSubNode != null ? rssSubNode.InnerText : "";

rssSubNode = rssNode.SelectSingleNode("img");
string Immage = rssSubNode != null ? rssSubNode.InnerText : "";

rssContent.Append("" + title + dateP + "
" + description);
}
Posted
Updated 14-Oct-22 19:35pm

1 solution

Here you go...
C#
var itemMediaContents = rssNode
    .OwnerDocument!.GetElementsByTagName("media:content");

var itemMediaContent = itemMediaContents[0];

var itemMediaThumbnails = itemMediaContent!
    .OwnerDocument!.GetElementsByTagName("media:thumbnail");

var itemMediaThumbnail = itemMediaThumbnails[0];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900