Java tutorial
//package com.java2s; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * @param sampleNode */ public static void tTestSetSampleAsReference(Node sampleNode) { Attr attr = sampleNode.getOwnerDocument().createAttribute("ttest"); attr.setNodeValue("reference"); Element e = (Element) sampleNode; e.setAttributeNode(attr); } }