AW: [jdom-interest] Formatting of files

MarkW markw at wilsoncom.de
Mon Aug 13 00:24:44 PDT 2001


Hi!,
Take a look at the example samples\sax\FilterTest.java.
You´ve probably got a formatted file to start with and first you have to
unformat it (see example).
You can output using:

  public static void JDOMDocToFile( String filename, org.jdom.Document doc )
  {
    try
    {
      FileOutputStream out = new FileOutputStream( filename );
      XMLOutputter fmt = new XMLOutputter();
      fmt.setTextNormalize( true );
      fmt.setIndent( true );
      fmt.setIndentSize( 2 );
      fmt.setNewlines( true );
      fmt.output( doc, out );
      out.close();
    }
    catch ( FileNotFoundException fnfx )
    {
      logError( fnfx );
    }
    catch ( IOException iox )
    {
      logError( iox );
    }
  }

Take a look at the various options of XMLOutputter.
Hope it helps.

Greetings from Germany,
Mark Wilson
WILSONCOM.

> -----Ursprüngliche Nachricht-----
> Von: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]Im Auftrag von Abhishek Srivastava
> Gesendet: Samstag, 11. August 2001 15:04
> An: Jdom-Interest (E-mail)
> Betreff: [jdom-interest] Formatting of files
>
>
> Hello All,
>
> I have a XML file, I build a JDOM tree out of it and then I save
> it back to
> the file.
>
> On saving back, I find that there are a lot of extra lines
> introduced in my
> XML file.
>
> I looked up the documentation of jdom and used the API
> out.setTextNormalize(true);
> Even after this, I still see some extra new lines coming into my document.
> Can I rectify this ?
>
> I am attaching the original.xml (this is how my file initially
> looked like)
> distroted1.xml (this is the output if I do not use setTextNormalize)
> distorted2.xml (this is the output if I use setTextNormalize).
>
> Also attached is the program that I am using.
> Any help would be greatly appreciated.
>
> regards,
> Abhishek.
>




More information about the jdom-interest mailing list