我正在研究Apple的LazyTableImages示例代码。我想了解应用程序如何从应用程序中包含的 RSS 提要中提取数据: http://phobos.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/limit=75/xml
上述 url 的内容是如何解析的?查看页面源代码会发现没有明显 xml 部分的 HTML。在查看示例解析代码时,我发现了一些符号,例如 im:name
。然而这些符号并不在上述url的内容中。
我尝试在本地托管上述网址的内容(w/limit=1)。但是,将示例代码指向 @"~/Desktop/a.xml"
会导致应用程序抛出错误不支持的 url
。
更多信息:阅读时 http://en.wikipedia.org/wiki/Rss我在上面的 phobos 链接中发现了我期望看到的内容。像这样:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.someexamplerssdomain.com/main.html</link>
<pubDate>Mon, 06 Sep 2009 16:45:00 +0000 </pubDate>
<item>
<title>Example entry</title>
<description>an interesting description</description>
<link>http://www.wikipedia.org/</link>
<guid>unique string per item</guid>
<pubDate>Mon, 06 Sep 2009 16:45:00 +0000 </pubDate>
</item>
</channel>
</rss>
是否存在与上述 phobos 链接相对应的等效“人类可读”xml 文档?
最佳答案
你是对的,从技术上讲,你正在查看的提要不是 RSS 提要。这是一个Atom 1.0 Feed,但两者都是流行的基于 XML 的 Feed 格式。
如果您查看提要的来源,您将看到您正在查找的 XML 元素,例如:
<entry>
<updated>2011-12-09T16:15:32-07:00</updated>
<id>http://itunes.apple.com/us/app/tetris/id479943969?mt=8&uo=2</id>
<title>TETRIS® - Electronic Arts</title>
<summary>Long summary here</summary>
<im:name>TETRIS®</im:name>
...
</entry>
某些浏览器版本将 RSS/Atom 提要解析为用户友好的 HTML 页面,并呈现它们而不是实际的提要,听起来这就是您正在查看的 HTML 页面类型。
在 OS X 上,您可以使用 Curl 之类的命令在终端中下载 feed:
curl -o feed.xml http://phobos.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/limit=75/xml
关于ios - 了解Apple示例代码中的xml解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8453137/