Package org.znerd.xmlenc

The xmlenc library, version 0.33.

See:
          Description

Interface Summary
StatefulXMLEventListener Stateful XMLEventListener.
XMLEventListener Interface for XML event listeners.
XMLEventListenerStates All XMLEventListenerStates.
XMLOutputterStates Deprecated. Deprecated since xmlenc 0.31.
 

Class Summary
Library Class that represents this xmlenc library.
XMLEventListenerState State for an XML event listener.
XMLOutputter Stream-based XML outputter.
 

Package org.znerd.xmlenc Description

The xmlenc library, version 0.33.

Light-weight XML output library for Java. It fills the gap between a light-weight parser like SAX, and a heavy-weight XML output library, like JDOM.

Example

The example below shows how xmlenc is typically used. The output to be generated is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en">
<head><title>Example document</title></head><body class="SummaryPage">
<h1>Example document</h1></body></html>

This XML document can be produced using the specified code:

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.znerd.xmlenc.XMLOutputter;

public class Main {

   public final static void main(String[] args) throws IOException {

      final String encoding = "iso-8859-1";
      Writer writer = new OutputStreamWriter(System.out, encoding);
      XMLOutputter outputter = new XMLOutputter(writer, encoding);
      outputter.declaration();
      outputter.whitespace("\n");
      outputter.dtd("html",
                    "-//W3C//DTD XHTML 1.0 Transitional//EN",
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
      outputter.whitespace("\n\n");
      outputter.startTag("html");
      outputter.attribute("lang", "en");
      outputter.whitespace("\n");
      outputter.startTag("head");
      outputter.startTag("title");
      outputter.pcdata("Example document");
      outputter.endTag(); // title
      outputter.endTag(); // head

      outputter.startTag("body");
      outputter.attribute("class", "SummaryPage");

      outputter.whitespace("\n");
      outputter.startTag("h1");
      outputter.pcdata("Example document");

      outputter.endDocument(); // closes: h1, body and html
      outputter.getWriter().flush();
   }
}

Since:
xmlenc 0.1


Copyright © Ernst de Haan
See http://xmlenc.sourceforge.net/.