Code example for StringWriter

Methods: appendwrite

0
			//In XML, closing an element can mean either close the start tag or end element 
 
			//When the element needs to end, user must specify if she wants to print a close tag 
 
			if (closeStartTag){
				writer.append(">");
			} 
 
			if (createCloseTag){
 
				if (prettyPrint){
					writeIdentation(true); 
					number_of_spaces_to_use_for_identation.poll();
				} 
 
				writer.append("</");
				writer.append(name);
				writer.append(">");
			} 
		} 
	} 
 
	private void write(char[] ch, int start, int length, boolean attribute){
		for (int i = start; i < start + length; i++) {
			if (ch[i] == '>') {
				writer.write("&gt;");
			} else if (ch[i] == '<') {
				writer.write("&lt;");
			} else if (ch[i] == '&') {
				writer.write("&amp;");
			} else if (attribute && ch[i] == '"') {
				writer.write("&quot;");
			} else if (attribute && ch[i] == '\'') {
				writer.write("&apos;");
			} else { 
				writer.write(ch[i]);
			} 
		} 
	} 
 
	private void writeIdentation(boolean addNewLine) {
 
		if (addNewLine){
			writer.write("\n");
		} 
 
		Integer numberOfSpaces = number_of_spaces_to_use_for_identation.peek();
 
		if (numberOfSpaces == null){
			writer.write(" ");
		} 
		else{ 
			String spaces = String.format("%"+numberOfSpaces+"s", "");
			writer.write(spaces);
		} 
 
	} 
 
	public void writeAttribute(String name, String value){