add Integer Property to XML Element - Android XML

Android examples for XML:XML Element

Description

add Integer Property to XML Element

Demo Code


//package com.java2s;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Main {
    public static final String PROPERTY_NODE = "property";
    public static final String NAME_ATTR = "name";
    public static final String INTEGER_ATTR = "intvalue";

    public static void addIntegerProperty(Document document,
            Element parent, String name, int value) {
        addPropertyNode(document, parent, name).setAttribute(INTEGER_ATTR,
                Integer.toString(value));
    }/*  www  . j  a va  2 s.c om*/

    private static Element addPropertyNode(Document document,
            Element parent, String name) {
        Element element = document.createElement(PROPERTY_NODE);
        parent.appendChild(element);
        element.setAttribute(NAME_ATTR, name);
        return element;
    }
}

Related Tutorials