Strip extra spaces in a XML string : XML Serialization « XML « Java Tutorial

public class Main {
  public static void main(String[] args) {
    String xml = "<a>test 1</a>    <b>test 2</b> ";
    String out = xml.replaceAll(">\\s+<", "><");

33.21.XML Serialization
33.21.1.Saving a DOM tree to XML file javax.xml.parsers (JAXP)
33.21.2.PropsToXML takes a standard Java properties file, and converts it into an XML file
33.21.3.Writing a DOM Document to an XML File
33.21.4.Writing Only the Text of a DOM Document
33.21.5.Create an XML document with DOM
33.21.6.Strip extra spaces in a XML string
33.21.7.Extracting an XML formatted string out of a DOM object