7

科普:如何运用OPML格式向阅读器导入RSS列表

 1 year ago
source link: https://jiongks.name/blog/2011-01-09
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

科普:如何运用OPML格式向阅读器导入RSS列表

本文摘自 勾三股四 更早时期的 不老歌 博客。


最近做RSS相关内容的原因,特意去opml.org学习了一下大名鼎鼎的OPML(Outline Processor Markup Language)文件格式。

OPML格式是基于xml的,首先,在根结点下有一个head结点和一个body结点:

<?xml version="1.0" encoding="UTF-8"?>
<opml>
    <head>
        <title>xxx</title>
        ...
    </head>
    <body>
        <outline ... />
        ...
    </body>
</opml>

head结点中的内容和具体的数据关系不大,大概有下面这么几个(最显眼的莫过于title了)

<head>
    <title>xxx</title>
    <dateCreated>xxx</dateCreated>
    <dateModified>xxx</dateModified>
    <ownerName>xxx</ownerName>
    <ownerEmail>xxx</ownerEmail>
    <ownerId>xxx</ownerId>
    <docs>xxx</docs>
    <expansionState>xxx</expansionState>
    <vertScrollState>xxx</vertScrollState>
    <windowTop>xxx</windowTop>
    <windowBottom>xxx</windowBottom>
    <windowLeft>xxx</windowLeft>
    <windowRight>xxx</windowRight>
</head>

body结点中全部都是outline结点,表示了RSS列表的内容和目录结构,比如:

<body>
    <outline text="Folder 1" ...>
    <outline type="rss" text="Title 1" xmlUrl="http://xxx.rss" ... />
    </outline>
</body>

这里就是opml最主要的部分了,格式对于html/xml开发者来讲应该相当熟悉了。值得一提的是,几个关键的属性text、title、xmlUrl、htmlUrl、type、description中,title/description/htmlUrl都是可选的,如果text/title同时存在,会以text为准,而不是更常见的title,另外xmlUrl和htmlUrl分别表示这个outline的RSS地址和网站地址,而不是所有的RSS都有htmlUrl的。另外RSS的type必须是"rss"。

其实OPML可以做很多事情——远不止导入导出RSS这种,感兴趣的童鞋可以移步到opml.org


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK