我正在尝试创建一个自动创建iTunes Podcast RSS feed的程序。我遇到的问题是我不知道如何创建所需的XML元素。我试图以两种不同的方式在这里创建两个标签。首先,我将"itunes:"
用作字幕,但它不起作用,它引发了一个异常,即我无法在名称中使用冒号。第二个(图像)输出此
<image xmlns="http://www.itunes.com/dtds/podcast-1.0.dtd" href="http://someurkl.com/myimgp.png"/>
有什么方法可以使它与ASP.net一起使用?或者,您可以为我指出正确的文档说明方向还是可以向我展示如何为iTunes播客创建提要的教程。
我的代码:
XNamespace itunesNS = "http://www.itunes.com/dtds/podcast-1.0.dtd";
SyndicationFeed feed = new SyndicationFeed(title, description, new Uri(link));
feed.ElementExtensions.Add(new XElement("itunes:" + "subtitle", subTitle).CreateReader());
feed.ElementExtensions.Add(new XElement(itunesNS + "image", new XAttribute("href", imageUrl)).CreateReader());
iTunes要求的格式:
<itunes:subtitle>My Subtitle Here</itunes:subtitle>
Apple的示例Feed:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>All About Everything</title>
<link>http://www.example.com/podcasts/everything/index.html</link>
<language>en-us</language>
<copyright>℗ & © 2005 John Doe & Family</copyright>
<itunes:subtitle>A show about everything</itunes:subtitle>
<itunes:author>John Doe</itunes:author>
<itunes:summary>All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our Podcast in the iTunes Store</itunes:summary>
<description>All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our Podcast in the iTunes Store</description>
<itunes:owner>
<itunes:name>John Doe</itunes:name>
<itunes:email>[email protected]</itunes:email>
</itunes:owner>
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything.jpg" />
<itunes:category text="Technology">
<itunes:category text="Gadgets"/>
</itunes:category>
<itunes:category text="TV & Film"/>
<item>
<title>Shake Shake Shake Your Spices</title>
<itunes:author>John Doe</itunes:author>
<itunes:subtitle>A short primer on table spices</itunes:subtitle>
<itunes:summary>This week we talk about salt and pepper shakers, comparing and contrasting pour rates, construction materials, and overall aesthetics. Come and join the party!</itunes:summary>
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg" />
<enclosure url="http://example.com/podcasts/everything/AllAboutEverythingEpisode3.m4a" length="8727310" type="audio/x-m4a" />
<guid>http://example.com/podcasts/archive/aae20050615.m4a</guid>
<pubDate>Wed, 15 Jun 2005 19:00:00 GMT</pubDate>
<itunes:duration>7:04</itunes:duration>
</item>
<item>
<title>Socket Wrench Shootout</title>
<itunes:author>Jane Doe</itunes:author>
<itunes:subtitle>Comparing socket wrenches is fun!</itunes:subtitle>
<itunes:summary>This week we talk about metric vs. old english socket wrenches. Which one is better? Do you really need both? Get all of your answers here.</itunes:summary>
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything/Episode2.jpg" />
<enclosure url="http://example.com/podcasts/everything/AllAboutEverythingEpisode2.mp3" length="5650889" type="audio/mpeg" />
<guid>http://example.com/podcasts/archive/aae20050608.mp3</guid>
<pubDate>Wed, 8 Jun 2005 19:00:00 GMT</pubDate>
<itunes:duration>4:34</itunes:duration>
</item>
<item>
<title>Red, Whine, & Blue</title>
<itunes:author>Various</itunes:author>
<itunes:subtitle>Red + Blue != Purple</itunes:subtitle>
<itunes:summary>This week we talk about surviving in a Red state if you are a Blue person. Or vice versa.</itunes:summary>
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything/Episode3.jpg" />
<enclosure url="http://example.com/podcasts/everything/AllAboutEverythingEpisode1.mp3" length="4989537" type="audio/mpeg" />
<guid>http://example.com/podcasts/archive/aae20050601.mp3</guid>
<pubDate>Wed, 1 Jun 2005 19:00:00 GMT</pubDate>
<itunes:duration>3:59</itunes:duration>
</item>
</channel>
</rss>
TL; DR
看起来您需要在生成rss的代码区域中为itunes:
标记定义自定义名称空间。>>
这里有一些info originally written by Lukasz Karolak,可能会对您有所帮助。
假设我们想要一个RSS feed,实际上它可以用作播客,例如适用于iTunes。 Apple的软件使用其自定义的RSS标记(带有itunes
前缀)的某些信息,例如:
<itunes:author>Anonymous One</itunes:author>
没有此前缀,这非常简单。我们的
SyndicationItem
类为我们提供了扩展标准项元素的功能:
SyndicationItem item = new SyndicationItem(); item.ElementExtensions.Add(customTagString.Empty, "My test");
第二个属性是在下一步中起作用的名称空间。为了如前所述添加标签前缀,首先要将名称空间添加到供稿实例:
SyndicationFeed feed = new SyndicationFeed(); XmlQualifiedName n=new XmlQualifiedName("itunes","http://www.w3.org/2000/xmlns/"); String itunesNs = "http://www.itunes.com/dtds/podcast-1.0.dtd"; feed.AttributeExtensions.Add(n, itunesNs);
现在我们已经将新的名称空间添加到了提要中,我们可以开始在该名称空间中添加自定义项目元素。
SyndicationItem item = new SyndicationItem(); item.ElementExtensions.Add(new SyndicationElementExtension("author", itunesNs, "Famous author"));
这应该使用带有自定义前缀的自定义标签解决该问题。