Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Format XML

 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic