|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnu.xom.Serializer
nu.xom.samples.SourceCodeSerializer
public class SourceCodeSerializer
This class converts an XML document into XOM source code that creates the same XML document. It's often useful for building self-contained unit tests.
Constructor Summary | |
---|---|
SourceCodeSerializer(java.io.OutputStream out)
|
|
SourceCodeSerializer(java.io.OutputStream out,
java.lang.String encoding)
|
Method Summary | |
---|---|
static void |
main(java.lang.String[] args)
|
protected void |
write(nu.xom.Attribute attribute)
Writes an attribute in the form name="value" . |
protected void |
write(nu.xom.Comment comment)
Writes a comment onto the output stream using the current options. |
protected void |
write(nu.xom.DocType doctype)
Writes a DocType object
onto the output stream using the current options. |
void |
write(nu.xom.Document doc)
Serializes a document onto the output stream using the current options. |
protected void |
write(nu.xom.ProcessingInstruction instruction)
Writes a processing instruction onto the output stream using the current options. |
protected void |
write(nu.xom.Text text)
Writes a Text object
onto the output stream using the current options. |
protected void |
writeAttributes(nu.xom.Element element)
Writes all the attributes of the specified element onto the output stream, one at a time, separated by white space. |
protected void |
writeEmptyElementTag(nu.xom.Element element)
Writes an empty-element tag for the element including all its namespace declarations and attributes. |
protected void |
writeEndTag(nu.xom.Element element)
Writes the end-tag for an element in the form </name> . |
protected void |
writeNamespaceDeclarations(nu.xom.Element element)
Writes all the namespace declaration attributes of the specified element onto the output stream, one at a time, separated by white space. |
protected void |
writeStartTag(nu.xom.Element element)
Writes the start-tag for the element including all its namespace declarations and attributes. |
Methods inherited from class nu.xom.Serializer |
---|
breakLine, flush, getColumnNumber, getEncoding, getIndent, getLineSeparator, getMaxLength, getPreserveBaseURI, getUnicodeNormalizationFormC, setIndent, setLineSeparator, setMaxLength, setOutputStream, setPreserveBaseURI, setUnicodeNormalizationFormC, write, writeAttributeValue, writeChild, writeEscaped, writeNamespaceDeclaration, writeRaw, writeXMLDeclaration |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SourceCodeSerializer(java.io.OutputStream out)
public SourceCodeSerializer(java.io.OutputStream out, java.lang.String encoding) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
Method Detail |
---|
public void write(nu.xom.Document doc) throws java.io.IOException
nu.xom.Serializer
Serializes a document onto the output stream using the current options.
write
in class nu.xom.Serializer
doc
- the Document
to serialize
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void writeStartTag(nu.xom.Element element) throws java.io.IOException
nu.xom.Serializer
Writes the start-tag for the element including all its namespace declarations and attributes.
The writeAttributes
method is called to write
all the non-namespace-declaration attributes.
The writeNamespaceDeclarations
method
is called to write all the namespace declaration attributes.
writeStartTag
in class nu.xom.Serializer
element
- the element whose start-tag is written
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void writeEndTag(nu.xom.Element element) throws java.io.IOException
nu.xom.Serializer
Writes the end-tag for an element in the form
</name>
.
writeEndTag
in class nu.xom.Serializer
element
- the element whose end-tag is written
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void writeEmptyElementTag(nu.xom.Element element) throws java.io.IOException
nu.xom.Serializer
Writes an empty-element tag for the element including all its namespace declarations and attributes.
The writeAttributes
method is called to write
all the non-namespace-declaration attributes.
The writeNamespaceDeclarations
method
is called to write all the namespace declaration attributes.
If subclasses don't wish empty-element tags to be used,
they can override this method to simply invoke
writeStartTag
followed by
writeEndTag
.
writeEmptyElementTag
in class nu.xom.Serializer
element
- the element whose empty-element tag is written
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void writeAttributes(nu.xom.Element element) throws java.io.IOException
nu.xom.Serializer
Writes all the attributes of the specified
element onto the output stream, one at a time, separated
by white space. If preserveBaseURI is true, and it is
necessary to add an xml:base
attribute
to the element in order to preserve the base URI, then
that attribute is also written here.
Each individual attribute is written by invoking
write(Attribute)
.
writeAttributes
in class nu.xom.Serializer
element
- the Element
whose attributes are
written
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void write(nu.xom.Attribute attribute) throws java.io.IOException
nu.xom.Serializer
Writes an attribute in the form
name="value"
.
Characters in the attribute value are escaped as necessary.
write
in class nu.xom.Serializer
attribute
- the Attribute
to write
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void writeNamespaceDeclarations(nu.xom.Element element) throws java.io.IOException
nu.xom.Serializer
Writes all the namespace declaration
attributes of the specified element onto the output stream,
one at a time, separated by white space. Each individual
declaration is written by invoking
writeNamespaceDeclaration
.
writeNamespaceDeclarations
in class nu.xom.Serializer
element
- the Element
whose namespace
declarations are written
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void write(nu.xom.ProcessingInstruction instruction) throws java.io.IOException
nu.xom.Serializer
Writes a processing instruction onto the output stream using the current options. Since character and entity references are not resolved in processing instructions, processing instructions can only be serialized when all characters they contain are available in the current encoding.
write
in class nu.xom.Serializer
instruction
- the ProcessingInstruction
to serialize
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void write(nu.xom.DocType doctype) throws java.io.IOException
nu.xom.Serializer
Writes a DocType
object
onto the output stream using the current options.
write
in class nu.xom.Serializer
doctype
- the document type declaration to serialize
java.io.IOException
- if the underlying
output stream encounters an I/O errorprotected void write(nu.xom.Comment comment) throws java.io.IOException
nu.xom.Serializer
Writes a comment onto the output stream using the current options. Since character and entity references are not resolved in comments, comments can only be serialized when all characters they contain are available in the current encoding.
write
in class nu.xom.Serializer
comment
- the Comment
to serialize
java.io.IOException
- if the underlying output stream
encounters an I/O errorprotected void write(nu.xom.Text text) throws java.io.IOException
nu.xom.Serializer
Writes a Text
object
onto the output stream using the current options.
Reserved characters such as <, > and "
are escaped using the standard entity references
such as <
, >
,
and "
.
Characters which cannot be encoded in the current character set (for example, Ω in ISO-8859-1) are encoded using character references.
write
in class nu.xom.Serializer
text
- the Text
to serialize
java.io.IOException
- if the underlying output stream
encounters an I/O errorpublic static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |