Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { /** * Adds the attribute to the given node * @param doc * @param node * @param attrName * @param attrValue */ public static void addAttr(Document doc, Node node, String attrName, Object attrValue) { Node attr = doc.createAttribute(attrName); attr.setNodeValue(attrValue.toString()); node.getAttributes().setNamedItem(attr); } }