How to specify which stax parser to use
I have a woodstox and and java SE 1.6 stax parser in the classpath but woodstox seems to get开发者_开发问答 selected by default. However in certain cases I'd like to use the default Java stax parser. Is there any way to specify which implementation to use?
Easiest way is to just directly instantiate one you want -- there is no need to use XMLInputFactory.newInstance()
; for Woodstox you would instantiate com.ctc.wstx.stax.WstxInputFactory
. For Sun implementation it is something else (com.sun.sjsxp or such) -- you can see class name if you instantiate it via Stax API when Woodstox jar is not in classpath.
But if you absolutely want to use indirection, value of system property "javax.xml.stream.XMLInputFactory" is used, as per javadocs: value is the name of class to instantiate.
I had a similar problem, my local jboss has woodstox in the path but the remote server don't (or something is not properly configured). So I chose to instantiate the reference implementation:
// Use BEA streaming parser to avoid runtime exceptions
XMLOutputFactory xmlof = new XMLOutputFactoryBase();
精彩评论