Hi guys, sorry to be asking this here. But I'm having trouble googling this
out.

Here is the problem. Given an xml document. I read it on my app and
manipulate it, then save it when I am done.


When I remove a child, the output files shows all the extra lines from the
formatting and indent. So it looks like a big hole in the xml file after the
node is removed. Here is an example

<bookshelf>
   <books>
       <book>
           <isbn>3349583080580584308</isbn>
           <author>Jon Stewart</author>
       </book>
        <book>
           <isbn>9900909770543356488</isbn>
           <author>Stephen Colbert</author>
       </book>
  </books>
</bookshelf>


Node parentNode = jonStewartNode.getParentNode();
parentNode.removeChild (jonStewartNode);

The result of this is the following xml.


<bookshelf>
   <books>




        <book>
           <isbn>9900909770543356488< /isbn>
           <author>Stephen Colbert</author>
       </book>
  </books>
</bookshelf>


How can I output the xml without this extra lines?


Thanks in advance,
f(t)
PS: here is the initialization, and configuration of the TransformerFactory,
and Transformer, and finally the save method.
    /**
    * Initializes factory instances and member variables.
    */
   private void initialize(){
       try{
           //obtain a trasformer factory to save the file
           this.transformerFactory = TransformerFactory.newInstance();
           this.transformerFactory.setAttribute("indent-number", 4);
           //obtain the transforme
           this.transformer = this.transformerFactory.newTransformer();
           //setup transformer
           this.transformer.setOutputProperty(OutputKeys.METHOD, "xml");
           this.transformer.setOutputProperty(OutputKeys.INDENT, "yes");
           
//this.transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount
<http://xml.apache.org/xslt%7Dindent-amount>", "4");
       }catch(TransformerConfigurationException tcex){
           this.logger.logException(this, "
errors.storage.xml.configuringXmlTransformer", true, tcex);
       }

   }




    /**
    * Saves the DOM document to the XML file.
    */
   private void saveDocument(){
       //verify that the documents is not null
       if(this.document==null)
           return;
       //sincronize document
       synchronized (this.document){
           try{
               //normalize document
               this.document.normalizeDocument();
               //get a document documentSource object out of the document
               DOMSource documentSource                = new DOMSource(
this.document);
               //create the file output stream
               FileOutputStream fileOutputStream       = new
FileOutputStream( this.file);
               //create the output stream writer
               OutputStreamWriter outputStreamWriter   = new
OutputStreamWriter(fileOutputStream);
               //create the stream streamResult out to the file Stream
               StreamResult streamResult               = new
StreamResult(outputStreamWriter);
               //performe the trasformation
               transformer.transform(documentSource, streamResult);
               //clean up
               outputStreamWriter.close();
               outputStreamWriter = null;
               fileOutputStream.close();
               fileOutputStream = null;
               documentSource = null;
           } catch (TransformerConfigurationException tcex) {
               // Error generated by the parser
               // Log Error
               this.logger.logException(this, "
errors.storage.xml.saveXMLRepositoryFile", true, tcex);

           } catch (TransformerException tex) {
               // Error generated by the parser
               // Log Error
               this.logger.logException(this, "
errors.storage.xml.saveXMLRepositoryFile", true, tex);
           } catch (Exception ex) {
               // Unknown error
               // Log Error
               this.logger.logException(this, "
errors.storage.xml.saveXMLRepositoryFile", true, ex);
           }
       }
   }
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to