public final class XmlWriter extends Object implements IXmlWriter
Lightweight IXmlWriter
implementation.
Requires a wrapper to be used safely in a multithreaded environment.
Not intended to be subclassed. Please copy and hack!
Constructor and Description |
---|
XmlWriter(Writer writer)
Constructs an XmlWriter with the specified writer for output.
|
Modifier and Type | Method and Description |
---|---|
IXmlWriter |
attribute(CharSequence name,
CharSequence value)
Writes an attribute of an element.
|
IXmlWriter |
cdata(CharSequence content)
Writes CDATA content.
|
void |
close() |
IXmlWriter |
closeDocument()
Closes all pending elements.
|
IXmlWriter |
closeElement()
Closes the last element written.
|
IXmlWriter |
comment(CharSequence text)
Writes a comment
|
IXmlWriter |
content(CharSequence content)
Writes content.
|
IXmlWriter |
openElement(CharSequence elementName)
Writes the start of an element.
|
IXmlWriter |
startDocument()
Starts a document by writing a prolog.
|
public XmlWriter(Writer writer)
writer
- the writer to write to.public IXmlWriter startDocument() throws IOException
startDocument
in interface IXmlWriter
OperationNotAllowedException
- if called after the first element has
been written or once a prolog has already been writtenIOException
public IXmlWriter openElement(CharSequence elementName) throws IOException
openElement
in interface IXmlWriter
elementName
- the name of the element, not nullInvalidXmlException
- if the name is not valid for an xml elementOperationNotAllowedException
- if called after the first element has
been closedIOException
public IXmlWriter comment(CharSequence text) throws IOException
IXmlWriter
comment
in interface IXmlWriter
text
- the comment textOperationNotAllowedException
- if called after the first element has been closedIOException
public IXmlWriter attribute(CharSequence name, CharSequence value) throws IOException
openElement(CharSequence)
or attribute(java.lang.CharSequence, java.lang.CharSequence)
.attribute
in interface IXmlWriter
name
- the attribute name, not nullvalue
- the attribute value, not nullInvalidXmlException
- if the name is not valid for an xml attribute or
if a value for the attribute has already been writtenOperationNotAllowedException
- if called after
content(CharSequence)
or closeElement()
or before any call
to openElement(CharSequence)
IOException
public IXmlWriter content(CharSequence content) throws IOException
IXmlWriter
content
in interface IXmlWriter
content
- the content to writeOperationNotAllowedException
- if called before any call to IXmlWriter.openElement(java.lang.CharSequence)
or after the first element has been closedIOException
public IXmlWriter cdata(CharSequence content) throws IOException
IXmlWriter
]]>
cdata
in interface IXmlWriter
content
- the content to writeOperationNotAllowedException
- if called before any call to IXmlWriter.openElement(java.lang.CharSequence)
or after the first element has been closedIOException
public IXmlWriter closeElement() throws IOException
closeElement
in interface IXmlWriter
OperationNotAllowedException
- if called before any call to
openElement(java.lang.CharSequence)
or after the first element has been closedIOException
public IXmlWriter closeDocument() throws IOException
closeDocument
in interface IXmlWriter
OperationNotAllowedException
- if called before any call to
openElement(java.lang.CharSequence)
IOException
public void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 2006–2024 Apache Software Foundation. All rights reserved.