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

Jason Hunter jhunter at acm.org
Wed Dec 5 18:46:11 PST 2001


This is due to a known bug in XMLOutputter present in beta7.  It was
even in the TODO.txt if you'll notice.  Since b7 there've been some
changes to try to fix this and other issues, and in fact the outputter
now is not printing newlines sometimes when it should.  It needs a
cleanup.

-jh-

Andriy Palamarchuk wrote:
> 
> 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
> _______________________________________________
> 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