To obtain an instance of any of the four primary StAX interfaces mentioned above, you'll use one of two factory classes: javax.xml.stream.XMLInputFactory and javax.xml.stream.XMLOutputFactory . To obtain an instance of the factory class, call the static method newInstance( ) on the abstract class XMLInputFactory.
XMLInputFactory inputFactory = XMLInputFactory.newInstance( );
The following steps determine which implementation of StAX is returned by the newInstance( ) method:
In general, an implementation's jar file will provide the META-INF/services file. The first two options are useful when you want to provide your own implementation of the interfaces or if you have multiple implementations in your classpath and need to be explicit about which one to use.