Urgent: simple transformer failing with strange file exception
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
Posts: 245
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Oh, and you need to create a new file - you just created a handle
Gopi Krishna
Greenhorn
Posts: 5
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
| WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






