Top Fields Constructors Methods
com.sun.xml.internal.stream.writers

public Class XMLEventWriterImpl

extends Object
implements XMLEventWriter
Class Inheritance
All Implemented Interfaces
javax.xml.stream.XMLEventWriter, javax.xml.stream.util.XMLEventConsumer
Imports
java.util.Iterator, javax.xml.namespace.NamespaceContext, .QName, javax.xml.stream.XMLEventReader, .XMLEventWriter, .XMLStreamException, .XMLStreamWriter, javax.xml.stream.events.Attribute, .Characters, .Comment, .DTD, .EntityReference, .Namespace, .ProcessingInstruction, .StartDocument, .StartElement, .XMLEvent

Author
Neeraj Bajaj, Sun Microsystems.

Field Summary

Modifier and TypeField and Description
private static final boolean
private final XMLStreamWriter

Constructor Summary

AccessConstructor and Description
public
XMLEventWriterImpl(XMLStreamWriter streamWriter)

Constructs an XMLEventWriterImpl that implements the standard XMLStreamWriter interface.

Method Summary

Modifier and TypeMethod and Description
public void
add(XMLEventReader xMLEventReader)

Implements javax.xml.stream.XMLEventWriter.add.

Adds an entire stream to an output stream, calls next() on the inputStream argument until hasNext() returns false This should be treated as a convenience method that will perform the following loop over all the events in an event reader and call add on each event.
public void
add(XMLEvent xMLEvent)

Implements javax.xml.stream.XMLEventWriter.add.

Add an event to the output stream Adding a START_ELEMENT will open a new namespace scope that will be closed when the corresponding END_ELEMENT is written.
public void
close()

Implements javax.xml.stream.XMLEventWriter.close.

Frees any resources associated with this stream
public void
flush()

Implements javax.xml.stream.XMLEventWriter.flush.

Writes any cached events to the underlying output mechanism
public NamespaceContext
getNamespaceContext()

Implements javax.xml.stream.XMLEventWriter.getNamespaceContext.

Returns the current namespace context.
public String

Returns:

prefix associated with the URI.
getPrefix
(String
Namespace URI
namespaceURI
)

Implements javax.xml.stream.XMLEventWriter.getPrefix.

Gets the prefix the uri is bound to
public void
setDefaultNamespace(String
Namespace URI
uri
)

Implements javax.xml.stream.XMLEventWriter.setDefaultNamespace.

Binds a URI to the default namespace This URI is bound in the scope of the current START_ELEMENT / END_ELEMENT pair.
public void
setNamespaceContext(NamespaceContext
Namespace Context
namespaceContext
)

Implements javax.xml.stream.XMLEventWriter.setNamespaceContext.

Sets the current namespace context for prefix and uri bindings.
public void
setPrefix(String
namespace prefix associated with the uri.
prefix
,
String
Namespace URI
uri
)

Implements javax.xml.stream.XMLEventWriter.setPrefix.

Sets the prefix the uri is bound to.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUGback to summary
private static final boolean DEBUG
fStreamWriterback to summary
private final XMLStreamWriter fStreamWriter

Constructor Detail

XMLEventWriterImplback to summary
public XMLEventWriterImpl(XMLStreamWriter streamWriter)

Constructs an XMLEventWriterImpl that implements the standard XMLStreamWriter interface.

Method Detail

addback to summary
public void add(XMLEventReader xMLEventReader) throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.add.

Doc from javax.xml.stream.XMLEventWriter.add.

Adds an entire stream to an output stream, calls next() on the inputStream argument until hasNext() returns false This should be treated as a convenience method that will perform the following loop over all the events in an event reader and call add on each event.

Exceptions
XMLStreamException:
if an error occurs
addback to summary
public void add(XMLEvent xMLEvent) throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.add.

Doc from javax.xml.stream.XMLEventWriter.add.

Add an event to the output stream Adding a START_ELEMENT will open a new namespace scope that will be closed when the corresponding END_ELEMENT is written.

Required and optional fields for events added to the writer
Event Type Required Fields Optional Fields Required Behavior
START_ELEMENT QName name namespaces , attributes A START_ELEMENT will be written by writing the name, namespaces, and attributes of the event in XML 1.0 valid syntax for START_ELEMENTs. The name is written by looking up the prefix for the namespace uri. The writer can be configured to respect prefixes of QNames. If the writer is respecting prefixes it must use the prefix set on the QName. The default behavior is to lookup the value for the prefix on the EventWriter's internal namespace context. Each attribute (if any) is written using the behavior specified in the attribute section of this table. Each namespace (if any) is written using the behavior specified in the namespace section of this table.
END_ELEMENT Qname name None A well formed END_ELEMENT tag is written. The name is written by looking up the prefix for the namespace uri. The writer can be configured to respect prefixes of QNames. If the writer is respecting prefixes it must use the prefix set on the QName. The default behavior is to lookup the value for the prefix on the EventWriter's internal namespace context. If the END_ELEMENT name does not match the START_ELEMENT name an XMLStreamException is thrown.
ATTRIBUTE QName name , String value QName type An attribute is written using the same algorithm to find the lexical form as used in START_ELEMENT. The default is to use double quotes to wrap attribute values and to escape any double quotes found in the value. The type value is ignored.
NAMESPACE String prefix, String namespaceURI, boolean isDefaultNamespaceDeclaration None A namespace declaration is written. If the namespace is a default namespace declaration (isDefault is true) then xmlns="$namespaceURI" is written and the prefix is optional. If isDefault is false, the prefix must be declared and the writer must prepend xmlns to the prefix and write out a standard prefix declaration.
PROCESSING_INSTRUCTION None String target, String data The data does not need to be present and may be null. Target is required and many not be null. The writer will write data section directly after the target, enclosed in appropriate XML 1.0 syntax
COMMENT None String comment If the comment is present (not null) it is written, otherwise an an empty comment is written
START_DOCUMENT None String encoding , boolean standalone, String version A START_DOCUMENT event is not required to be written to the stream. If present the attributes are written inside the appropriate XML declaration syntax
END_DOCUMENT None None Nothing is written to the output
DTD String DocumentTypeDefinition None The DocumentTypeDefinition is written to the output
Exceptions
XMLStreamException:
if an error occurs
closeback to summary
public void close() throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.close.

Doc from javax.xml.stream.XMLEventWriter.close.

Frees any resources associated with this stream

Exceptions
XMLStreamException:
if an error occurs
flushback to summary
public void flush() throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.flush.

Doc from javax.xml.stream.XMLEventWriter.flush.

Writes any cached events to the underlying output mechanism

Exceptions
XMLStreamException:
will inturn call flush on the stream to which data is being written.
getNamespaceContextback to summary
public NamespaceContext getNamespaceContext()

Implements javax.xml.stream.XMLEventWriter.getNamespaceContext.

Doc from javax.xml.stream.XMLEventWriter.getNamespaceContext.

Returns the current namespace context.

getPrefixback to summary
public String getPrefix(String namespaceURI) throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.getPrefix.

Doc from javax.xml.stream.XMLEventWriter.getPrefix.

Gets the prefix the uri is bound to

Parameters
namespaceURI:String

Namespace URI

Returns:String

prefix associated with the URI.

Exceptions
XMLStreamException:
if an error occurs
setDefaultNamespaceback to summary
public void setDefaultNamespace(String uri) throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.setDefaultNamespace.

Doc from javax.xml.stream.XMLEventWriter.setDefaultNamespace.

Binds a URI to the default namespace This URI is bound in the scope of the current START_ELEMENT / END_ELEMENT pair. If this method is called before a START_ELEMENT has been written the uri is bound in the root scope.

Parameters
uri:String

Namespace URI

Exceptions
XMLStreamException:
if an error occurs
setNamespaceContextback to summary
public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.setNamespaceContext.

Doc from javax.xml.stream.XMLEventWriter.setNamespaceContext.

Sets the current namespace context for prefix and uri bindings. This context becomes the root namespace context for writing and will replace the current root namespace context. Subsequent calls to setPrefix and setDefaultNamespace will bind namespaces using the context passed to the method as the root context for resolving namespaces.

Parameters
namespaceContext:NamespaceContext

Namespace Context

Exceptions
XMLStreamException:
if an error occurs
setPrefixback to summary
public void setPrefix(String prefix, String uri) throws XMLStreamException

Implements javax.xml.stream.XMLEventWriter.setPrefix.

Doc from javax.xml.stream.XMLEventWriter.setPrefix.

Sets the prefix the uri is bound to. This prefix is bound in the scope of the current START_ELEMENT / END_ELEMENT pair. If this method is called before a START_ELEMENT has been written the prefix is bound in the root scope.

Parameters
prefix:String

namespace prefix associated with the uri.

uri:String

Namespace URI

Exceptions
XMLStreamException:
if an error occurs