Here you can find the source of setAttribute(String name, String value, Element el)
public static void setAttribute(String name, String value, Element el)
//package com.java2s; import org.w3c.dom.*; public class Main { /**/*from w w w . j a v a 2 s . com*/ * Sets the value of the given DOM element's attribute * with the specified name to the given value. */ public static void setAttribute(String name, String value, Element el) { if (name == null || value == null || el == null) return; // strip out invalid characters from the value char[] v = value.toCharArray(); int count = 0; for (int i = 0; i < v.length; i++) { if (!Character.isISOControl(v[i])) count++; } if (count < v.length) { char[] nv = new char[count]; count = 0; for (int i = 0; i < v.length; i++) { if (!Character.isISOControl(v[i])) nv[count++] = v[i]; } value = new String(nv); } el.setAttribute(name, value); } /** * Sets the value of the given DOM element's attribute with the * specified name to the given value's string representation. */ public static void setAttribute(String name, Object value, Element el) { setAttribute(name, value == null ? null : value.toString(), el); } }