[jdom-interest] JDOM -> Xalan using SAX

Lasse Lindgård lasse at lintor.dk
Thu Jan 25 11:19:45 PST 2001

I just hacked this code together and I thought that I would submit it.
I wrote it this way because my old code (using Xalan 1.2 and the
DOMOutputter) seemed to be sluggish.
I didn't get a chance to profile this code just yet, but it might or might
not be faster than the original DOMOutputter code.

I hope that someone can suggest some improvements. I would have thought that
the code was faster than the old.


public final static void transformXalan2SAX(Document jdom, String
stylesheet, PrintWriter out)
	throws IOException, TransformerConfigurationException, SAXException,
JDOMException {
	// Instantiate a TransformerFactory.
	TransformerFactory tFactory = TransformerFactory.newInstance();
Honestly it seems a bit slower - but I don't know where the bottleneck is

	// Cast the TransformerFactory.
	SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
	// Create a ContentHandler to handle parsing of the stylesheet.
	TemplatesHandler templatesHandler = saxTFactory.newTemplatesHandler();

	// Create an XMLReader and set its ContentHandler.
	XMLReader reader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();

	// Parse the stylesheet.

	//Get the Templates object from the ContentHandler.
	Templates templates = templatesHandler.getTemplates();
	// Create a ContentHandler to handle parsing of the XML source.
	TransformerHandler handler = saxTFactory.newTransformerHandler(templates);

	Result result = new javax.xml.transform.stream.StreamResult(out);

	SAXOutputter jdomOut = new SAXOutputter(handler);

More information about the jdom-interest mailing list