Search code examples
c#xmlrsssyndication-feedsyndication-item

Retrieving custom element values from xml using SyndicationFeed


I'm trying to figure out a way to retrieve the itunes elements from this xml feed and can not for the life of me figure it out.

<item>
    <title>Episode 41 - Brobdingnagian Lunches To Die For</title>
    <pubDate>Fri, 17 Jul 2015 13:00:00 GMT</pubDate>
    <dcterms:modified>2015-07-17</dcterms:modified>
    <dcterms:created>2015-07-17</dcterms:created>
    <link>http://starttocontinue.podomatic.com</link>
    <dc:creator>Start To Continue</dc:creator>
    <itunes:duration>0</itunes:duration>
    <itunes:explicit>yes</itunes:explicit>
    <itunes:order>1</itunes:order>
    ...
</item>

I'm using a standard for each loop to set the easy elements like title etc.

foreach (SyndicationItem item in feed.Items)
{
    string subject = item.Title.Text;
    ...
}

But don't know how to access the itunes ones, does anyone have an idea if this is possible or how to do it?


Solution

  • This ended up working.

    XElement ele = extension.GetObject<XElement>();
    if (ele.ToString().StartsWith("<itunes:image"))
        {
          int index = ele.ToString().IndexOf("\" xmlns:itunes");
          if (index > 0)
            image = ele.ToString().Substring(0, index).Replace("<itunes:image href=\"", "");
        }