It may be ugly, but this works required that the DOM Document (aDocument
here) was stripped from ignorable white spaces (formatting indentation
nodes) at parse time. The 'OutputFormat' constructor takes its third
argument as an indicator if you want to indentate the Document again
(probably if you want to make it human-enabled)
From string -> file is trivial?

    public String getDocumentStringRepresentation() {
        // Format the document for string representation
        OutputFormat    format  =
            new OutputFormat(aDocument, null, true);   //Serialize DOM
        StringWriter  stringOut = 
            new StringWriter(); //Writer will be a String
        XMLSerializer    serial = new XMLSerializer(stringOut, format);
        try {
            serial.asDOMSerializer();   // As a DOM Serializer  
            serial.serialize( aDocument.getDocumentElement() );
        }  catch ( Exception ex ) {
            ex.printStackTrace();
        }

        return stringOut.toString();
    }

best,
/aksel

-----Original Message-----
From: David DELGRANCHE [mailto:[EMAIL PROTECTED]
Sent: 7. marts 2001 14:54
To: Xerces J Users (Adresse de messagerie)
Subject: Node Insertion in an XML document


                Hi all

        I have to insert a node into an XML document at the end. I know how
to 
insert a node into a DOM, but I have one question. How to come back to the 
XML document from the DOM: if I insert a node in my DOM How to be sure that 
there is also one more node in my document?
        Thanks
David.

David DELGRANCHE
[EMAIL PROTECTED]       
Tel: 02.99 05.34.25     
Fax: 02.99.05.34.05
Sogitec Industries
24, Avenue Lavoisier
ZI du Champ Niguel
35174 BRUZ CEDEX




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

Reply via email to