public class XmlGenerator extends java.lang.Object implements WireFormatGenerator, ElementVisitor
Element
objects
using the XML wire format.Modifier and Type | Class and Description |
---|---|
static interface |
XmlGenerator.ElementGenerator
|
static class |
XmlGenerator.XmlElementGenerator
The XmlElementGenerator class provides the default implementation of the
interface . |
ElementVisitor.StoppedException
Modifier and Type | Field and Description |
---|---|
protected ElementMetadata<?,?> |
rootMetadata
Metadata for the root element
|
protected XmlWriter |
xw
XML writer used by this generator.
|
Constructor and Description |
---|
XmlGenerator(StreamProperties props,
java.io.Writer w,
java.nio.charset.Charset cs,
boolean prettyPrint)
Creates a new xml generator for generating xml output.
|
XmlGenerator(StreamProperties props,
java.io.Writer w,
java.nio.charset.Charset cs,
boolean prettyPrint,
XmlNamespace defaultNamespace)
Creates a new xml generator for generating xml output, using the
given namespace as the default namespace.
|
Modifier and Type | Method and Description |
---|---|
void |
generate(Element element)
Generate wire content for tree rooted at
root . |
void |
generate(Element element,
ElementMetadata<?,?> metadata) |
boolean |
visit(Element parent,
Element e,
ElementMetadata<?,?> metadata)
Called during Element tree traversal to allow the visitor instance
to process an element in the tree.
|
void |
visitComplete(Element parent,
Element e,
ElementMetadata<?,?> metadata)
The visitComplete method is called when traversal for an Element
and all of its nested children has been completed.
|
protected final ElementMetadata<?,?> rootMetadata
protected final XmlWriter xw
public XmlGenerator(StreamProperties props, java.io.Writer w, java.nio.charset.Charset cs, boolean prettyPrint)
#XmlGenerator(OutputProperties, Writer, Charset, boolean, XmlNamespace)
with the namespace that should be used as the default.public XmlGenerator(StreamProperties props, java.io.Writer w, java.nio.charset.Charset cs, boolean prettyPrint, XmlNamespace defaultNamespace)
public void generate(Element element) throws java.io.IOException
WireFormatGenerator
root
.generate
in interface WireFormatGenerator
element
- root of treejava.io.IOException
- if content generation failedpublic void generate(Element element, ElementMetadata<?,?> metadata) throws java.io.IOException
java.io.IOException
public boolean visit(Element parent, Element e, ElementMetadata<?,?> metadata) throws ElementVisitor.StoppedException
ElementVisitor
visit
in interface ElementVisitor
parent
- the parent of the target elemente
- the target element being visitedmetadata
- the metadata for the target elementElementVisitor.StoppedException
- if the data model traversal should be stopped
immediately. This may be the result of an unexpected error, or some
visitor implementations may extend this exception type to signal
specific exit conditions.public void visitComplete(Element parent, Element e, ElementMetadata<?,?> metadata) throws ElementVisitor.StoppedException
ElementVisitor
visitComplete
in interface ElementVisitor
parent
- the parent of the target elemente
- the visited elementmetadata
- the metadata for the target elementElementVisitor.StoppedException
- if the data model traversal should be stopped
immediately. This may be the result of an unexpected error, or some
visitor implementations may extend this exception type to signal
specific exit conditions.