Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; public class Main { public static void setAttribute(Node node, String key, String value) { Node attributeNode = node.getOwnerDocument().createAttribute(key); attributeNode.setNodeValue(value); node.getAttributes().setNamedItem(attributeNode); } }