Create Xml Tag String from field name and field value - Android XML

Android examples for XML:XML String

Description

Create Xml Tag String from field name and field value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String fieldName = "java2s.com";
        String fieldValue = "java2s.com";
        System.out.println(toXml(fieldName, fieldValue));
    }/* www .  ja v a  2 s . co m*/

    public static String toXml(String fieldName, String fieldValue) {
        StringBuffer xmlBuf = new StringBuffer();
        xmlBuf.append(startTag(fieldName));
        xmlBuf.append(fieldValue);
        xmlBuf.append(endTag(fieldName));
        return xmlBuf.toString();
    }

    public static String startTag(String tagData) {
        return "<" + tagData + ">";
    }

    public static String endTag(String tagData) {
        return "</" + tagData + ">";
    }
}

Related Tutorials