create XML Tag from a Map - Android XML

Android examples for XML:XML Tag

Description

create XML Tag from a Map

Demo Code


//package com.java2s;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static String createTag(String tagName,
            Map<String, String> properties) {
        StringBuilder builder = new StringBuilder(1024); // 1 kb be default

        builder.append('<');
        builder.append(tagName);/*from   www  . j av  a2  s. c  om*/

        // output each property
        for (Entry<String, String> entry : properties.entrySet()) {
            builder.append(' ');
            builder.append(entry.getKey());
            builder.append("=\"");
            builder.append(entry.getValue());
            builder.append('"');
        }

        // close the tag
        builder.append(" />");

        return builder.toString();
    }
}

Related Tutorials