Can I add my own tags in a rss item?

怎甘沉沦 提交于 2020-01-03 01:55:12

问题


In the rss xml file I have my channel and several items. Typically the item has a title, link, description and maybe time or something. Can I put my own tags in there with additional data I want to send?

Example: Say if was a doing a rss feed to contains weather/temperature info, I might have several item tags, with one for each city. And then in the description I would have my string description. But if I wanted to also put separate tags for temperature, windspeed, high, low, inchesOfRain, etc too I could have something parse that differently on some other client.


回答1:


Yes you can - create a new namespace for your tags (it's standard XML).

An example:

<?xml version="1.0"?>
<rss version="2.0" xmlns:w="http://tempuri.org">
    <channel>
        ...
        <item>
            <title>Item title</title>
            <description>...</description>
            <w:temperature>...</w:temperature>
            <w:windspeed>...</w:windspeed>
        </item>
    </channel>
</rss>

That said, perhaps you should do a little searching first to see if there's an existing format that meets your needs. Standards == good :)

See http://www.feedforall.com/namespaces.htm, http://base.google.co.uk/support/bin/answer.py?answer=58085&hl=en_GB




回答2:


Is this what you're looking for?

http://cyber.law.harvard.edu/rss/rss.html#extendingRss

I think Atom has something similar too. You can look at the spec for Atom here:

http://tools.ietf.org/rfc/rfc4287.txt




回答3:


If you want an example of weather RSS feeds, you should definitely take a look at the RSS feeds that are produced by the Weather channel at http://www.weather.com

I remember using those a few years ago to generate weather widgets for a small city's website I helped produce. We would parse out the RSS feed to get the temperature and cloud coverage of our specific zip code's weather.



来源:https://stackoverflow.com/questions/644315/can-i-add-my-own-tags-in-a-rss-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!