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

ElementcreateElementNS(String namespaceURI, String qualifiedName, String text, Document doc)
create Element NS
if (namespaceURI == null)
    return createElement(qualifiedName, text, doc);
else {
    Element elem = doc.createElementNS(namespaceURI, qualifiedName);
    if ((text != null) && !text.equals(""))
        elem.appendChild(doc.createTextNode(text));
    return elem;
ElementcreateElementNsIn(Element parent, String ns, String name, String textContent)
create Element Ns In
Element el = parent.getOwnerDocument().createElementNS(ns, name);
parent.appendChild(el);
el.setTextContent(textContent);
return el;
ElementcreateElementWithText(Element parent, String name, String value)
helper method, creates a subelement with text embedded.
Document doc = parent.getOwnerDocument();
Element newElement = doc.createElement(name);
parent.appendChild(newElement);
newElement.appendChild(doc.createTextNode(value));
return newElement;
ElementcreateElmWithText(Document doc, String tagName, String text)
create Elm With Text
Element elm = doc.createElement(tagName);
text = text != null ? text.trim() : "";
Node node = (text.indexOf('<') >= 0 || text.indexOf('\n') >= 0) ? doc.createCDATASection(text)
        : doc.createTextNode(text);
elm.appendChild(node);
return elm;
ElementcreateNewElementAndSetAndAttribute(Document document, Element parent, String childElement, String childValue, String attributeName, String attributeValue)
create New Element And Set And Attribute
Element child = createNewElementAndSet(document, parent, childElement, childValue);
child.setAttribute(attributeName, attributeValue);
return child;
ElementcreateNode(Document doc, Element parent, String nodeName, Object[] attr)
Create a new node with parent element
Element elem = doc.createElement(nodeName);
for (int i = 0; i < attr.length; i += 2) {
    elem.setAttribute(attr[i].toString(), attr[i + 1].toString());
parent.appendChild(elem);
return elem;
ElementcreateNode(Document doc, Element parent, String nodeName, Object[] attr)
Create a new node with parent element
Element elem = doc.createElement(nodeName);
for (int i = 0; i < attr.length; i += 2) {
    elem.setAttribute(attr[i].toString(), attr[i + 1].toString());
parent.appendChild(elem);
return elem;
ElementcreateTable(Element theParent)
create Table
Element aElem = theParent.getOwnerDocument().createElement("table");
aElem.setAttribute("border", "0");
aElem.setAttribute("cellspacing", "0");
aElem.setAttribute("cellpadding", "0");
theParent.appendChild(aElem);
return aElem;
TextcreateText(final Node parent, final String text)
Creates the text.
final Text child = parent.getOwnerDocument().createTextNode(text);
parent.appendChild(child);
return child;
ElementcreateText(Node parent, String tag, String text)
create Text
Element e = createElement(parent, tag);
Node t = parent.getOwnerDocument().createTextNode(text);
e.appendChild(t);
return e;