Java tutorial
//package com.java2s; /** * Copyright (C) 2007 Asterios Raptis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Map; public class Main { /** * Creates a tag from the given string values. Can be used for creating html or xml tags. * * @param tagname * the tagname * @param value * the value from the tag. * @param attributtes * a map with the attributtes * @return the string */ public static String newTag(final String tagname, final String value, final Map<String, String> attributtes) { StringBuilder xmlTag = new StringBuilder(); xmlTag.append("<").append(tagname); if (attributtes != null && !attributtes.isEmpty()) { xmlTag.append(" "); int count = 1; for (Map.Entry<String, String> attributte : attributtes.entrySet()) { xmlTag.append(attributte.getKey()); xmlTag.append("="); xmlTag.append("\"").append(attributte.getValue()).append("\""); if (count != attributtes.size()) { xmlTag.append(" "); } count++; } } xmlTag.append(">"); xmlTag.append(value); xmlTag.append("</").append(tagname).append(">"); return xmlTag.toString(); } }