Here you can find the source of createElement(Document doc, String name, Map
Parameter | Description |
---|---|
doc | - document |
name | - element name |
attributes | - attribute map |
public static Element createElement(Document doc, String name, Map<String, String> attributes)
//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 { /**//from w ww .j a v a 2 s .co m * 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; } }