Link to home
Start Free TrialLog in
Avatar of sukhoi35
sukhoi35

asked on

How do I 'minify' or clean the XML using Java?

There is a need for me to clean all incoming XML payload data and store it as an unformatted string using Java. In short, do something like what what the link below does. Is there a way this can be achieved using any of the Java libraries?
https://www.webtoolkitonline.com/xml-minifier.html 

Thanks.
Avatar of dpearson
dpearson

Are you able to assume that the XML to be formatted is valid XML?

If so the approach would be to parse it as an XML document and then walk that document printing out each element in the format you want (which is a single line with all whitespace removed between tags I believe).  But that won't work for invalid XML as the parse step would fail.

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sukhoi35

ASKER

Thank you experts, yes the messages received are well formed messages.
:)