Meaningless Drivel is fun!
The moose likes XML and Related Technologies and the fly likes Format XML 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 "Format XML" Watch "Format XML" New topic

Format XML

Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
Hello everyone.
Does anybody know of an API to format XML strings?

I have lots of data in xml to debug, and having them all in a single line makes things very hard to understand.
It would be great if I could just wirte something like:
String formattedXml = XMLFormatter.format( xmlString ) ;

I'm starting my search, but I've found only thing for the .NET platform.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
See HowToPrettyPrintXmlWithJava for doing the job with Xerces' XMLSerializer (requires Xerces), or DocumentToString for doing it with an "identity transform" (uglier formatting, but doesn't require third party libraries if you're using J2SE 1.4).

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Format XML
It's not a secret anymore!