public class

XmlGenerator

extends Object
implements ElementVisitor WireFormatGenerator
java.lang.Object
   ↳ com.google.gdata.wireformats.XmlGenerator

Class Overview

XML generator that outputs a tree of Element objects using the XML wire format.

Summary

Nested Classes
interface XmlGenerator.ElementGenerator The ElementGenerator interface is implemented by helper classes that will generate the start element, text content, and end element syntax for an Element to an XmlWriter
class XmlGenerator.XmlElementGenerator The XmlElementGenerator class provides the default implementation of the interface
Fields
private static final XmlGenerator.ElementGenerator DEFAULT_GENERATOR
private static final XmlNamespace USE_ROOT_ELEMENT_NAMESPACE A namespace marker that means we should use the root element namespace as the default namespace.
private final XmlNamespace defaultNamespace The default namespace to use for this generator.
protected final ElementMetadata<?, ?> rootMetadata Metadata for the root element
protected final XmlWriter xw XML writer used by this generator.
Public Constructors
XmlGenerator(StreamProperties props, Writer w, Charset cs, boolean prettyPrint)
Creates a new xml generator for generating xml output.
XmlGenerator(StreamProperties props, Writer w, Charset cs, boolean prettyPrint, XmlNamespace defaultNamespace)
Creates a new xml generator for generating xml output, using the given namespace as the default namespace.
Public Methods
void generate(Element element, ElementMetadata<?, ?> metadata)
void generate(Element element)
Generate wire content for tree rooted at root.
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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.gdata.model.ElementVisitor
From interface com.google.gdata.wireformats.WireFormatGenerator

Fields

private static final XmlGenerator.ElementGenerator DEFAULT_GENERATOR

private static final XmlNamespace USE_ROOT_ELEMENT_NAMESPACE

A namespace marker that means we should use the root element namespace as the default namespace. This can be overridden by calling #XmlGenerator(OutputProperties, Writer, Charset, boolean, XmlNamespace) and giving it a different namespace.

private final XmlNamespace defaultNamespace

The default namespace to use for this generator.

protected final ElementMetadata<?, ?> rootMetadata

Metadata for the root element

protected final XmlWriter xw

XML writer used by this generator.

Public Constructors

public XmlGenerator (StreamProperties props, Writer w, Charset cs, boolean prettyPrint)

Creates a new xml generator for generating xml output. This constructor will use the namespace of the root element as the default namespace of the output. Callers that would like to change the default namespace should call #XmlGenerator(OutputProperties, Writer, Charset, boolean, XmlNamespace) with the namespace that should be used as the default.

Parameters
props
w
cs
prettyPrint

public XmlGenerator (StreamProperties props, Writer w, Charset cs, boolean prettyPrint, XmlNamespace defaultNamespace)

Creates a new xml generator for generating xml output, using the given namespace as the default namespace.

Parameters
props
w
cs
prettyPrint
defaultNamespace

Public Methods

public void generate (Element element, ElementMetadata<?, ?> metadata)

Parameters
element
metadata
Throws
IOException

public void generate (Element element)

Generate wire content for tree rooted at root.

Parameters
element Root of tree
Throws
IOException

public 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.

Parameters
parent The parent of the target element
e The target element being visited
metadata The metadata for the target element
Returns
  • boolean value indicating whether child elements (if any) should be visited.

public 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.

Parameters
parent The parent of the target element
e The visited element
metadata The metadata for the target element