[jdom-interest] bug: JDOM 1.0 XMLOutputter.outputString() --trailing 0A character

Hugo Garcia hugo.a.garcia at gmail.com
Thu Dec 1 10:10:18 PST 2005


I've notice this behavior too and thanks for solving it. So simple...

-H

On 11/30/05, William Krick <wkrick at eio-online.com> wrote:
> I think I found the problem.  In my servlet, I'm returning the XML using
> println() instead of print().  println is adding the 0A because the server
> is runing unix.  Sorry about that.  My bad.
>
> Just for reference, here's my sample servlet...
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.jdom.*;
> import org.jdom.output.*;
>
>
> public class TestJDOM extends HttpServlet {
>   public void doGet(HttpServletRequest req, HttpServletResponse res) throws
> ServletException, IOException {
>     res.setContentType("application/xml; charset=utf-8");
>     PrintWriter out = res.getWriter();
>     XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
>     Element root = new Element("ROOT");
>     root.setText("Hello World!");
>     Document doc = new Document(root);
>     String s = outputter.outputString(doc);
>     out.println(s); // wrong!  should use print() instead
>   }
> }
>
>
>
> -----Original Message-----
> From: Jason Hunter [mailto:jhunter at xquery.com]
> Sent: Tuesday, November 29, 2005 8:04 PM
> To: William Krick
> Cc: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] bug: JDOM 1.0 XMLOutputter.outputString()
> --trailing 0A character
>
>
> I don't see how, in logic or in code, you could get a 0A at the end of a
> document due to JDOM's actions.  Could you send a short (i.e. 5 line)
> complete program that reproduces the problem reliably on your end, and
> then we'll be able to figure out what's going on.
>
> -jh-
>
> William Krick wrote:
>
> > It puts a 0D0A (CRLF) at the end of each line and an additional 0D0A
> (CRLF)
> > at the end of the file, as you mention.  But then there is a final 0A
> > character tacked on the end.
> >
> > Here's a link to our servlet that generates the XML using JDOM...
> >
> > http://www.eio-online.com/update/getkey?account=AAA610456
> >
> > Open the link in your browser, save the file to your desktop, then open it
> > in an editor that allows you to look at the file in hex mode.  You'll see
> > the extra 0A at the end of the file.
> >
> >
> >
> > -----Original Message-----
> > From: Jason Hunter [mailto:jhunter at xquery.com]
> > Sent: Tuesday, November 29, 2005 4:41 PM
> > To: William Krick
> > Cc: jdom-interest at jdom.org
> > Subject: Re: [jdom-interest] bug: JDOM 1.0 XMLOutputter.outputString()
> > -- trailing 0A character
> >
> >
> > The pretty formatter prints a newline at the end of output.  When
> > printed to a console or file this is "prettier".  :)
> >
> > -jh-
> >
> > William Krick wrote:
> >
> >
> >>I have a jdom document object built dynamically by my application.
> >>
> >>When I use XMLOutputter.outputString() to convert the document to a
> >
> > string,
> >
> >>the resulting string ends with an extra trailing 0A character.  This
> >
> > appears
> >
> >>to be a bug.
> >>
> >>Here's what the code looks like...
> >>
> >>XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
> >>String s = outputter.outputString(doc);
> >>
> >>
> >>
> >>--
> >>No virus found in this outgoing message.
> >>Checked by AVG Free Edition.
> >>Version: 7.1.362 / Virus Database: 267.13.10/188 - Release Date:
> >
> > 11/29/2005
> >
> >>_______________________________________________
> >>To control your jdom-interest membership:
> >>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> >>
> >
> >
> >
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>



More information about the jdom-interest mailing list