編寫者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