Java XML Attribute Create createAttribute(Document doc, String nodeName, Map map)

Here you can find the source of createAttribute(Document doc, String nodeName, Map map)

Description

create Attribute

License

Apache License

Declaration

public static void createAttribute(Document doc, String nodeName, Map<String, String> map) 

Method Source Code


//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());
            }/*from   w w  w.j  a  v a2s  . co m*/
            //TransformerFactory factory = TransformerFactory.newInstance();
            //Transformer former = factory.newTransformer();
            //former.transform(new DOMSource(doc), new StreamResult(new File("src/shuiguo.xml")));
        }
    }
}

Related

  1. createAttr(Element parent, String name, Object value)
  2. createAttr(String attrName, String attrValue, Document document)
  3. createAttribute(Document doc, String friendlyName, String samlNS, String samlPrefix, QName attrKey)
  4. createAttribute(Document document, String name, String value)
  5. createAttribute(String sName, String sValue, Node nParent)
  6. createAttributeTable(Element e)
  7. createFillAttributeGraphics(Document d, boolean showColor, boolean showGradientColor, boolean showGradientRotation, boolean showImage)