I've experimented with making changes to the SqlXmlUtil class so that
it uses the JAXP/DOM interfaces instead of the Xalan implementation
classes to make it independent of the actual underlying implementation.
The attached patch (xml-interfaces.diff) is just for testing. It needs
more polishing before it can be committed, but in its current state it
successfully runs all the XML tests on Oracle's Java 6, without
separate Xalan jars on the classpath.
In short, the patch changes from the following implementation classes
to these interfaces:
org.apache.xalan.serialize.Serializer -> javax.xml.transform.Transformer
org.apache.xpath.XPath -> org.w3c.dom.xpath.XPathEvaluator
The javax.xml.transform.Transformer interface is part of JDK 1.4.2,
but org.w3c.dom.xpath.XPathEvaluator isn't, so this change means we'll
have to reintroduce the xml-apis.jar file (part of Xalan) that we
DERBY-3702. But only as a build dependency. On the bright
side, we shouldn't need xalan.jar, xercesImpl.jar or serializer.jar in
the build anymore.
There are interfaces that provide support for XPath in JDK 1.4.2 too,
but those interfaces require us to know up front what the return type
of an XPath query is, and we don't have that information when we
compile the query. org.w3c.dom.xpath.XPathEvaluator doesn't have this
To test the patch, get xml-apis.jar from the Subversion history with
svn copy https://svn.apache.org/repos/asf/db/derby/code/trunk/tools/java/xml-apis.jar@588374 tools/java
Some missing parts that need to be worked out before the patch is
1) Formatting of floating point numbers is done differently. The
current code uses org.apache.xpath.objects.XNumber.str() to format the
numbers, and the patch uses Double.toString(). Double.toString() uses
exponents/scientific notation to make the result string more compact,
whereas XNumber.str() doesn't use exponents. There are currently no
tests that expose this difference.
2) The original code uses an instance of
org.apache.xml.utils.PrefixResolverDefault to resolve prefixes when
evaluating XPath queries. According to the comments, this is needed in
order to prevent NPEs in some queries. However, none of the XML tests
failed when tried to replace the resolver with null in the original
code. So some more investigation is needed in order to find out what
problem this code is supposed to fix, and if something special is
needed to handle that in the new code.
Here are some more details about what the patch does:
Remove code that's not used anymore
Compile SqlXmlUtil.java against xml-apis.jar instead of xercesImpl.jar.
Stop looking for Xalan implementation classes, and instead see if we
have the JAXP interfaces and check that the DOM implementation
supports the required XPath functionality.
Use the interfaces as described above.
Check for JAXP interfaces and DOM level instead of a specific Xalan
version, and rename methods accordingly.
Use the new helper methods that check if the XML operators are