
To parse an XML file, you have to access and use SAX or DOM parsers, or Transformer-s. This topic describes how you do this.
To obtain a SAXParser , the user must first get its corresponding SAXParserFactory through the static SAXParserFactory.newInstance() method and then the SAXParser itself by the factory newSAXParser() method.
Similarly, DocumentBuilder-s (DOM parsers) and their factories are obtained through DocumentBuilderFactory , and Transformer-s (XSLT transformers) are obtained through TransformerFactory . Every factory's newInstance() method uses a specific algorithm for finding the JAXP implementation. Since JAXP 1.1.3 (also part of JDK 1.4), the factory find algorithm is the following:
For example, a SAXParser can be obtained through:
ClassLoader oldLoader = null;
SAXParserFactory fact;
try {
oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
this.getClass().getClassLoader());
fact = SAXParserFactory.newInstance();
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}It is essential that you set back the class loader that originally was set. Some other applications may rely on it. Problems may occur if these applications find a class loader that has the JAXP implementation in it.
This means that the component to which this class belongs has a reference to the SAP XML Toolkit library. Providing the classloader will implicitly mean that this loader can load the SAP XML Toolkit classes. In case this is not done, or it is done but the component does not have a reference to the SAP XML Toolkit, the Standard JDK 1.4 parser will be loaded - Crimson for Sun's JDK, Xerces for IBM's.
For J2EE applications, the Context classloader is already preset by the Thread Manager. This is not possible for services, libraries, and resource adapters as they can be invoked also by other components that may have preset the context classloader.
Setting system properties in a system that supports more than one parser is prohibited.
The JAXP view of J2EE Engine XML tools is placed in the com.sap.engine.lib.jaxp package. The currently supported version is JAXP 1.2.