!--a11y-->
SAP XML Toolkit for Java FAQ 
The frequently asked questions section aims to introduce to the reader the basic questions, which may occur when using SAP XML Toolkit for Java.
1. How can I build a DOM tree from an XML document?
2. How to match an XPath expression to an XML document, for getting a boolean result?
3. Using the Toolkit you receive a strange exception:
java.lang.NoSuchMethodError
at
com.sap.engine.lib.xml.util.DOMToDocHandler.process(DOMToDocHandler.jav:50)
at
com.sap.engine.lib.xml.util.DOMToDocHandler.process(DOMToDocHandler.java:113)
at
com.sap.engine.lib.xml.util.DOMToDocHandler.process(DOMToDocHandler.java:37)
at
4. How can I use SAP XML Toolkit in a stand-alone program?
5. How can I use SAP XML Toolkit in a deployed application?
6. How can I use Xerces parser in my application?
7. How can I use an HTTP proxy while parsing an XML?
...
1. Please, consider with the javax.xml.parsers.* JAXP package documentation.
Using JAXP 1.1 cannot easily perform this process. There is a class, which encapsulates the usage of our XPathProcessor as a stand-alone class, leaving the user distanced from the implementation. This class is very useful and provides a great functionality, which can be extended including any other suggestion.
Class:com.engine.lib.xsl.xpath.XpathMatcher
Constructor: XPathMatcher(String filename) throws FileNotFoundException, XpathException.
This constructs a new XPathMatcher object, and initializes it with the specified file. If the file cannot be found then a FileNotFoundException is thrown. If there is any other error then an XPathException (com.engine.lib.xsl.xpath.XPathException) is thrown. Also this exception is thrown when invoking the XML through any other method.
Methods:
init(String filename) – initializes an existing XPathMatcher instance.
match(String query) – matches this query with the current context (by default, this is the root node) and returns true or false.
An XnodeSet result – returns false if the node set is empty, else true.
An XString result – returns false if the string is empty, else true.
An XNumber result – returns false if the number is 0, else true.
An XBoolean result – it is clear.
Advanced Use
The following methods provide advanced functionality. To use them, check JavaDoc (Java code documentation) first, to understand the class purposes.
· process(String query) – processes this query and returns a XObject.For more information, see the JavaDoc.
· setContext(String query) – sets a current context. For example "/" sets the root node context, "/table" sets the first table node context, "/table[name = 'Bob']" sets the first table node context, which has 'name' child with 'Bob' value. In this case you can set the current context to any node and then to match the query, using this context.
· setContextNode(int node) – changes the context Node – see DTM and XpathContext.
· setContextSize(int node) – changes the context size.
· setContextPosition(int pos) – changes the context position.
2. You have several packages in your classpath, which include the org.xml.sax or org.w3c.dom, interfaces and the class loader loaded the older version. This usually happens when you try to use Apache (Tomcat) and SAP J2EE Engine. In this case you have either to move SAP J2EE Engine in front of apaches (xerces.jar, xalan.jar) in the classpath, to remove the other parser (it might be any other), or just to download new interfaces (for example 1.4.3 version of Xerces)
To use the SAP XML Toolkit in a stand-alone program, you can set the following system properties:
javax.xml.parsers.DocumentBuilderFactory=com.sap.engine.lib.jaxp.DocumentBuilderFactoryImpl
javax.xml.parsers.SAXParserFactory=com.sap.engine.lib.jaxp.SAXParserFactoryImpl
javax.xml.transform.TransformerFactory=com.sap.engine.lib.jaxp.TransformerFactoryImpl
or make sure the sapxmltoolkit.jar is set in your classpath. This file must be set before any other XML parser's JAR file.
3. To use SAP XML Toolkit, you must register a reference to it from your application. This can be done at deployment time using either Deploy tool or the Deploy Service CHANGEREF command. In order to register a reference from the deployed application to the SAP XML Toolkit library, refer to Editing the Deployment Properties of an Application.
Also, you can use the SAP NetWeaver Developer Studio to add a reference from your application to the SAP XML Toolkit library. With selected application choose Project ® Properties ® Java Build Path ® Libraries ® Add Variable. Select SAP_XML_TOOLKIT_LIBS_HOME and choose Extend. In lib folder, select sapxmltoolkit.jar and choose OK.
4. There are three possible ways to use Xerces parser in your application:
...
a. Register Xerces as an additional library on SAP J2EE Engine
You can do this using the Deploy Service
CHANGE_LIB command or manually copy the
archive file in <SAP_J2EE_Engine_install_dir>/cluster/server/bin/ext /
directory and you can write your own provider.xml
file in which you can specify the reference to the Xerces library. For more
information, refer to
library.provider.dtd. In order to register a reference
from your deployed application to the Xerces library, refer to Editing the Deployment
Properties of an Application.
b. If you are using the Xerces parser in classes that are included in a WAR file, add xerces.jar in the Web-Inf/lib directory in the WAR.
c. Add xerces.jar to your applications EAR.
5. You must set the http.proxyHost and http.proxyPort system properties.
