XML Minifier Online Tool




About XML Minifier Online Tool:

This online xml minifier tool helps you to minify raw XML string to save space to transmit faster cross Internet.

comic xml minifier

More information about XML (Extensible Markup Language):

RFC 3470 (XML): https://tools.ietf.org/html/rfc3470

Python Implementation of XML (BeautifulSoup): https://www.crummy.com/software/BeautifulSoup/

Java Implementation of XML (dom4j): https://dom4j.github.io/

XML Minifier with Python (with package htmlmin):

from htmlmin.minify import html_minify


def xml_minify(xml_str):
    xml_str = html_minify(xml_str, parser="lxml")
    return xml_str
    

XML Minifier with Java (with package dom4j):

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public String minify(String xmlStr){
    Document document=DocumentHelper.parseText(xmlStr);
    OutputFormat format=OutputFormat.createPrettyPrint();
    StringWriter stringWriter=new StringWriter();
    XMLWriter writer=new XMLWriter(stringWriter,format);
    writer.write(document);
    String resultStr=stringWriter.toString();
    return resultStr;
}