[jdom-interest] StreamResult JDOMSource Transformer problem

Rich Baldwin Rich.Baldwin at noaa.gov
Wed Sep 28 08:29:58 PDT 2005


fyi,

I have resolved this issue.  Although the StreamResult constructor 
accepts a File parameter, it doesn't handle the object correctly.  Pass 
a FileOutputStream and it works fine.

FileOutputStream outstream = new FileOutputStream(outfile);
StreamResult out = new StreamResult(outstream);


Rich

Rich Baldwin wrote:

> I trying to transform an xml document generated from a database call 
> to a text output file.  This works fine when System.out is specified 
> in the StreamResult, but when a File is defined I get a
>
> javax.xml.transform.TransformerException: 
> java.io.FileNotFoundException: home/username/Java/final.xml (No such 
> file or directory)
>        at 
> org.apache.xalan.transformer.TransformerImpl.createResultContentHandler(Unknown 
> Source)
>        at 
> org.apache.xalan.transformer.TransformerImpl.createResultContentHandler(Unknown 
> Source)
>        at 
> org.apache.xalan.transformer.TransformerImpl.transform(Unknown Source)
>
> Is there something about StreamResult or JDOMSource that the 
> Transformer doesn't like?
>
> Tx, Rich
>
> Here is a code snippet:
> public class xmlquerydb_xsl
> {
>  public static void main(String args[]) throws SQLException
>  {
>   File outfile = null;
>    
> System.setProperty("javax.xml.transform.TransformerFactory","org.apache.xalan.processor.TransformerFactoryImpl"); 
>
>    
> System.setProperty("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl"); 
>
> //  File output fails
>    //File outfile = new File("final.xml");
>    //StreamResult out = new StreamResult(outfile);
> // System.out works
>    StreamResult out = new StreamResult(System.out);    ""
> //  Connect to database generate xml document         OracleXMLQuery 
> qry = new OracleXMLQuery(conn, query);
>        Document domDoc = (Document) qry.getXMLDOM();
>         org.jdom.input.DOMBuilder builder = new 
> org.jdom.input.DOMBuilder();
>         org.jdom.Document jdomDoc = builder.build(domDoc);
>         JDOMSource src = new JDOMSource(jdomDoc);
>
>        TransformerFactory transformerfactory = 
> TransformerFactory.newInstance();
>        Transformer xf = transformerfactory.newTransformer(new 
> StreamSource("space-delimited.xsl"));        
> xf.setOutputProperty(OutputKeys.ENCODING,"US-ASCII");
>        xf.setOutputProperty(OutputKeys.INDENT,"yes");
>        xf.transform(src,out);
>  "
> }
> }
>
>------------------------------------------------------------------------
>
>_______________________________________________
>To control your jdom-interest membership:
>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rich.baldwin.vcf
Type: text/x-vcard
Size: 125 bytes
Desc: not available
Url : http://www.jdom.org/pipermail/jdom-interest/attachments/20050928/ec2cb8ef/rich.baldwin.vcf


More information about the jdom-interest mailing list