Here you can find the source of addElementAndAttributes(Node parent, String name, String[] atts)
public static Node addElementAndAttributes(Node parent, String name, String[] atts)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static Node addElementAndAttributes(Node parent, String name, String[] atts) { Node n = addElement(parent, name); for (int i = 0; i < atts.length; i += 2) addAttribute(n, atts[i], atts[i + 1]); return n; }// ww w . j a v a 2 s . c om public static Element addElement(Node parent, String name) { Element node; if (parent.getOwnerDocument() != null) node = parent.getOwnerDocument().createElement(name); else if (parent instanceof Document) node = ((Document) parent).createElement(name); else return null; parent.appendChild(node); return node; } public static Attr addAttribute(Node parent, String name, String value) { if (value == null) return null; Attr node = parent.getOwnerDocument().createAttribute(name); try { node.setValue(value); parent.getAttributes().setNamedItem(node); } catch (Exception e) { System.out.println("Problem rewriting " + parent.getNodeName() + "." + name + "='" + node.getValue() + "' -> '" + value + "'"); } return node; } }