How can I configure a SAX parser in the Sun JVM to match the Android one?

浪尽此生 提交于 2020-01-16 05:06:28

问题


Is there a way to configure features/properties on the SAX parser so that it matches the default Android one?

I have implemented a SAX parser for an Atom feed and I'd like to be able to unit test it without running it via an InstrumentationTestCase. The differences I see right away is that in startElement(), localName has the element name when running on Android, yet the "name" method parameter is populated when running under the Sun JVM. In addition, whitespace is ignored when running on the Sun JVM, but not on Android.


回答1:


For those looking, after some trial and error, these two features seemed to make it the most similar. In the end, we ended up running these types of unit tests as instrumentation tests due to the differences in the XML parsing.

XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
reader.setFeature("http://xml.org/sax/features/namespaces", false);
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
reader.setContentHandler(handler);
reader.parse(source);



回答2:


probably need to configure the parser to be namespace aware, and set the "http://apache.org/xml/features/dom/include-ignorable-whitespace" feature to true.



来源:https://stackoverflow.com/questions/5481043/how-can-i-configure-a-sax-parser-in-the-sun-jvm-to-match-the-android-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!