add Boolean Property to XML Document parent Element - Java XML

Java examples for XML:XML Element Value

Description

add Boolean Property to XML Document parent 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 BOOLEAN_ATTR = "booleanvalue";

    public static void addBooleanProperty(Document document,
            Element parent, String name, boolean value) {
        addPropertyNode(document, parent, name).setAttribute(BOOLEAN_ATTR,
                Boolean.toString(value));
    }// w ww  .jav a  2  s  .com

    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