de.zeigermann.xml

Class XMLStringWriter


public class XMLStringWriter
extends XMLWriter

This is a convenience class for writing XML to a string. As no IOExceptions will occur this class catches them for you doing nothing. Call toString() to finally get your string. As constructor for XMLWriter already needs writer call create() to get your objects instead of consructor.
Author:
Olli Z.

Field Summary

Fields inherited from class de.zeigermann.xml.XMLWriter

NEWLINE, NO_NEWLINE, depth, indent, nlAfterEmptyTag, nlAfterEndTag, nlAfterStartTag, prettyPrintMode, tabWidth, xmlDeclWritten

Method Summary

static XMLStringWriter
create()
Creates a new XMLStringWriter objects.
String
toString()
Gets the string representation of your written XML.
void
writeCData(String cData)
Writes character data with encoding.
void
writeComment(String comment)
Writes comment encoded as comment.
void
writeElementWithCData(String startTag, String cData, String endTag)
Writes a full element consisting of a start tag, character data and an end tag.
void
writeElementWithPCData(String startTag, String pcData, String endTag)
Writes a full element consisting of a start tag, character data and an end tag.
void
writeEmptyElement(String emptyTag)
Writes an empty element.
void
writeEmptyElement(String emptyTag, boolean nl)
Writes an empty element.
void
writeEndTag(String endTag)
Writes an end tag.
void
writeEndTag(String endTag, boolean nl)
Writes an end tag.
void
writeNl()
Writes a single newline.
void
writePCData(String pcData)
Writes character data without encoding.
void
writePI(String target, String data)
Writes a processing instruction.
void
writeProlog(String prolog)
Writes prolog data like doctype delcaration and DTD parts followed by a newline.
void
writeStartTag(String startTag)
Writes a start tag.
void
writeStartTag(String startTag, boolean nl)
Writes a start tag.
void
writeXMLDeclaration()
Writes XML declaration.

Methods inherited from class de.zeigermann.xml.XMLWriter

createEmptyTag, createEmptyTag, createEmptyTag, createEmptyTag, createEmptyTag, createEndTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, generateAndWriteElementWithCData, generateAndWriteElementWithCData, getNlAfterEmptyTag, getNlAfterEndTag, getNlAfterStartTag, getPrettyPrintMode, getTabWidth, isXMLDeclarationWritten, setNlAfterEmptyTag, setNlAfterEndTag, setNlAfterStartTag, setPrettyPrintMode, setTabWidth, setXMLDeclarationWritten, writeCData, writeComment, writeElementWithCData, writeElementWithPCData, writeEmptyElement, writeEmptyElement, writeEndTag, writeEndTag, writeNl, writePCData, writePI, writeProlog, writeStartTag, writeStartTag, writeXMLDeclaration

Method Details

create

public static XMLStringWriter create()
Creates a new XMLStringWriter objects.

toString

public String toString()
Gets the string representation of your written XML.

writeCData

public void writeCData(String cData)
Writes character data with encoding.
Overrides:
writeCData in interface XMLWriter
Parameters:
cData - the character data to write

writeComment

public void writeComment(String comment)
Writes comment encoded as comment.
Overrides:
writeComment in interface XMLWriter

writeElementWithCData

public void writeElementWithCData(String startTag,
                                  String cData,
                                  String endTag)
Writes a full element consisting of a start tag, character data and an end tag. There will be no newline after start tag, so character data is literally preserved.
The character data will be encoded.
Overrides:
writeElementWithCData in interface XMLWriter
Parameters:
startTag - the complete start tag, e.g. <element>
cData - the character data to write
endTag - the complete end tag, e.g. </element>

writeElementWithPCData

public void writeElementWithPCData(String startTag,
                                   String pcData,
                                   String endTag)
Writes a full element consisting of a start tag, character data and an end tag. There will be no newline after start tag, so character data is literally preserved.
The character data will not be encoded.
Overrides:
writeElementWithPCData in interface XMLWriter
Parameters:
startTag - the complete start tag, e.g. <element>
pcData - the parseable character data to write
endTag - the complete end tag, e.g. </element>

writeEmptyElement

public void writeEmptyElement(String emptyTag)
Writes an empty element.
Overrides:
writeEmptyElement in interface XMLWriter
Parameters:
emptyTag - the complete tag for an empty element, e.g. <start/>

writeEmptyElement

public void writeEmptyElement(String emptyTag,
                              boolean nl)
Writes an empty element.
Overrides:
writeEmptyElement in interface XMLWriter
Parameters:
emptyTag - the complete tag for an empty element, e.g. <empty/>
nl - decides whether there should be a newline after the tag

writeEndTag

public void writeEndTag(String endTag)
Writes an end tag.
Overrides:
writeEndTag in interface XMLWriter
Parameters:
endTag - the complete end tag, e.g. </end>

writeEndTag

public void writeEndTag(String endTag,
                        boolean nl)
Writes an end tag.
Overrides:
writeEndTag in interface XMLWriter
Parameters:
endTag - the complete end tag, e.g. </end>
nl - decides whether there should be a newline after the tag

writeNl

public void writeNl()
Writes a single newline.
Overrides:
writeNl in interface XMLWriter

writePCData

public void writePCData(String pcData)
Writes character data without encoding.
Overrides:
writePCData in interface XMLWriter
Parameters:
pcData - the parseable character data to write

writePI

public void writePI(String target,
                    String data)
Writes a processing instruction.
Overrides:
writePI in interface XMLWriter

writeProlog

public void writeProlog(String prolog)
Writes prolog data like doctype delcaration and DTD parts followed by a newline.
Do not misuse this to write plain text, but rather - if you really have to - use the standard XMLWriter methods.
Overrides:
writeProlog in interface XMLWriter

writeStartTag

public void writeStartTag(String startTag)
Writes a start tag.
Overrides:
writeStartTag in interface XMLWriter
Parameters:
startTag - the complete start tag, e.g. <start>

writeStartTag

public void writeStartTag(String startTag,
                          boolean nl)
Writes a start tag.
Overrides:
writeStartTag in interface XMLWriter
Parameters:
startTag - the complete start tag, e.g. <start>
nl - decides whether there should be a newline after the tag

writeXMLDeclaration

public void writeXMLDeclaration()
Overrides:
writeXMLDeclaration in interface XMLWriter

Copyright © 2002-2004 Oliver Zeigermann. All Rights Reserved.