Java Utililty Methods XML Element Text Set

List of utility methods to do XML Element Text Set

Description

The list of methods to do XML Element Text Set are organized into topic(s).

Method

voidsetElementTextByAttr(Element modsroot, String nodename, String attrname, String attrvalue, String newValue)
Sets text of element by attribute value (e.g.
NodeList list = modsroot.getElementsByTagName(nodename);
for (int i = 0; i < list.getLength(); i++) {
    Node node = (Node) list.item(i);
    NamedNodeMap attrs = node.getAttributes();
    Attr attr = (Attr) attrs.getNamedItem(attrname);
    if (attr != null) {
        if (attr.getValue().equals(attrvalue)) {
            setTextValue(node, newValue);
...
voidsetElementTextValue(Element e, String text)
set Element Text Value
setElementTextValue(e, text, false);
voidsetElementValue(Element element, String val)
Set the value of element
Node node = element.getOwnerDocument().createTextNode(val);
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    Node nd = nl.item(i);
    if (nd.getNodeType() == Node.TEXT_NODE) {
        nd.setNodeValue(val);
        return;
element.appendChild(node);
voidsetElementValue(Element element, String value)
Appends the specified value as a text node to the element.
Node child = element.getFirstChild();
if (value != null) {
    if (child == null) {
        child = element.getOwnerDocument().createTextNode("");
        element.appendChild(child);
    child.setNodeValue(value);
} else {
...