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 doc, String expr, Element parentElement, String elementName, boolean firstChild, Map attributes)
Generic API to update or create DOM elements
if (doc == null) {
    throw new IllegalArgumentException(INVALID_ARG);
} else {
    XPath xPath = XPathFactory.newInstance().newXPath();
    Element element = null;
    if (expr != null)
        element = (Element) xPath.evaluate(expr, doc, XPathConstants.NODE);
    if (element == null) {
...
ElementcreateElement(Document doc, String name, Map attributes)
create an element from a document, that has some text content in it
Element e = doc.createElement(name);
for (String attribute : attributes.keySet())
    e.setAttribute(attribute, attributes.get(attribute));
return e;
ElementcreateElement(Document doc, String name, Object text, Map attributes)
Convenience function for creating elements.
Element e = doc.createElement(name);
if (attributes != null) {
    for (Entry<String, Object> entry : attributes.entrySet()) {
        e.setAttribute(entry.getKey(), entry.getValue().toString());
if (text != null)
    e.appendChild(createTextNode(doc, text.toString()));
...
ElementcreateElement(Document doc, String name, String prefix, String namespaceURI)
Creates an element on the given document.
if (prefix != null)
    name = prefix + ":" + name;
return doc.createElementNS(namespaceURI, name);
ElementcreateElement(Document doc, String tag, String data)
Creates a new element
Element receiverEmail = doc.createElement(tag);
if (data != null) {
    Text receiverEmailText = doc.createTextNode(data);
    receiverEmail.appendChild(receiverEmailText);
return receiverEmail;
ElementcreateElement(Document doc, String tag, String nsURI, String prefix)
create Element
String qName = prefix == null ? tag : prefix + ":" + tag;
return doc.createElementNS(nsURI, qName);
ElementcreateElement(Document doc, String tagName)
create Element
return doc.createElementNS(null, tagName);
ElementcreateElement(Document document, Element parent, String name)
Create an element with the specified name and add it as a child of the specified parent.
Element element = document.createElement(name);
parent.appendChild(element);
return element;
ElementcreateElement(Document document, QName name)
create Element
String prefix = name.getPrefix();
String qname = (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart()
        : name.getLocalPart();
return document.createElementNS(name.getNamespaceURI(), qname);
ElementcreateElement(Document document, String name, float value)
create Element
return createElement(document, name, Float.toString(value));