AW: [jdom-interest] SAXBuilder inserts unwanted carriage return

Jason Hunter jhunter at acm.org
Thu Nov 1 17:53:15 PST 2001


With your outputter you're asking for indention and whitespace to be
added.  But if your document already has that, then you're going to end
up with too much indentation and too much whitespace.  The default
settings on XMLOutputter are what you want if the data came
pre-formatted.  You can use the DUF classes to strip the whitespace and
then add it on output.  That's most helpful if you're going to
manipulate the data and change its whitespace and don't want the
whitespace preserved.

-jh-

MarkW wrote:
> 
> Hi,
> I had a similar problem and somebody pointed me to an example in
> \samples\sax.
> Look at DataFormatFilter.java and DataUnformatFilter.java.
> Hope it helps.
> 
> Mark
> 
> > When you create a document using SAXBuilder.build(), it seems that a
> > carriage return is inserted at each end of line. And when you output the
> > loaded document, it leads to ugly indentation.
> >
> > This is particularly true on script elements where
> > "<![CDATA[
> > ]]>"
> >   is inserted on EACH line.
> >
> > Here is a small code that shows the problem
> > public void showError()
> > {
> >      InputStream input;
> >      Document document;
> >      SAXBuilder builder;
> >      XMLOutputter outputter;
> >
> >      try
> >      {
> >        outputter = new XMLOutputter("  ", true);
> >        builder = new SAXBuilder();
> >        // Use your own xml file defining a script
> >        document = builder.build(new File("myDocument.xml"));
> >        outputter.output(document, System.out);
> >      }
> >      catch(Exception e)
> >      {
> >      }
> > }
> >
> > It is not a big deal, but if you want to use templates to generate your
> > final XML files, then you got badly indented files and human unreadable
> > scripts.
> >
> > Can the wonderful jdom team try to fix that for the next release?
> > Thanks,
> >
> > Philippe Converset
> >
> > _______________________________________________
> > To control your jdom-interest membership:
> > http://lists.denveronline.net/mailman/options/jdom-interest/yourad
> dr at yourhost.com
> 
> _______________________________________________
> 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