Formatting XML

View: New views
3 Messages — Rating Filter:   Alert me  

Formatting XML

by Oliver Hirschi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

I have an XML generated with JDOM 1.1 and output it to a file
(pretty.xml) in PrettyFormat.
Now, I read the above file and output it with JDOM to another file
(raw.xml) in RawFormat:
----------------
SAXBuilder builder = new SAXBuilder();
Document oDoc_Chart = builder.build("c:\\000\\pretty.xml");

XMLOutputter oXMLOutputter = new XMLOutputter();
Format oFormat = Format.getRawFormat();
oXMLOutputter.setFormat(oFormat);
FileOutputStream oFileOutputStream = new
FileOutputStream("c:\\000\\raw.xml");
OutputStreamWriter oOutputStreamWriter = new
OutputStreamWriter(oFileOutputStream, "UTF-8");
oXMLOutputter.output(oDoc_Chart, oOutputStreamWriter);
oOutputStreamWriter.close();
oFileOutputStream.close();
----------------

The new file (raw.xml) is still pretty-formated and NOT raw - Why???

Thanks & Regards,
Oliver Hirschi


_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

Re: Formatting XML

by Rolf Lear-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Oliver....

Raw format is intended to output the file in the same format as it was
imported.... so, if you raw format output a file that was pretty to
start with, it will be unchanged.

Perhaps you are looking for Format.getCompactFormat().

I just wrote a small test program, and ran it against a file that has an
uncommon format. I can confirm that getPrettyFormat() makes it pretty,
getRawFormat leaves u unchanged, and getCompactFormat makes it all on
one line....

Rolf



Oliver Hirschi wrote:

> Hi
>
> I have an XML generated with JDOM 1.1 and output it to a file
> (pretty.xml) in PrettyFormat.
> Now, I read the above file and output it with JDOM to another file
> (raw.xml) in RawFormat:
> ----------------
> SAXBuilder builder = new SAXBuilder();
> Document oDoc_Chart = builder.build("c:\\000\\pretty.xml");
>
> XMLOutputter oXMLOutputter = new XMLOutputter();
> Format oFormat = Format.getRawFormat();
> oXMLOutputter.setFormat(oFormat);
> FileOutputStream oFileOutputStream = new
> FileOutputStream("c:\\000\\raw.xml");
> OutputStreamWriter oOutputStreamWriter = new
> OutputStreamWriter(oFileOutputStream, "UTF-8");
> oXMLOutputter.output(oDoc_Chart, oOutputStreamWriter);
> oOutputStreamWriter.close();
> oFileOutputStream.close();
> ----------------
>
> The new file (raw.xml) is still pretty-formated and NOT raw - Why???
>
> Thanks & Regards,
> Oliver Hirschi
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@...
>

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

Re: Formatting XML

by Oliver Hirschi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Rolf" <jdom@...> schrieb im Newsbeitrag
news:47C57F43.5050404@......

> Hi Oliver....
>
> Raw format is intended to output the file in the same format as it
> was imported.... so, if you raw format output a file that was pretty
> to start with, it will be unchanged.
>
> Perhaps you are looking for Format.getCompactFormat().
>
> I just wrote a small test program, and ran it against a file that has
> an uncommon format. I can confirm that getPrettyFormat() makes it
> pretty, getRawFormat leaves u unchanged, and getCompactFormat makes
> it all on one line....

Hi Rolf

I found the mistake:
There was a xml:space="preserve" attribute in the root-element...
After removing this it works well!

Thanks & Regards,
Oliver Hirschi


_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...
LightInTheBox - Buy quality products at wholesale price