XmlBuilder is a tool for declarative construction of XML.
It was originally created to generate XML for unit tests, but is useful
wherever you want to construct XML documents with minimal code and a
low memory footprint.
The two classes of interest are {@link net.sf.practicalxml.builder.ElementNode} and {@link net.sf.practicalxml.builder.XmlBuilder}: the former contains public methods for transforming a tree into various representations, while the latter contains static methods for building such a tree:
import static net.sf.practicalxml.builder.XmlBuilder.*;
// ...
ElementNode root =
element("root",
element("child1",
text("this is some <text>")),
element("child2",
attribute("foo", "bar"),
attribute("baz", "biff")),
element("http::www.example.com/foo", "ns:child3"));
Document dom = root.toDOM();
String out = root.toString();