Java tutorial
//package com.java2s; import java.util.Map; public class Main { public static final String TAG_START = "<"; public static final String TAG_END = ">"; public static String getElementTagWithAttributes(String elementName, Map<String, String> attributes) { if (notEmptyStr(elementName) && attributes != null) { StringBuffer buffer = new StringBuffer(); buffer.append(TAG_START).append(elementName); for (String key : attributes.keySet()) { buffer.append(" ").append(key).append("=").append("\"").append(attributes.get(key)).append("\""); } return buffer.append("/").append(TAG_END).toString(); } return null; } public static boolean notEmptyStr(String value) { if (value != null && !"".equals(value)) { return true; } return false; } }