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(Element parent, String tagName)
Creates a DOM element
Document doc = parent.getOwnerDocument();
Element e = doc.createElement(tagName);
parent.appendChild(e);
return e;
ElementcreateElement(Element parent, String tagName, String value)
create an child element with the specified name and value and append it in a parent element
Document doc = parent.getOwnerDocument();
Element child = doc.createElement(tagName);
setElementValue(child, value);
parent.appendChild(child);
return child;
ElementcreateElement(final Document document, final String elementName)
create Element
final String prefix = getPrefixOfQName(elementName);
final String namespaceURI = prefix.isEmpty() ? null : document.lookupNamespaceURI(prefix);
final Element element;
if (namespaceURI == null) {
    element = document.createElement(elementName);
} else {
    element = document.createElementNS(namespaceURI, elementName);
return element;
ElementcreateElement(final Document parentDocument, final String name)
create Element
return parentDocument.createElement(name);
ElementcreateElement(Node element, String name)
create Element
return element.getOwnerDocument().createElement(name);
ElementcreateElement(Node node, String name)
create Element
return node.getOwnerDocument().createElement(name);
ElementcreateElement(Node parent, String tag)
create Element
Document doc = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument();
Element e = doc.createElement(tag);
parent.appendChild(e);
return e;
ElementcreateElement(QName key)
create Element
return createDocument().createElementNS(key.getNamespaceURI(), key.getPrefix() + ":" + key.getLocalPart());
ElementcreateElement(QName qName)
Creates a new Element having the specified qualified name.
Document doc = null;
try {
    doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
    throw new RuntimeException(e);
Element elem = doc.createElementNS(qName.getNamespaceURI(), qName.getLocalPart());
return elem;
...
ElementcreateElement(String name, Object value, Document doc)
create Element
Element element = doc.createElement(name);
element.appendChild(doc.createTextNode(value.toString()));
return element;