The xmlenc library is a fast stream-based XML output library for Java. Main design goals are performance, simplicitity and pureness. As far as known, xmlenc is the fastest XML output library for Java.


The following code uses xmlenc to print a minimal XHTML document:

import java.io.OutputStreamWriter;
import org.znerd.xmlenc.*;
public class Tester {
   public static void main(String[] args) throws Exception {
      XMLOutputter outputter = new XMLOutputter(new OutputStreamWriter(System.out), "US-ASCII");
      outputter.pcdata("Example document");
      outputter.endTag(); // title
      outputter.endTag(); // head
      outputter.pcdata("Example document");
      outputter.endDocument(); // closes all tags and flushes the stream

To test, save the code in a file called Tester.java and then run the following command to compile the Java code:

javac -classpath xmlenc-0.52.jar Tester.java

Then to execute it, run the following command:

java -classpath xmlenc-0.52.jar:. Tester

Note: On Windows platforms, you need to replace the colon (:) with a semi-colon (;).

Quick start

To get started quickly, download the JAR file, put it in your CLASSPATH and write your code using the API documentation as a guide.

Building xmlenc

The xmlenc library can be built as follows:

  • Have Apache Ant (1.4 or later) installed.
  • Download the TAR GZ distribution file.
  • Run ant jar to build the JAR file.

Hint: Run ant -projecthelp for an overview of all available build targets.