Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] Whitespace

Jeremy Whitlock

2004-01-19


JDOM,
 I’m trying to clear all nodes of a particular type so here is my
code:

Try
{
 SAXBuilder builder = new SAXBuilder();
 InputStream ins =
ClassLoader.getSystemResourceAsStream("testlogins.conf"); // was
dbpirate.conf
 Document doc = builder.build (ins);
 Element rootElement = doc.getRootElement();
 Element connElement = rootElement.getChild("connections");
 List children = connElement.getChildren("connection");
 Iterator iterator = children.iterator();
     
 rootElement.getChildren("connections").clear();
 rootElement.addContent(new Comment("Testing"));
 rootElement.addContent(new Element("connections"));
 try
 {
   XMLOutputter outputter = new XMLOutputter(" ", true);

 
   outputter.output(doc, System.out);
 }
 catch (java.io.IOException e)
 {
   e.printStackTrace();
 }
}

and I get output like this:

<?xml version="1.0" encoding="UTF-8"?>
<!--DBPirate Configuration File-->
<dbpirate>

 

<!--Testing-->
<connections />
</dbpirate>

You’ll notice about 3 lines of white space before the comment in the
<dbpirate> element. Is there any way to get rid of this or a better way
to get rid of nodes so that I can keep the white space out? Thanks,

Jeremy Whitlock --- MCP/MCSA
IT Manager for Star Precision, Inc.
Phone:  (970) 535-4795
Metro:  (303) 926-0559
Fax:  (970) 535-0780
Metro Fax:  (303) 926-8557
http://www.starprecision.com


_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.