• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error transforming XML using TransformerHandler

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to port a web application that from Oracle9iAS to Websphere 5.0. I am getting a problem on Websphere, when I try to get a TransformerHandler from TransformerFactory and using TransformerHandler as a ContentHandler to fire SAX events. The transformation does not happen and I get an empty XML declaration in the output. I verified that if I do not specify the templates while getting the TransformerHandler, it is doing an identity transformation correctly. Also there are templates within my XSL to handle the XML tags.
Here is the outline of my code :
if( templates == null )
{
templates = TransformerFactory.newInstanc().newTemplates
(new StreamSource(new File("xml_to_fo.xsl")));
}
TransformerHandler hd = tf.newTransformerHandler
(templates);
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty( OutputKeys.INDENT,"no" );
hd.setResult( new StreamResult(new File(OUTPUT_FILENAME) );
hd.startDocument();
..... // Code to add XML nodes to the document
hd.endDocument();
I tried 2 different approaches to troubleshoot this:
1) On Oracle9IAS I was using an older version on xalan. I thought that the problem may due to a bug in the xalan that ships with Websphere. So I changed the Application class loading mode to 'Parent Last' from 'Parent First' so that Websphere would pick my version of the xalan classes(under web-inf/classes/lib). That did not help. In both cases, when I printed the loader info, I got com.ibm.ws.bootstrap.ExtClassLoader@56fd9395 as class loader and sun.misc.Launcher$AppClassLoader@55021395 as parent loader.
2) Next I wrote a stand alone java program to test the transformation process with the xalan.jar version from websphere and the version I had from Oracle9iAS. I found that with both versions of the jar, transformation happened correctly. I think this means that there is something wrong in the Websphere environment that is causing the problem. The stand alone program code is shown below :
TransformerFactory tf = TransformerFactory.newInstance();
Templates templates = tf.newTemplates(new StreamSource("xml_to_fo.xsl"));
TransformerHandler hd = ((SAXTransformerFactory)tf).newTransformerHandler
(templates );
Transformer transformer = hd.getTransformer();
transformer.transform(new StreamSource(new File("source.xml")), new StreamResult(System.out));
Any help in fixing the problem is appreciated.
Thanks,
Sankar
[ August 22, 2003: Message edited by: Sankar Tanguturi ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic