How to specify which stax parser to use

4.7k views Asked by At

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?

2

There are 2 answers

0
StaxMan On BEST ANSWER

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.

0
Lluis Martinez On

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();