轻量级的xml parser: KXML
2004-11-27 16:12
369 查看
kXML is a small XML pull parser, specially designed for constrained environments such as Applets, Personal Java or MIDP devices.
最小的版本只有11k,比那些庞大的xml解析起确实小好多。当你对xml解析不需要很严格时可以使用它。
下面是使用kxml的一段示例代码:
最小的版本只有11k,比那些庞大的xml解析起确实小好多。当你对xml解析不需要很严格时可以使用它。
下面是使用kxml的一段示例代码:
import org.xmlpull.v1.*; import java.util.*; import java.io.*; import java.net.*; /** * A simple example illustrationg some differences of the XmlPull API * and SAX. For the corresponding SAX based implementation, please refer to * http://www.cafeconleche.org/slides/sd2001east/xmlandjava/81.html ff. */ public class Weblogs { static List listChannels() throws IOException, XmlPullParserException { return listChannels("http://static.userland.com/weblogMonitor/logs.xml"); } static List listChannels(String uri) throws IOException, XmlPullParserException { Vector result = new Vector(); InputStream is = new URL(uri).openStream(); XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); parser.setInput(is, null); parser.nextTag(); parser.require(XmlPullParser.START_TAG, "", "weblogs"); while (parser.nextTag() == XmlPullParser.START_TAG) { String url = readSingle(parser); if (url != null) result.addElement(url); } parser.require(XmlPullParser.END_TAG, "", "weblogs"); parser.next(); parser.require(XmlPullParser.END_DOCUMENT, null, null); is.close (); parser.setInput (null); return result; } public static String readSingle(XmlPullParser parser) throws IOException, XmlPullParserException { String url = null; parser.require(XmlPullParser.START_TAG, "", "log"); while (parser.nextTag() == XmlPullParser.START_TAG) { String name = parser.getName(); String content = parser.nextText(); if (name.equals("url")) url = content; parser.require(XmlPullParser.END_TAG, "", name); } parser.require(XmlPullParser.END_TAG, "", "log"); return url; } public static void main(String[] args) throws IOException, XmlPullParserException { List urls = args.length > 0 ? listChannels(args[0]) : listChannels(); for (Iterator i = urls.iterator(); i.hasNext();) System.out.println(i.next()); } }
相关文章推荐
- 在Excel中应用VBA批量导入数据
- Visual C++ MFC/ATL开发-初级篇
- Review of Debugging the development process 5. Schedule Madness
- 访问 Microsoft SQL Server 元数据的三种方法
- 如何获得系统进程信息
- 应用Python在组件式GIS中集成地质统计学
- 用户控件中使用了Javascript ,把2个控件放在页面上,那么页面上会有2个同名的javascript函数,如何处理
- 在组件式GIS开发中集成Python方法研究
- Window 消息大全使用详解
- 华为公司三层以太网交换机基本原理及转发流程
- An OSGi framework implementation
- Windows系统的内存管理
- 精彩flash《猪之歌》
- live communications server 2003 的BUG?
- Blog定制
- wss2.0安装后IIS服务ISAPI筛选器stsfltr.dll带来的问题
- 如何处理Oracle数据库中的坏块问题
- 在Excel中使用VBA来筛选数据
- 在Linux操作下如何编译安装php&mysql&apache
- 多媒体处理