Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Set node's attribute. * * @param node * the node * @param attributeName * the attribute name * @param value * the value */ public static void setNodeAttributeValue(Node node, String attributeName, String value) { if (null == node) { // Do Nothing return; } NamedNodeMap attributes = node.getAttributes(); if (null == attributes) { // Do Nothing return; } Node n = attributes.getNamedItem(attributeName); if (null == n) { // Do Nothing return; } n.setNodeValue(value); } }