4 Replies Latest reply: May 2, 2008 5:04 AM by 807591 RSS

    saving a file on disk

    807591
      I have a domdocument in memory obtained from a query to an oraqcle database and I want to save this file on disk. I'm tryng with this function, where xmlDoc is the document in memory and sFile is the name and path of the file to save (I don't know if the file must exists):

      public void SaveXMLRecordset(Document xmlDoc, String sFile)
      {
      try {
      DOMSource source = new DOMSource(xmlDoc);
      File file = new File(sFile);
      StreamResult result = new StreamResult(file);

      Transformer xformer = TransformerFactory.newInstance().newTransformer();
      xformer.transform(source, result);
      }
      catch (TransformerConfigurationException e)
      {
      e.printStackTrace();
      }
      catch (TransformerException e)
      {
      e.printStackTrace();
      }
      }

      I recieve the next error:
      XSL-1110: (Fatal Error) Invalid StreamResult set in TransformerHandler.
      javax.xml.transform.TransformerException: XSL-1110: (Fatal Error) Invalid StreamResult set in TransformerHandler.
      at oracle.xml.jaxp.JXTransformer.reportException(JXTransformer.java:681)
      at oracle.xml.jaxp.JXTransformer.transform(JXTransformer.java:268)
      at hospitalet.MngDataBase.SaveXMLRecordset(Hospitalet.java:485)
      at hospitalet.Hospitalet.main(Hospitalet.java:123)
      Caused by: java.io.FileNotFoundException: file:\C:\Develop\xmlRet.xml (El nombre de archivo, directorio o etiqueta del volumen no es v�lido)
      at java.io.FileOutputStream.open(Native Method)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
      at oracle.xml.jaxp.JXTransformer.transform(JXTransformer.java:264)
      ... 2 more
      ---------
      java.io.FileNotFoundException: file:\C:\Develop\xmlRet.xml (El nombre de archivo, directorio o etiqueta del volumen no es v�lido)
      at java.io.FileOutputStream.open(Native Method)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
      at oracle.xml.jaxp.JXTransformer.transform(JXTransformer.java:264)
      at hospitalet.MngDataBase.SaveXMLRecordset(Hospitalet.java:485)
      at hospitalet.Hospitalet.main(Hospitalet.java:123)


      I need solve this problem
      thank you
        • 1. Re: saving a file on disk
          800322
          File file:\C:\Develop\xmlRet.xml does not exist. I'd think the error message is quite clear. The path is syntactically wrong even if it were an URL.
          • 2. Re: saving a file on disk
            807591
            which is my error? the file really exists, is an empty file with this name and path
            • 3. Re: saving a file on disk
              807591
              Using the Xerces DOM parser, you can save a file like this:
                   public static void serializeXMLDocument(Document xmldoc, File filename) throws IOException {
                        FileOutputStream fos = new FileOutputStream(filename);
              //           XERCES 1 or 2 additionnal classes.
                        OutputFormat of = new OutputFormat("XML","ISO-8859-1",true);
                        //of.setIndent(1);
                        of.setIndent(0);
                        //of.setIndenting(true);
                        of.setIndenting(false);
                        //of.setDoctype(null,"users.dtd");
                        XMLSerializer serializer = new XMLSerializer(fos,of);
              //           As a DOM Serializer
                        serializer.asDOMSerializer();
                        serializer.serialize( xmldoc.getDocumentElement() );
                        fos.close();
                        //IOUtils.loadData(f)
                   }
              It looks like maybe you're not using Xerces... Is there an easy way to convert?
              • 4. Re: saving a file on disk
                807591
                thank you, I have the result desired on disk.