Hi Peter,

I have upgraded my project from Cocoon 2.1.8 to 2.1.9. It did not bring
in any extra whitespace behaviour.

The saveDocument() function from 2.1.9 samples could be responsible
although I doubt. I use a modified version of it. Hereafter the code you may try to see if it makes any difference. (Please note this code is test code).

importPackage(Packages.java.io);
importPackage(Packages.javax.xml.transform);


/* document: DOM document to be saved
 * uri:      Path to saved file /tmp/mydoc.xml
 * encoding: For ex: "ISO-8859-1"
 */
function saveDocument(document, uri, encoding) {

  cocoon.log.info("saveDocument, uri: " + uri);
  var outFile = null;
  var bufferOS = null;

    try {
        outFile = new Packages.java.io.File(uri);
        var fileOS = new FileOutputStream(outFile);
        var bufferOS = new BufferedOutputStream(fileOS);
        var resultStream = new
Packages.javax.xml.transform.stream.StreamResult(bufferOS);
                
        var factory = TransformerFactory.newInstance();
        var transformer = factory.newTransformer();

        transformer.setOutputProperty(OutputKeys.INDENT, "false");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");

        transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
        transformer.setOutputProperty(
          OutputKeys.OMIT_XML_DECLARATION,  "no");
        transformer.transform(
          new Packages.javax.xml.transform.dom.DOMSource(document),
          resultStream
        );

        cocoon.log.info(
          "saveDocument() trans. from document to resultStream done");
        }
        catch (error) {
          cocoon.log.error("saveDocument(): Could not save document: " +
            error);
        }
        finally {
        if (bufferOS != null) {
            try {
                bufferOS.flush();
                bufferOS.close();
            } catch (error) {
                cocoon.log.error(
                  "Could not flush/close BufferedOutputStream: " +
                   error);
            }
        }
    }
}


The third cause for extra whitespace might come from your binding...


Patrick


Peter Sparkes wrote:
Hi Patrick,

I am using Cocoon 2.1.9. I am doing the following


//All the ***URI variables are in putted via the sitemap
//create new form
var form = new Form(definitionURI);
// bind form - builds the binding  using xslt via the sitemap
form.createBinding('cocoon:/'+bindingURI);
// parse the xml document, which is to be amended to a DOM-tree
var document = loadDocument(documentURI);
// bind the document data to the form
form.load(document);
// show the form to the user until it is validated successfully
form.showForm(documentURI+"lodge-display-pipeline"); // bind the form's data back to the document
   form.save(document);
// save the DOM-tree back to an XML file using the saveDocument function from the CForm samples
 saveDocument(document, documentURI);
Peter

Peter Sparkes wrote:

Hi,

I am using CForms to amend an xml file on the server. Every time the file is amended it gets a lot of extra whitespace, when it is saved using the flowscript, wherever there is a repeater widget.

Please how can I stop this happening

Peter Sparkes

Hi Peter,

I think you should give more details about what you mean by "saved using the flowscript". I am not aware of a single way to saving an XML file representation in flowscript (DOM) to a file.

I do use Cocoon Flow with DOM binding to amend XML files, using repeaters, and did not notice the behaviour you describe. (Using Cocoon 2.1.8)

Patrick


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to