You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by oceatoon <t....@systheo.com> on 2005/04/04 13:02:37 UTC

save XML document to disk?

Hi cocooners

I'm using loadDocument(path2myxml) to act on an xml file in my flow. Before
going into a new dev I was wondering if there allready existed a
"savedocument(document , path)" or document.save() function, that saves
back to disk the applied modifications. I found saveXML in the
sessionContext, but can't use it in the FLow.

var document = loadDocument("path/labels_multi.xml");
---XML modfications---
document.save();

Thanks for the thoughts
Tibor


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re:(Solved) save XML document to disk?

Posted by oceatoon <t....@systheo.com>.
My Apologies for these auto responded questions 
I guess it fills up the list with questions and answers ;)
Regards

//saves document to the uri
function saveDocument(document, uri) { 
     var source = null; 
     var resolver = null; 
     var outputStream = null; 
     try { 
         resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE); 
         source = resolver.resolveURI(uri); 
 
        var tf =
Packages.javax.xml.transform.TransformerFactory.newInstance(); 
        if (source instanceof
Packages.org.apache.excalibur.source.ModifiableSource &&
tf.getFeature(Packages.javax.xml.transform.sax.SAXTransformerFactory.FEATURE))
{ 
             outputStream = source.getOutputStream(); 
             var transformerHandler = tf.newTransformerHandler(); 
             var transformer = transformerHandler.getTransformer(); 
             transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.INDENT,
"true"); 
             transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.METHOD,
"xml"); 
             transformerHandler.setResult(new
Packages.javax.xml.transform.stream.StreamResult(outputStream)); 
             var streamer = new
Packages.org.apache.cocoon.xml.dom.DOMStreamer(transformerHandler); 
             streamer.stream(document); 
         } else { 
             throw new
Packages.org.apache.cocoon.ProcessingException("Cannot write to source " +
uri); 
         } 
     } finally { 
         if (source != null) 
             resolver.release(source); 
         cocoon.releaseComponent(resolver); 
         if (outputStream != null) { 
             try { 
                 outputStream.flush(); 
                 outputStream.close(); 
             } catch (error) { 
                 cocoon.log.error("Could not flush/close outputstream: " +
error); 
             } 
         } 
     } 
 } 

<posté comme article et comme courrier>

oceatoon wrote:

> Hi cocooners
> 
> I'm using loadDocument(path2myxml) to act on an xml file in my flow.
> Before going into a new dev I was wondering if there allready existed a
> "savedocument(document , path)" or document.save() function, that saves
> back to disk the applied modifications. I found saveXML in the
> sessionContext, but can't use it in the FLow.
> 
> var document = loadDocument("path/labels_multi.xml");
> ---XML modfications---
> document.save();
> 
> Thanks for the thoughts
> Tibor



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org