codeblockutil
Class XMLStringWriter

java.lang.Object
  extended by codeblockutil.XMLStringWriter

public class XMLStringWriter
extends java.lang.Object

XMLStringWriter is a very simple and naive writer to create XML Strings that are nicely formatted. It's not very smart, so you need to be careful how you use addDataElement, beginElement, endAttribute, endElement. See the doc for these methods as you use them.


Constructor Summary
XMLStringWriter()
          Constructs a new XMLStringWriter with a default indentation length of 4.
XMLStringWriter(int indent)
          Constructs a new XMLStringWriter that formats elements and attributes appened to this writer instance.
 
Method Summary
 void addAttribute(java.lang.String key, java.lang.String value)
          Adds an attributes to the current active Element
 void addDataElement(java.lang.String ele, java.lang.String text)
          Adding an element like this assumes that there are no attributes to be added to this element
 void addElementTextData(java.lang.String data)
          Adds the specified data to the current XML string.
 void appendXMLWriterString(XMLStringWriter writer)
          Appends the string constructed by the specified writer to this.
 void beginElement(java.lang.String ele, boolean hasAttributes)
          Adding an element like this or beginning an element tree.
 void beginXMLString(java.lang.String root)
          Begings this XML String.
 void endAttributes()
          Ends the attributes for the currently active Element
 void endElement(java.lang.String ele)
          Ends the specified element
 void endXMLString()
          Ends this XML String.
static void main(java.lang.String[] args)
           
 java.lang.String toString()
          Returns XML String representation of what was appended/written on this
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLStringWriter

public XMLStringWriter(int indent)
Constructs a new XMLStringWriter that formats elements and attributes appened to this writer instance.

Parameters:
indent - the size of the indent for this writer

XMLStringWriter

public XMLStringWriter()
Constructs a new XMLStringWriter with a default indentation length of 4.

Method Detail

appendXMLWriterString

public void appendXMLWriterString(XMLStringWriter writer)
Appends the string constructed by the specified writer to this.

Parameters:
writer - the desired XMLStringWriter to append to this

beginXMLString

public void beginXMLString(java.lang.String root)
Begings this XML String. Must call this first.

Parameters:
root -

endXMLString

public void endXMLString()
Ends this XML String. Must call this last.


addDataElement

public void addDataElement(java.lang.String ele,
                           java.lang.String text)
Adding an element like this assumes that there are no attributes to be added to this element

Parameters:
ele -
text -

beginElement

public void beginElement(java.lang.String ele,
                         boolean hasAttributes)
Adding an element like this or beginning an element tree. If hasAttriutes is true, must call endAttributes when you're done adding all attributes In order to add elements, you must call endAttributes().

Parameters:
ele -

addElementTextData

public void addElementTextData(java.lang.String data)
Adds the specified data to the current XML string. This data should be added between a begin and end Element tag

Parameters:
data - String data to append to the current XML String

addAttribute

public void addAttribute(java.lang.String key,
                         java.lang.String value)
Adds an attributes to the current active Element

Parameters:
key -
value -

endAttributes

public void endAttributes()
Ends the attributes for the currently active Element


endElement

public void endElement(java.lang.String ele)
Ends the specified element

Parameters:
ele - String of element

toString

public java.lang.String toString()
Returns XML String representation of what was appended/written on this

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)