[jdom-interest] XMLOutputter bug?

Joseph Bowbeer jozart at csi.com
Wed Aug 29 23:15:43 PDT 2001


Does XMLOutputter remove a newline it shouldn't?

I wrote a test program that builds a document from this input string:

<Person>
  <name>Jane Smith</name>
  <date-of-birth>1965-05-23</date-of-birth>
  <citizenship>US</citizenship>
</Person>

The output from XMLOutputter is:

<?xml version="1.0" encoding="UTF-8"?>
<Person>
  <name>Jane Smith</name>
  <date-of-birth>1965-05-23</date-of-birth>
  <citizenship>US</citizenship></Person>

( Where's the newline before the closing </Person>? )

I've verified that SAXBuilder is not losing the newline; if I send the
document through SAXOutputter and XMLWriter (samples.sax), I get the
following output:

<?xml version="1.0"?>

<Person>
  <name>Jane Smith</name>
  <date-of-birth>1965-05-23</date-of-birth>
  <citizenship>US</citizenship>
</Person>


Here's the test program:

/*
 * OutputterTest2.java
 */

import java.io.StringReader;

import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.SAXOutputter;
import org.jdom.output.XMLOutputter;

import samples.sax.XMLWriter;

/**
 * Demonstrate bug in XMLOutputter
 */
public class OutputterTest2 {

    /** Creates new OutputterTest2 */
    public OutputterTest2() {
    }

    /**
    * @param args the command line arguments
    */
    public static void main (String args[]) throws Exception {
        String xml =
            "<Person>\n" +
            "  <name>Jane Smith</name>\n" +
            "  <date-of-birth>1965-05-23</date-of-birth>\n" +
            "  <citizenship>US</citizenship>\n" +
            "</Person>\n";

        System.out.println("Input string:\n\n" + xml + "\n");
        Document doc = new SAXBuilder().build(new StringReader(xml));

        System.out.println("Output by XMLOutputter:\n");
        new XMLOutputter().output(doc, System.out);
        System.out.println("\n");

        System.out.println("Output by XMLWriter:\n");
        XMLWriter xw = new XMLWriter();
        SAXOutputter outputter = new SAXOutputter(xw, xw, xw, xw, xw);
        outputter.output(doc);
    }
 }

--
Joe Bowbeer





More information about the jdom-interest mailing list