天天看点

[xmlpull]XmlPull常见错误

编写者

日期

关键词

郑昀@ultrapower

2005-9-28

xmlpull kxml java

优点:不必等整个文档解析完成,部分求值结果早就可以开始反馈给用户。

xmlpull project is dedicated to be a site for

for general pull parsing promotion/education (including stax) and in particular to contain easy-to-reuse samples and code fragments

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

网络中有很多人问到同样一个问题:

为什么我们在调用

<b>xmlpullparserfactory factory = xmlpullparserfactory.newinstance();</b>

<b></b>

时,总是得到这样的错误:

 错误提示:

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)

看到了他们自己的注解:

 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. 

note:in j2se or j2ee environments, you may want to use<code>newinstance(property, classloaderctx)</code> where first argument is<code>system.getproperty(xmlpullparserfactory.property_name)</code> and second is<code>thread.getcontextclassloader().getclass()</code> .

看来它确实需要寻找这么一个资源:

meta-inf/services/org.xmlpull.v1.xmlpullparserfactory

。但又没说如何才能找到它。

xmlpullparserfactory factory = xmlpullparserfactory.newinstance(

                            system.getproperty(xmlpullparserfactory.property_name),

                   thread.currentthread().getcontextclassloader().getclass() );

就通过了。

org.kxml2.io.kxmlparser,org.kxml2.io.kxmlserializer