GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes xml-xml transformation exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml-xml transformation exception" Watch "xml-xml transformation exception" New topic
Author

xml-xml transformation exception

Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

When I am trying to transform a xml to another xml via xslt in Weblogic8.1 with default transformer available, I am getting following exception.

; Line#: -1; Column#: -1
javax.xml.transform.TransformerException: Premature end of file.
at org.apache.xalan.transformer.TransformerImpl.fatalError(TransformerIm
pl.java:739)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:715)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:1129)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:1107)
at com.toshiba.phoenix.ddc.ddcbatchprocess.XMLHelper.transformXML(XMLHel
per.java:70)
at com.toshiba.phoenix.ddc.ddcbatchprocess.DeviceDataCollectionWorkerThr
ead.run(DeviceDataCollectionWorkerThread.java:146)
at java.lang.Thread.run(Thread.java:534)

Here is the code for transformer:

Source inputXML= new StreamSource(in);
Source inputXSL = new StreamSource(Thread.currentThread().getContextClassLoader().getResourceAsStream("DDCCommonDataEbridge.xslt"));
TransformerFactory tFact = TransformerFactory.newInstance();

Transformer tf = tFact.newTransformer(inputXSL);

Result result = new StreamResult(new BufferedOutputStream(new FileOutputStream(new File("test.xml"))));

tf.transform(inputXML,result);

[ August 26, 2005: Message edited by: Jignesh Patel ]
[ August 26, 2005: Message edited by: Jignesh Patel ]
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

Moreover I have tried to implement inbuilt xlan processor with weblogic8.1
I got the following exception;
java.lang.ClassCastException
at weblogic.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1
531)
at weblogic.apache.xalan.xslt.XSLTEngineImpl.getSourceTreeFromInput(XSLT
EngineImpl.java:816)
at weblogic.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java
:390)
at com.toshiba.phoenix.ddc.ddcbatchprocess.XMLHelper.transformXML(XMLHel
per.java:90)
at com.toshiba.phoenix.ddc.ddcbatchprocess.DeviceDataCollectionWorkerThr
ead.run(DeviceDataCollectionWorkerThread.java:146)
at java.lang.Thread.run(Thread.java:534)

Here is the code:
XSLTInputSource source = new XSLTInputSource(in);

XSLTInputSource stylesheet= new XSLTInputSource(Thread.currentThread().getContextClassLoader().getResourceAsStream("DDCCommonDataEbridge.xslt"));
//System.out.println("test:"+stylesheet.getCharacterStream().read());

XSLTResultTarget target = new XSLTResultTarget(System.out);

And at the following line ClassCastException arises.

processor.process(source, stylesheet,target);
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

I have identified the problem: before transformation, I used to pass inputstream object to SAXParser, so it was convert inputstream in SAX format, and during transformation I have coded by considering as common inputstream and that is where the problem is.

Now 1 more query: Is there any way of converting SAXResult object to inputstream object or XMLBeans object.
 
GeeCON Prague 2014
 
subject: xml-xml transformation exception