add String Property to XML Element - Java XML

Java examples for XML:XML Element Value

Description

add String 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 STRING_ATTR = "stringvalue";

    public static void addStringProperty(Document document, Element parent,
            String name, String value) {
        addPropertyNode(document, parent, name).setAttribute(STRING_ATTR,
                value);//from   ww w .  j  a  v  a 2s . c  o  m
    }

    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