Java XML Attribute Add addAttribute(Node parent, String name, String value)

Here you can find the source of addAttribute(Node parent, String name, String value)

Description

add Attribute

License

Open Source License

Declaration

public static Attr addAttribute(Node parent, String name, String value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Attr;

import org.w3c.dom.Node;

public class Main {
    public static Attr addAttribute(Node parent, String name, String value) {
        if (value == null)
            return null;
        Attr node = parent.getOwnerDocument().createAttribute(name);
        try {// ww  w . ja  v  a 2  s.com
            node.setValue(value);
            parent.getAttributes().setNamedItem(node);
        } catch (Exception e) {
            System.out.println("Problem rewriting " + parent.getNodeName() + "." + name + "='" + node.getValue()
                    + "' -> '" + value + "'");
        }
        return node;
    }
}

Related

  1. addAttribute(final AttributesImpl attributes, final String localName, final Object value)
  2. addAttribute(final Document doc, final Element parent, final String name, final String value)
  3. addAttribute(final Element element, final String attributeName, final String value)
  4. addAttribute(final Node e, final String name, final String value)
  5. addAttribute(final Node node, final Attr attribute)
  6. addAttribute(Node pNode, String attrName, String attrValue)
  7. addAttributes(Element element, String[][] attributes)
  8. addAttributeToXPathExpression(Node nodeAttr, String xpathExpression, String and)
  9. addDomAttr(Document doc, String tagName, String tagNamespaceURI, String attrName, String attrValue)