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 getElementStartTagWithAttributes(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()) { String value = attributes.get(key); if (value == null) { value = ""; } buffer.append(" ").append(key).append("=").append("\"").append(value).append("\""); } return buffer.append(TAG_END).toString(); } return null; } public static boolean notEmptyStr(String value) { if (value != null && !"".equals(value)) { return true; } return false; } }