StAX Factories






StAX Factories

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:

  1. Check the javax.xml.stream.XMLInputFactory system property.

  2. Look for a file named xml.stream.properties in the lib subdirectory of the JRE. This file is in the standard properties file syntax and defines the property javax.xml.stream.XMLInputFactory.

  3. Look for a resource named META-INF/services/javax.xml.stream.XMLInputFactory in the classpath.

If these steps look familiar, that's because it's the same process used by JAXP.


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.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows