org.apache.commons.xmlio.out
Class XMLStringWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.FilterWriter
          extended by org.apache.commons.xmlio.out.XMLWriter
              extended by org.apache.commons.xmlio.out.XMLStringWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

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.


Field Summary
 
Fields inherited from class org.apache.commons.xmlio.out.XMLWriter
depth, indent, NEWLINE, nlAfterEmptyTag, nlAfterEndTag, nlAfterStartTag, NO_NEWLINE, prettyPrintMode, tabWidth, xmlDeclWritten
 
Fields inherited from class java.io.FilterWriter
out
 
Fields inherited from class java.io.Writer
lock
 
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 org.apache.commons.xmlio.out.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
 
Methods inherited from class java.io.FilterWriter
close, flush, write, write, write
 
Methods inherited from class java.io.Writer
append, append, append, append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

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


toString

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

Overrides:
toString in class Object

writeXMLDeclaration

public void writeXMLDeclaration()
Description copied from class: XMLWriter
Writes XML declaration. XML declaration will be written using version 1.0 and no encoding defaulting to standard encoding (supports UTF-8 and UTF-16):
<?xml version="1.0"?>
If you want to have a different encoding or the standalone declaration use XMLWriter.writeProlog(String).
This sets xmlDeclWritten to true.

Overrides:
writeXMLDeclaration in class XMLWriter

writeProlog

public void writeProlog(String prolog)
Description copied from class: XMLWriter
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 FilterWriter.write(int) methods.

Overrides:
writeProlog in class XMLWriter

writeNl

public void writeNl()
Description copied from class: XMLWriter
Writes a single newline.

Overrides:
writeNl in class XMLWriter

writeComment

public void writeComment(String comment)
Description copied from class: XMLWriter
Writes comment encoded as comment.

Overrides:
writeComment in class XMLWriter

writePI

public void writePI(String target,
                    String data)
Description copied from class: XMLWriter
Writes a processing instruction.

Overrides:
writePI in class XMLWriter

writeStartTag

public void writeStartTag(String startTag,
                          boolean nl)
Description copied from class: XMLWriter
Writes a start tag.

Overrides:
writeStartTag in class XMLWriter
Parameters:
startTag - the complete start tag, e.g. <start>
nl - decides whether there should be a newline after the tag

writeStartTag

public void writeStartTag(String startTag)
Description copied from class: XMLWriter
Writes a start tag.

Overrides:
writeStartTag in class XMLWriter
Parameters:
startTag - the complete start tag, e.g. <start>
See Also:
XMLWriter.setNlAfterStartTag(boolean)

writeEndTag

public void writeEndTag(String endTag,
                        boolean nl)
Description copied from class: XMLWriter
Writes an end tag.

Overrides:
writeEndTag in class XMLWriter
Parameters:
endTag - the complete end tag, e.g. </end>
nl - decides whether there should be a newline after the tag

writeEndTag

public void writeEndTag(String endTag)
Description copied from class: XMLWriter
Writes an end tag.

Overrides:
writeEndTag in class XMLWriter
Parameters:
endTag - the complete end tag, e.g. </end>
See Also:
XMLWriter.setNlAfterEndTag(boolean)

writeEmptyElement

public void writeEmptyElement(String emptyTag,
                              boolean nl)
Description copied from class: XMLWriter
Writes an empty element.

Overrides:
writeEmptyElement in class XMLWriter
Parameters:
emptyTag - the complete tag for an empty element, e.g. <empty/>
nl - decides whether there should be a newline after the tag

writeEmptyElement

public void writeEmptyElement(String emptyTag)
Description copied from class: XMLWriter
Writes an empty element.

Overrides:
writeEmptyElement in class XMLWriter
Parameters:
emptyTag - the complete tag for an empty element, e.g. <start/>
See Also:
XMLWriter.setNlAfterEmptyTag(boolean)

writeCData

public void writeCData(String cData)
Description copied from class: XMLWriter
Writes character data with encoding.

Overrides:
writeCData in class XMLWriter
Parameters:
cData - the character data to write

writePCData

public void writePCData(String pcData)
Description copied from class: XMLWriter
Writes character data without encoding.

Overrides:
writePCData in class XMLWriter
Parameters:
pcData - the parseable character data to write

writeElementWithCData

public void writeElementWithCData(String startTag,
                                  String cData,
                                  String endTag)
Description copied from class: XMLWriter
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 class 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)
Description copied from class: XMLWriter
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 class 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>


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.