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

voidcreateText(String sValue, Node nParent)
This method creates a new textnode with the passed on value.
if (nParent != null) {
    Document dDoc = nParent.getOwnerDocument();
    Node nTemp = dDoc.createTextNode(sValue);
    nParent.appendChild(nTemp);
ElementcreateTextElement(Element parent, String tagName, String text)
create Text Element
Document doc = parent.getOwnerDocument();
Element e = createElement(parent, tagName);
if (text == null) {
    text = "";
e.appendChild(doc.createTextNode(text));
return e;
ElementcreateTextElement2(Element parent, String tagName, String text)
Creates a DOM text element
Document doc = parent.getOwnerDocument();
Element e = doc.createElement(tagName);
e.appendChild(doc.createTextNode(text));
parent.appendChild(e);
return e;
ElementfindElementElseCreateAndAttribute(Document document, Element parent, String element, String attributeName, String attributeValue)
find Element Else Create And Attribute
NodeList nl = parent.getElementsByTagName(element);
Element e = null;
if (nl.getLength() == 0) {
    parent.appendChild(document.createElement(element));
    e = (Element) parent.getElementsByTagName(element).item(0);
    e.setAttribute(attributeName, attributeValue);
return e;
...
ElementfindElementElseCreateAndSetAndAttribute(Document document, Element parent, String element, String value, String attributeName, String attributeValue)
find Element Else Create And Set And Attribute
Element e = findElementElseCreateAndAttribute(document, parent, element, attributeName, attributeValue);
if (e != null)
    e.appendChild(document.createTextNode(value));
return e;