I am using StAX to create a quite large xml document. Until now I was using the IndentingXMLStreamwriter class to get a well formatted document (see also this answer). A few days ago we setup a jenkins server with an older jdk version (6.26), on which i get build errors.
package com.sun.xml.internal.txw2.output does not exist
I assume the package cannot be found because of the installed jdk version. For different reasons this cannot be changed
(by the way, does anyone know the jdk version, at which this package (com.sun.xml.internal.txw2.output) was added?).
Therefore I am looking for an alternative to do the indenting. I would prefer a solution similar to the one I was using, which means without reparsing the document. Any ideas or suggestions?
Thanks
Lars
If you are using Maven and Java 8, you can improt the following to use this class:
And then, you import it as:
import com.sun.xml.txw2.output.IndentingXMLStreamWriter;
There is an alternative implementation of IndentingXmlStreamWriter, which is provided as part of the open source stax-utils project here: http://java.net/projects/stax-utils/pages/Home
stax-utils seems to be a project set up to provide utilities based around the jsr-173 streaming xml api for Java
You'd need to add the stax-utils jar as a dependency for your project. Then you can import javanet.staxutils.IndentingXmlStreamWriter
Since stax-utils is in the maven central repository, if you use maven for your dependencies you can get it with:
Functionality seems very similar / equivalent to the txw2 class
I have excluded jsr173-ri since I am using jdk 1.7. I think 1.6+ has the jsr173 api as a standard feature, but if you are using 1.5 or lower you'd need the extra jsr173 jar.
If other suggestions don't work, you can get an indenting XMLStreamWriter from Saxon like this:
One advantage is that this allows you a lot of control over the serialization using other serialization properties.
Just expanding on Michael Kay's answer ( https://stackoverflow.com/a/10108591/2722227 ).
maven dependencies:
java code:
Instead of
com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter
usecom.sun.xml.txw2.output.IndentingXMLStreamWriter
that can be found in: