Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { public static void addAttribute(Document document, Node parent, String attrName, String value) { Attr attr = document.createAttribute(attrName); attr.setValue(value); NamedNodeMap map = parent.getAttributes(); map.setNamedItem(attr); } }