cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From will.durr...@digitalsteps.com
Subject How do I prevent elements being re-ordered when calling Form.save()
Date Thu, 19 Aug 2004 16:42:54 GMT
I'm binding a schema validated xml document to a cocoon form and then 
re-saving and sending it back to the database. However, at some point the 
xml elements are being re-ordered in alphabetical order which causes the 
schema validation to fail. I'm assuming that this alphabetical re-ordering 
occurs either when I call the Form.save() method within my flowscript or 
when I serialize the saved document by calling the serialize method below 
(as used in the cocoon examples). Can anyone confirm where this 
re-ordering might be taking place and if possible advise how to prevent 
it.


function serializeDocument(document) {
    var source = null;
    var resolver = null;
    var writer = null;
    var xmlStr = null;
    try {
        resolver = 
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
        var tf = 
Packages.javax.xml.transform.TransformerFactory.newInstance();

        if 
(tf.getFeature(Packages.javax.xml.transform.sax.SAXTransformerFactory.FEATURE)) 
{
                        writer = new java.io.StringWriter();
            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(writer));

            var streamer = new 
Packages.org.apache.cocoon.xml.dom.DOMStreamer(transformerHandler);
            streamer.stream(document);
            xmlStr = writer.toString();
        } else {
            throw new Packages.org.apache.cocoon.ProcessingException(
"Cannot write to string");
        }
    } finally {
        if (writer != null) {
            try {
                writer.flush();
                writer.close();
            } catch (error) {
                cocoon.log.error("Could not flush/close writer: " + 
error);
            }
        }
    }
    return xmlStr;
}

Thanks

Will

Mime
View raw message