[jdom-interest] XMLOutputter bug?

Jason Hunter jhunter at acm.org
Thu Aug 30 11:39:56 PDT 2001


I wouldn't be surprised.  It used to add a new one in some cases.  There
was a patch from Alex Chaffee to fix that bug, but it may have been too
aggressive.  Alex?

-jh-

Joseph Bowbeer wrote:
> 
> 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
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list