Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Map; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /** * create an element from a document, that has some text content in it * @param doc - document * @param name - element name * @param content - text content * @return element object */ public static Element createElement(Document doc, String name, String content) { Element e = doc.createElement(name); e.appendChild(doc.createTextNode(content)); return e; } /** * create an element from a document, that has some text content in it * @param doc - document * @param name - element name * @param attribute - attribute * @param value - value * @return element object */ public static Element createElement(Document doc, String name, String attribute, String value) { Element e = doc.createElement(name); e.setAttribute(attribute, value); return e; } /** * create an element from a document, that has some text content in it * @param doc - document * @param name - element name * @param attributes - attribute map * @return element object */ public static Element createElement(Document doc, String name, Map<String, String> attributes) { Element e = doc.createElement(name); for (String attribute : attributes.keySet()) e.setAttribute(attribute, attributes.get(attribute)); return e; } /** * create an element from a document, that has some text content in it * @param doc - document * @param name - element name * @param attributes - attribute map * @param content - string content * @return element object */ public static Element createElement(Document doc, String name, Map<String, String> attributes, String content) { Element e = createElement(doc, name, attributes); e.appendChild(doc.createTextNode(content)); return e; } }