[jdom-interest] BUG: XMLOutputter inserts extra empty lines

Andriy Palamarchuk apa3a at yahoo.com
Wed Nov 21 07:06:13 PST 2001


When I read an XML file and save it back with
XMLOutputter the result document contains extra empty
lines before some closing tags which are on separate
lines.
However, there is no extra empty lines when I compose
exactly the same document as JDom object in code and
then print it with XMLOutputter. Obviously, this is
some problem in the outputter with handling space
between tags.

I use JDom Beta 7.

Please, let me know in case I missed something.
Is there any workaround for this problem?

Code which reads/writes XML:

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(
    new File("employees.xml"));

XMLOutputter outputter = new XMLOutputter();
outputter.setNewlines(true);
outputter.setIndent(true);
outputter.setTextNormalize(true);
String docStr = outputter.outputString(doc);
System.out.println(docStr);

The original XML file:
<?xml version="1.0" encoding="UTF-8"?>

<employees>
  <employee id="1" title="developer"
first-name="first-name1" last-name="last-name1">
    <picture>apalamarchuk.jpeg</picture>
    <profile>Design, coding, debugging; goto
design;</profile>
  </employee>
  <employee id="2" title="developer"
first-name="first-name2" last-name="last-name2">
    <picture>mmiller.jpeg</picture>
    <profile>Design, coding, debugging, riding bike;
goto design;</profile>
  </employee>
  <employee id="3" title="manager"
first-name="first-name3" last-name="last-name3">
    <picture>mbaara.jpeg</picture>
    <profile>Manage employees 1 and 2.</profile>
  </employee>
</employees>

The resulting XML file:
<?xml version="1.0" encoding="UTF-8"?>
<employees>
  <employee id="1" title="developer"
first-name="first-name1" last-name="last-name1">
    <picture>apalamarchuk.jpeg</picture>
    <profile>Design, coding, debugging; goto
design;</profile>
    
  </employee>
  <employee id="2" title="developer"
first-name="first-name2" last-name="last-name2">
    <picture>mmiller.jpeg</picture>
    <profile>Design, coding, debugging, riding bike;
goto design;</profile>
    
  </employee>
  <employee id="3" title="manager"
first-name="first-name3" last-name="last-name3">
    <picture>mbaara.jpeg</picture>
    <profile>Manage employees 1 and 2.</profile>
    
  </employee>
  
</employees>



__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1



More information about the jdom-interest mailing list