Java XML Sanitize sanitizeXML(String xml)

Here you can find the source of sanitizeXML(String xml)

Description

Remove all unnecessary white spaces, tabs and line breaks from XML string.

License

Open Source License

Parameter

Parameter Description
xml a parameter

Declaration

public static String sanitizeXML(String xml) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  ww  .j a v a  2  s .  c  o m
     * Remove all unnecessary white spaces, tabs and line breaks from XML string.
     * TODO: Would be better to use a XSD with setIgnoringElementContentWhitespace attribute true
     * 
     * @param xml
     * @return
     */
    public static String sanitizeXML(String xml) {
        return xml.replace("\n", "").replace("\r", "").replace("\t", "").replaceAll(">\\s+<", "><").trim();
    }
}

Related

  1. sanitizeJson4XML(String jsonString)
  2. SanitizeXmlString(String xml)
  3. sanitizeXmlTypeName(String name)