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

voidaddNewElementWithAttribute(Document xmlDoc, Node node, String elementName, String elementValue, String attrName, String attrValue)
add New Element With Attribute
Node newVal = xmlDoc.createElement(elementName);
Node newValText = xmlDoc.createTextNode(elementValue);
newVal.appendChild(newValText);
addAttribute(xmlDoc, newVal, attrName, attrValue);
node.appendChild(newVal);
ElementcreateChildElement(Document doc, Element parent, String name, String textValue, String[] attributeNames, String[] attributeValues)
This method is used to create an element with Attributes.
Element newElem = doc.createElement(name);
if (textValue != null) {
    newElem.appendChild(doc.createTextNode(textValue));
for (int i = 0; i < attributeNames.length; i++) {
    newElem.setAttribute(attributeNames[i], attributeValues[i]);
parent.appendChild(newElem);
...
NodecreateChildInternal(Document document, Node parent, String nodeName, String... attr_name_and_value)
create Child Internal
Element newNode = document.createElement(nodeName);
for (int i = 0; i < attr_name_and_value.length; i += 2) {
    String attrName = attr_name_and_value[i];
    String attrValue = attr_name_and_value[i + 1];
    newNode.setAttribute(attrName, attrValue);
parent.appendChild(newNode);
return newNode;
...
CommentcreateComment(Element parent, String str)
Creates a DOM comment
Document doc = parent.getOwnerDocument();
Comment c = doc.createComment(str);
parent.appendChild(c);
return c;
ElementcreateElement(Document d, String name, String value)
create Element
Element e = d.createElement(name);
e.appendChild(d.createTextNode(value));
return e;
ElementcreateElement(Document d, String name, String value, boolean isCDATA)
Creates a DOM element node with the given name and contents.
Element e = createElement(d, name);
if (isCDATA)
    e.appendChild(createCDATA(d, value));
else
    e.appendChild(createText(d, value));
return e;
ElementcreateElement(Document d, String tagName)
create Element
Element e = d.createElement(tagName);
return e;
ElementcreateElement(Document doc, Node parent, int depth, String name, String contents)
Creates an element in the specified document, the created element has a single text node child with the specified contents.
Element result = createElement(doc, parent, depth, name);
createText(doc, result, contents);
return result;
ElementcreateElement(Document doc, Node parent, String tagName)
create Element
Element e = doc.createElement(tagName);
parent.appendChild(e);
return e;
ElementcreateElement(Document doc, String elementNamespace, String elementName)
create Element
Element element = doc.createElementNS(elementNamespace, elementName);
return element;