Java Utililty Methods XML Element Create

List of utility methods to do XML Element Create

Description

The list of methods to do XML Element Create are organized into topic(s).

Method

ElementcreateElement(Document document, String name, Map attributes, Element... children)
create Element
Element element = document.createElement(name);
for (Map.Entry<String, String> attribute : attributes.entrySet())
    element.setAttribute(attribute.getKey(), attribute.getValue());
for (Element child : children)
    element.appendChild(child);
return element;
ElementcreateElement(Document document, String name, String textContent)
create Element
Element element = document.createElement(name);
element.setTextContent(textContent);
return element;
ElementcreateElement(Document dom, String elementName, Properties attributes)
create Element
Element element = dom.createElementNS("", elementName); 
if (attributes != null) {
    Enumeration e = attributes.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        element.setAttribute(key, attributes.getProperty(key));
return element;
ElementcreateElement(Document dom, String elementName, Properties attributes)
create Element
Element element = dom.createElementNS("", elementName); 
if (attributes != null) {
    Enumeration e = attributes.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        element.setAttribute(key, attributes.getProperty(key));
return element;
ElementcreateElement(Document owner, String nsURI, String elementName, String textValue)
Creates an Element object in the CyberSource namespace.
Attr attr = owner.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns");
attr.setValue(nsURI);
Element elem = owner.createElementNS(nsURI, elementName);
elem.setAttributeNodeNS(attr);
elem.appendChild(owner.createTextNode(textValue));
return (elem);
ElementcreateElement(Element parent, String elementName)
create Element
Element el = parent.getOwnerDocument().createElement(elementName);
parent.appendChild(el);
return el;
ElementcreateElement(Element parent, String name)
helper method, creates a subelement, does not format result.
Document doc = parent.getOwnerDocument();
Element newElement = doc.createElement(name);
parent.appendChild(newElement);
return newElement;
ElementcreateElement(Element parent, String name)
Add a new element to the given parent
Document document;
Element element;
document = parent.getOwnerDocument();
element = document.createElement(name);
parent.appendChild(element);
return element;
ElementcreateElement(Element parent, String path)
create Element
int i = path.indexOf('.');
Element element = null;
if (i < 0) {
    element = parent.getOwnerDocument().createElement(path);
    parent.appendChild(element);
} else {
    String p = path.substring(0, i), c = path.substring(i + 1);
    Element pe = getUniqueChild(parent, p);
...
ElementcreateElement(Element parent, String tagName)
create Element
Element tag = parent.getOwnerDocument().createElement(tagName);
parent.appendChild(tag);
return tag;