4

我正在尝试创建一个自动创建 iTunes Podcast RSS 提要的程序。我遇到的问题是我不知道如何创建所需的 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>&#x2117; &amp; &#xA9; 2005 John Doe &amp; 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>john.doe@example.com</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 &amp; 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, &amp; 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>
4

1 回答 1

0

TL;博士

看起来您需要为itunes:生成 rss 的代码区域中的标记定义自定义命名空间。


这是Lukasz Karolak 最初编写的一些信息,可能会对您有所帮助。

假设我们想要一个 RSS 提要,它实际上可以用作播客,例如 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"));

这应该可以解决带有自定义前缀的自定义标签的问题。

于 2020-05-10T21:50:01.423 回答