Java examples for XML:XML String
Appends an end XML tag to the given StringBuffer .
/******************************************************************************* * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany * Technical University Darmstadt, Germany * Chalmers University of Technology, Sweden * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*ww w .ja v a2 s . c o m*/ * Technical University Darmstadt - initial API and implementation and/or initial documentation *******************************************************************************/ import java.util.Map; import java.util.Map.Entry; public class Main{ public static void main(String[] argv) throws Exception{ int level = 2; String tagName = "java2s.com"; StringBuffer sb = new StringBuffer(); appendEndTag(level,tagName,sb); } /** * The used leading white space in each level. */ public static final String LEADING_WHITE_SPACE_PER_LEVEL = " "; /** * Appends an end tag to the given {@link StringBuffer}. * @param level The level. * @param tagName The tag name. * @param sb The {@link StringBuffer} to append to. */ public static void appendEndTag(int level, String tagName, StringBuffer sb) { appendWhiteSpace(level, sb); sb.append("</"); sb.append(tagName); sb.append(">"); appendNewLine(sb); } /** * Adds leading white space to the {@link StringBuffer}. * @param level The level in the tree used for leading white space (formating). * @param sb The {@link StringBuffer} to write to. */ public static void appendWhiteSpace(int level, StringBuffer sb) { for (int i = 0; i < level; i++) { sb.append(LEADING_WHITE_SPACE_PER_LEVEL); } } /** * Adds a line break to the given {@link StringBuffer}. * @param sb The {@link StringBuffer} to write to. */ public static void appendNewLine(StringBuffer sb) { sb.append(StringUtil.NEW_LINE); } }