aspose file tools *
The moose likes XML and Related Technologies and the fly likes Formatting  xml using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Formatting  xml using java " Watch "Formatting  xml using java " New topic
Author

Formatting xml using java

prash patil
Ranch Hand

Joined: May 26, 2008
Posts: 40
Hello All,
I am writting an xml which I have stored in the Oracle DB in clob field.
When I retrieve the xml from DB as String it comes with chars like < etc.

I want to convert the string contains these chars to an XML tags like <, > etc.
Also The string is continious. I want to formated XML.
I am using XMLStreamWritter for writing xml.

Suggestion/Pointers required.

Thanks,
PP
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi prash,

the commons lang project contains an utility class named with which you can convert the XML entities in both directions ;)

Marco
prash patil
Ranch Hand

Joined: May 26, 2008
Posts: 40
Thanks Macro!!

Is there any way to format string containing xml tags.
i.e. <entries><entry><templateID>F04FD51B-C537-4d02-BB1D-E89971D1D65</templateID><entryID>41</entryID><subject>Updated Terms and Conditions</subject>

then outpur should be
<entries>
<entry>
<templateID>F04FD51B-C537-4d02-BB1D-E89971D1D65</templateID>
<entryID>41</entryID>
<subject>Updated Terms and Conditions</subject>
etc...
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Looking at your sample XML content a simple solution could be to replace the string "><" with ">\n<" to insert a line break between every two XML tags. Of course this is a very simplified idea which won't indent the output and works only for XML similar to your example.

Another possibility would be to really parse the XML content and re-create a new XML output file/stream with known XML APIs like SAX or DOM which can be configured to do pretty printing.

Marco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting xml using java