编写者 | 日期 | 关键词 |
郑昀@ultrapower | 2005-9-28 | Xmlpull kxml java |
Xmlpull官方站点:http://www.xmlpull.org/
优点:不必等整个文档解析完成,部分求值结果早就可以开始反馈给用户。
XmlPull project is dedicated to be a site for
网络中有很多人问到同样一个问题:
为什么我们在调用
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
时,总是得到这样的错误:
错误提示: |
Exception in thread "main" org.xmlpull.v1.XmlPullParserException: caused by: org.xmlpull.v1.XmlPullParserException: resource not found: /META-INF/services/org.xmlpull.v1.XmlPullParserFactory make sure that parser implementing XmlPull API is available at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:294) |
虽然从http://www.xmlpull.org/v1/doc/api/org/xmlpull/v1/XmlPullParserFactory.html
看到了他们自己的注解:
XmlPullParserFactory的注释: |
If no name of parser factory was passed (or is null) it will try to find name by searching in CLASSPATH for META-INF/services/org.xmlpull.v1.XmlPullParserFactory resource that should contain a comma separated list of class names of factories or parsers to try (in order from left to the right). If none found, it will throw an exception. |
看来它确实需要寻找这么一个资源:
META-INF/services/org.xmlpull.v1.XmlPullParserFactory
。但又没说如何才能找到它。
下载的kxml2.jar加到你的项目中即可。这时候再调用
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
Thread.currentThread().getContextClassLoader().getClass() );
就通过了。
kxml2.jar就包含了META-INF/services/org.xmlpull.v1.XmlPullParserFactory文件,它的内容其实就是一句话:
org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer
编写者 | 日期 | 关键词 |
郑昀@ultrapower | 2005-9-28 | Xmlpull kxml java |