create XML Tag from tag and tag value - Android XML

Android examples for XML:XML Tag

Description

create XML Tag from tag and tag value

Demo Code



public class Main{
    public static void main(String[] argv) throws Exception{
        String parTag = "java2s.com";
        String parValue = "java2s.com";
        System.out.println(createTag(parTag,parValue));
    }//  w  w  w  . jav  a  2 s . co m
    public static String createTag(String parTag, String parValue) {
        return createTag(0, parTag, parValue);
    }
    public static String createTag(int parIndent, String parTag,
            String parValue) {
        return String.format("%s<%2$s>%3$s</%2$s>\n", indent(parIndent),
                parTag, (parValue != null ? parValue : ""));
    }
    private static String indent(int parIndent) {
        StringBuilder indentBuilder = new StringBuilder();
        for (int i = 0; i < (parIndent * Settings.getTabSize()); i++) {
            indentBuilder.append(" ");
        }
        return indentBuilder.toString();
    }
}

Related Tutorials