Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; import java.util.Map; public class Main { public static void createAttribute(Document doc, String nodeName, Map<String, String> map) { Node node = doc.getElementsByTagName(nodeName).item(0); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; for (Map.Entry<String, String> entry : map.entrySet()) { element.setAttribute(entry.getKey(), entry.getValue()); } //TransformerFactory factory = TransformerFactory.newInstance(); //Transformer former = factory.newTransformer(); //former.transform(new DOMSource(doc), new StreamResult(new File("src/shuiguo.xml"))); } } }