我需要编写一个 XML 解析类,我可以在整个 Android 应用程序中重用它,并且从我读过的内容来看,SAXParser 是移动应用程序的最佳选择。我正在使用本指南:
http://www.jondev.net/articles/Android_XML_SAX_Parser_Example
我希望解析的文档类型是来自 Blogger GData API 的提要 - 例如:
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"CUIGRnc4fyp7ImA9Wx9SEEg."'>
<id>tag:blogger.com,1999:user-464300745974.blogs</id>
<updated>2010-11-29T17:58:47.937Z</updated>
<title>Tim's Blogs</title>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.blogger.com/feeds/blogid/blogs'/>
<link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/blogid/blogs'/>
<link rel='alternate' type='text/html' href='http://www.blogger.com/profile/blogid'/>
<author>
<name>Tim</name>
<uri>http://www.blogger.com/profile/blogid</uri>
<email>noreply@blogger.com</email>
</author>
<generator version='7.00' uri='http://www.blogger.com'>Blogger</generator>
<openSearch:totalResults>2</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<entry gd:etag='W/"DUIBQHg-cCp7ImA9Wx9TF0s."'>
<id>tag:blogger.com,1999:user-464300745974.blog-blogid</id>
<published>2010-06-22T10:59:38.603-07:00</published>
<updated>2010-11-26T02:32:31.658-08:00</updated>
<title>Application Testing Blog</title>
<summary type='html'>This blog is for testing the Android application.</summary>
<link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/blogid/blogs/blogid'/>
<link rel='alternate' type='text/html' href='http://devrum.blogspot.com/'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://devrum.blogspot.com/feeds/posts/default'/>
<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://www.blogger.com/feeds/blogid/posts/default'/>
<link rel='http://schemas.google.com/blogger/2008#template' type='application/atom+xml' href='http://www.blogger.com/feeds/blogid/template'/>
<link rel='http://schemas.google.com/blogger/2008#settings' type='application/atom+xml' href='http://www.blogger.com/feeds/blogid/settings'/>
<author>
<name>Tim</name>
<uri>http://www.blogger.com/profile/blogid</uri>
<email>noreply@blogger.com</email>
</author>
</entry>
<entry gd:etag='W/"C08HRXo4eSp7ImA9Wx9TE0o."'>
<id>tag:blogger.com,1999:user-464300745974.blog-515600026106499737</id>
<published>2010-06-22T10:59:00.328-07:00</published>
<updated>2010-11-21T12:37:14.431-08:00</updated>
<title>Development Blog</title>
<summary type='html'>etc</summary>
<link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/blogid/blogs/515600026106499737'/>
<link rel='alternate' type='text/html' href='http://rumdev.blogspot.com/'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rumdev.blogspot.com/feeds/posts/default'/>
<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://www.blogger.com/feeds/515600026106499737/posts/default'/>
<link rel='http://schemas.google.com/blogger/2008#template' type='application/atom+xml' href='http://www.blogger.com/feeds/515600026106499737/template'/>
<link rel='http://schemas.google.com/blogger/2008#settings' type='application/atom+xml' href='http://www.blogger.com/feeds/515600026106499737/settings'/>
<author>
<name>Tim</name>
<uri>http://www.blogger.com/etc</uri>
<email>noreply@blogger.com</email>
</author>
</entry>
</feed>
我需要从上面的提要中解析博客 ID 和发布 ID。从我在 SAX 上找到的任何示例来看,它们根本不是通用的。我想写一个可重用的,你有什么例子我可以相应地修改 SAXParser 吗?