[jdom-interest] RE: Whitespace
Jeremy Whitlock
jwhitlock at starprecision.com
Tue Jan 20 07:13:39 PST 2004
Bradley,
I'm using B9 as well and here is my code. It might have to do
with the fact that I'm loading it in from an InputStream but I don't see
why there would be a constructor using an InputStream if it caused
adverse effects. Here is my source:
package org.test;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
/**
* @author Jeremy Whitlock
*/
public class xmlTest
{
public static void main(String[] args)
{
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();
try
{
XMLOutputter outputter = new
XMLOutputter(" ", true);
FileWriter writer = new
FileWriter("test.conf");
outputter.output(doc, writer);
writer.close();
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
}
catch(JDOMException e)
{
e.printStackTrace();
}
catch(NullPointerException e)
{
e.printStackTrace();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
And with no modification what so ever, I get lines in between each line.
I've been looking at the XMLOutputter but I'm yet to find a solution.
I'll look at your code further and try to see why mine isn't working.
Thanks, Jeremy
-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]
On Behalf Of Bradley S. Huffman
Sent: Monday, January 19, 2004 9:20 PM
To: jwhitlock at starprecision.com
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] RE: Whitespace
"Jeremy Whitlock" writes:
> Bradley,
> That made no change. Here it is:
Hmmm, I use this
<?xml version="1.0" encoding="UTF-8"?>
<!--DBPirate Configuration File-->
<dbpirate>
<connections>
<connection>
<name>Oracle</name>
<user>cbuser</user>
<password>cbpass</password>
<hostname>localhost</hostname>
<port>1521</port>
<timestamp>345678</timestamp>
<class>org.mysql.jdbc.Driver</class>
<url>jdbc:mysql at localhost:3306:cookbook:cbuser:cbpass</url>
<sid>cookbook</sid>
</connection>
<connection>
<name>MySQL</name>
<user>scott</user>
<password>tiger</password>
<hostname>localhost</hostname>
<port>1521</port>
<timestamp>12345888</timestamp>
<class>oracle.jdbc.OracleDriver</class>
<url>jdbc:oracle:thin at localhost:1521:orcl:scott:tiger</url>
<sid>orcl</sid>
</connection>
</connections>
</dbpirate>
with this
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
public class TestXMLOutputter {
public static void main(String args[]) throws Exception {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build("pirate.xml");
XMLOutputter outputter = new XMLOutputter();
outputter.output(doc, System.out);
}
catch (java.io.IOException e) {
e.printStackTrace();
}
}
}
And it worked as expected with B9 and the latest CVS. What version of
JDOM are you using?
Brad
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
rhost.com
More information about the jdom-interest
mailing list