Here you can find the source of addAttribute(final Node node, final Attr attribute)
public static final void addAttribute(final Node node, final Attr attribute)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Attr; import org.w3c.dom.Node; public class Main { public static final void addAttribute(final Node node, final Attr attribute) { if (node != null) { node.getAttributes().setNamedItem(attribute); }/*from w ww. ja v a 2 s . c o m*/ } public static final void addAttribute(final Node node, final String name, final Attr attribute) { if (node != null) { final String nodeName = node.getNodeName(); if (nodeName != null && nodeName.equals(name)) { node.getAttributes().setNamedItem(attribute); } } } }