编写者html |
日期java |
关键词api |
郑昀@ultrapower 网络 |
2005-9-28ide |
Xmlpull kxml javaui |
Xmlpull官方站点:http://www.xmlpull.org/idea
优势:没必要等整个文档解析完成,部分求值结果早就能够开始反馈给用户。spa
XmlPull project is dedicated to be a site for.net
for general Pull parsing promotion/education (including StAX) and in particular to contain easy-to-reuse samples and code fragmentscode
a resource for discussing new ideas and concepts related to pull parsing
a java namespace (org.xmlpull.*) and project location of a free implementation of the event object API and Factories, based on the StAX XMLStreamReade and old Common API for XML Pull Parsing
as java namespace and project location of StAX and XmlPull based utilities and samples such as:
- providing an XML stream from a DOM tree
- a DOM builder
- SAX adapter
- JUnit tests
as a maintenance resource for the existing XmlPull interface
网络中有不少人问到一样一个问题:
为何咱们在调用
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