[jdom-interest] Whitespace
Jeremy Whitlock
jwhitlock at starprecision.com
Mon Jan 19 14:44:01 PST 2004
JDOM,
Im 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>
Youll 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
More information about the jdom-interest
mailing list