创建RSS2.0,RSS1.0兼容的feed解析器

时间:2013-08-02 16:48:08

标签: xml xml-parsing rss rss-reader

我必须在Salesforce平台上创建RSS阅读器。我阅读了RSS 1.0和2.0的规范。

在RSS 2.0中,这个文档http://feed2.w3.org/docs/rss2.html中指定的格式,没有像它中的扩展,没有我们在RSS 1.0中看到的模块和命名空间,我们在其中定义XML,即使在关闭之后channel项。例如,在此链接http://static.userland.com/gems/backend/rssTwoExample2.xml中,channel之上只有一个RSS父元素,但是当我们采用RSS 1.0的情况时,它包含了许多像这个例子中的兄弟姐妹。

<?xml version="1.0"?>

<rdf:RDF 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns="http://purl.org/rss/1.0/"
>

  <channel rdf:about="http://www.xml.com/xml/news.rss">
    <title>XML.com</title>
    <link>http://xml.com/pub</link>
    <description>
      XML.com features a rich mix of information and services 
      for the XML community.
    </description>

    <image rdf:resource="http://xml.com/universal/images/xml_tiny.gif" />

    <items>
      <rdf:Seq>
        <rdf:li resource="http://xml.com/pub/2000/08/09/xslt/xslt.html" />
        <rdf:li resource="http://xml.com/pub/2000/08/09/rdfdb/index.html" />
      </rdf:Seq>
    </items>

  </channel>

  <image rdf:about="http://xml.com/universal/images/xml_tiny.gif">
    <title>XML.com</title>
    <link>http://www.xml.com</link>
    <url>http://xml.com/universal/images/xml_tiny.gif</url>
  </image>

  <item rdf:about="http://xml.com/pub/2000/08/09/xslt/xslt.html">
    <title>Processing Inclusions with XSLT</title>
    <link>http://xml.com/pub/2000/08/09/xslt/xslt.html</link>
    <description>
     Processing document inclusions with general XML tools can be 
     problematic. This article proposes a way of preserving inclusion 
     information through SAX-based processing.
    </description>
  </item>

  <item rdf:about="http://xml.com/pub/2000/08/09/rdfdb/index.html">
    <title>Putting RDF to Work</title>
    <link>http://xml.com/pub/2000/08/09/rdfdb/index.html</link>
    <description>
     Tool and API support for the Resource Description Framework 
     is slowly coming of age. Edd Dumbill takes a look at RDFDB, 
     one of the most exciting new RDF toolkits.
    </description>
  </item>

</rdf:RDF>

为了创建一个处理核心部分的标准解析器,可以很容易地获得每个项目的描述和链接。但是当我们在任何元素中讨论RSS 1.0时,当我们在元素中看到任何rdf:resource属性时,我们必须在rdf:about元素的兄弟中找到channel属性并查找它的描述和链接。

请提供有关如何解析RSS 1.0以获取Feed中每个项目的说明和链接的指南。或者我的假设是否正确?

0 个答案:

没有答案