|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.util.xml.io.DOMDocumentWriter
A class for writing DOM documents to writers as XML text.
If the DOMDocumentWriter is created using a java.io.OutputStreamWriter, its encoding will be used in the XML declaration.
If a java.io.Writer that does not extend java.io.OutputStreamWriter is used, then UTF-8 encoding will be used.
Note that if you use a java.io.FileWriter, the default platform encoding
will be used. On a US Windows machine this will likely be ISO-8859-1
or Windows Latin-1 (the default encoding is specified in the System property
file.encoding
). This may not be desirable for interoperability
with Systems from other locales. As such you may want to explicitly
specify an alternative encoding. Here are some examples of how to control
the encoding.
FileOutputStream fos = new FileOutputStream(new File("foo.xml")); OutputStreamWriter w = new OutputStreamWriter(fos, "SJIS"); DOMDocumentWriter writer = new DOMDocumentWriter(w); writer.write(doc); writer.close();
If you create a DOMDocumentWriter with an OutputStream, then it will automatically encode the document using UTF-8 encoding. This form of the constructore is
FileOutputStream stream = new FileOutputStream(new File("foo.xml")); DOMDocumentWriter writer = new DOMDocumentWriter(stream); writer.write(doc); writer.close();
Field Summary | |
private static String |
CLASSNAME
|
private String |
cummulativeIndentString
|
private String |
dtdPublicId_
|
private String |
dtdSystemId_
|
private String |
encoding
|
private String |
indentString
|
private static String |
LINE_SEPARATOR
|
private static String |
RESOURCE
|
private Writer |
writer
|
Constructor Summary | |
DOMDocumentWriter(OutputStream stream)
Create and instance to write the document to the specified stream in UTF-8 encoding. |
|
DOMDocumentWriter(Writer writer)
Create instance to write documents to the specified Writer. |
Method Summary | |
void |
close()
Close the wrappered writer. |
private void |
descend(Node node,
boolean perform_indent)
For a specified node, increase the indent depth, then iterate over each child. |
void |
flush()
Flush work written to the wrappered writer. |
private void |
indent()
|
private String |
normalize(String s)
Normalizes the string. |
private void |
printIndent()
|
void |
setIndentString(String indent_string)
Set the string that will be used for each indent level. |
private Attr[] |
sortAttributes(NamedNodeMap attrs)
Sorts the attributes alphabetically. |
private void |
unindent()
|
void |
write(CDATASection cdata)
Write a CDATA node to the writer like <![CDATA[...]]>. |
void |
write(Comment comment)
Write a comment in the format . |
void |
write(Document document)
Write a document to the writer including the <?xml version=...?> tag. |
void |
write(DocumentFragment document_fragment)
Write a DocumentFragment node to the writer. |
void |
write(Document document,
String system_id)
Write a document to the writer including the <?xml version=...?> tag. |
void |
write(Document document,
String public_id,
String system_id)
Write a document to the writer including the <?xml version=...?> tag. |
void |
write(DocumentType document_type)
Write a DOCTYPE node to the writer. |
void |
write(Element element)
Write an element, its attrbutes, and its children to the writer. |
void |
write(Entity entity)
Write an Entity node to the writer. |
void |
write(EntityReference entity_reference)
Write an entity reference to the writer (e.g. |
void |
write(Node node)
Write any type of node to the wrappered writer. |
void |
write(Notation notation)
Write a Notation node to the writer. |
void |
write(ProcessingInstruction processing_instruction)
Write a processing instruction to the writer (e.g. |
void |
write(Text text)
Write a text node as escaped text to the writer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final String RESOURCE
private static final String CLASSNAME
private Writer writer
private String encoding
private String cummulativeIndentString
private String indentString
private String dtdPublicId_
private String dtdSystemId_
private static final String LINE_SEPARATOR
Constructor Detail |
public DOMDocumentWriter(Writer writer)
writer
- A writer to write to. Because it is an OutputStreamWriter, the document writer can ask it for its character encoding and include in in the <?xml ... tag of the written document. May not be null. If it is, an IllegalArgumentException will be issued.public DOMDocumentWriter(OutputStream stream) throws UnsupportedEncodingException
stream
-
UnsupportedEncodingException
Method Detail |
public void setIndentString(String indent_string)
indent_string
- May not be null. If it is, an IllegalArgumentException will be issued.public void write(Node node) throws IOException
node
- The node to write. Must not be null. If it is an IllegalArgumentException will be issued.
IOException
public void write(CDATASection cdata) throws IOException
cdata
- The CDATA section to be written.
IOException
public void write(Comment comment) throws IOException
comment
- The comment node to render.
IOException
public void write(Document document) throws IOException
document
- The Document to be written.
IOException
public void write(Document document, String system_id) throws IOException
document
- system_id
-
IOException
public void write(Document document, String public_id, String system_id) throws IOException
document
- public_id
- system_id
-
IOException
public void write(Element element) throws IOException
element
- The Element to be written.
IOException
public void write(EntityReference entity_reference) throws IOException
entity_reference
- The EntityReference to be written.
IOException
public void write(ProcessingInstruction processing_instruction) throws IOException
processing_instruction
- The ProcessingInstruction to be written.
IOException
public void write(Text text) throws IOException
text
- The Text node to be written.
IOException
public void write(DocumentType document_type) throws IOException
document_type
- The DocumentType node to be written.
IOException
public void write(Entity entity) throws IOException
entity
- The Entity node to be written.
IOException
public void write(Notation notation) throws IOException
notation
- The Notation node to be written.
IOException
public void write(DocumentFragment document_fragment) throws IOException
document_fragment
- The DocumentFragment node to be written.
IOException
public void flush() throws IOException
IOException
public void close() throws IOException
IOException
private void descend(Node node, boolean perform_indent) throws IOException
node
- The node to write out after indentation.perform_indent
- Whether or not to apply the indent. If false, no indentation will be done.
IOException
private void indent()
private void unindent()
private String normalize(String s)
s
-
private Attr[] sortAttributes(NamedNodeMap attrs)
attrs
-
private void printIndent() throws IOException
IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |