wood burning stoves*
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
Author

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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Format XML