Java tutorial
//package com.java2s; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static void addAttribute(Document doc, Element element, String name, String value) { Attr attr = doc.createAttribute(name); attr.setValue(value); element.setAttributeNode(attr); } }