wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Urgent: simple transformer failing with strange file exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Urgent: simple transformer failing with strange file exception" Watch "Urgent: simple transformer failing with strange file exception" New topic
Author

Urgent: simple transformer failing with strange file exception

Gopi Krishna
Greenhorn

Joined: Aug 09, 2002
Posts: 5
Hi I wrote very simple XSL transformer program using xalan and xereces and it is failing with following strange error. pl help me about what to do.

code :

import java.io.File;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class TransformFiles {
public static void main(String inArgs[]) throws Exception {

File xsltFile = new File(inArgs[0]);
File xmlFile = new File(inArgs[1]);
File outputFile = new File(inArgs[2]);

StreamSource xsltStream = new StreamSource(xsltFile);
StreamSource xmlStream = new StreamSource(xmlFile);
StreamResult outputResult = new StreamResult(outputFile);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer(xsltStream);
t.transform(xmlStream, outputResult);
}
}

here is the command I give

C:\java TransformFile <inputXSL> <inputXML> out.xml
and my class path has
rt.jar, xml-apis.jar, xercesImpl.jar, xalan.jar, xsltc.jar;

and I get follwoing error when I run above command.

Exception in thread "main" javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:\C:\java\out.xml (The filename, directory name, or volume label syntax is incorrect)

at org.apache.xalan.transformer.TransformerImpl.createSerializationHandler(TransformerImpl.java:1137)
at org.apache.xalan.transformer.TransformerImpl.createSerializationHandler(TransformerImpl.java:981)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1187)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1170)
at TransformFiles.main(TransformFiles.java:45)

any help is highly appreciated
thanks
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
That's weird. Try to specify a fully qualified path name to the arg2 and see what happens. I'm having a similar problem - the transformer stuff doesn't work when there are imbedded spaces in the path (i.e. c:\documents and settings... in a Windows env.) Temp files as such don't work unless you specify a directory that you know exists (like root) in your file constructor. So it's not really portable as such.
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Oh, and you need to create a new file - you just created a handle
Gopi Krishna
Greenhorn

Joined: Aug 09, 2002
Posts: 5
HI Paul,
Thanks for your reply. But I tried all those options like giving
full path,
"./input.xsl".
Regarding output.xml I tried both options like using existing file and giving a new file name.
in all cases it is failing with same exception.

Strange thing is: If I use System.out instead of a file like

//StreamResult outputResult = new StreamResult(outputFile);
StreamResult outputResult = new StreamResult(System.out);

Thanks
Gopi
 
Don't get me started about those stupid light bulbs.
 
subject: Urgent: simple transformer failing with strange file exception