XML Minifier Pro






Related Pages: XML Formatter.

About XML Minifier Pro:

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

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 re):

import re


def minify_xml(input_str):
    return re.sub('[ \t]*[\r\n]{1,2}[ \t]*', '', input_str.strip())
    

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;
}