Here you can find the source of setAttribute(Node node, String attr, String value)
Parameter | Description |
---|---|
node | The node |
attr | The name of the attribute to set |
value | The value to assign to the attribute |
public synchronized static void setAttribute(Node node, String attr, String value)
//package com.java2s; import org.w3c.dom.*; public class Main { /**//from w w w. j ava 2s. c om * Sets a named attribute of a Node * @param node The node * @param attr The name of the attribute to set * @param value The value to assign to the attribute */ public synchronized static void setAttribute(Node node, String attr, String value) { if (node == null) throw new IllegalArgumentException("Node argument cannot be null"); if (attr == null) throw new IllegalArgumentException("Node attribute argument cannot be null"); if (value == null) throw new IllegalArgumentException("Node attribute value argument cannot be null"); Node attrN = null; NamedNodeMap map = node.getAttributes(); if (map != null) attrN = map.getNamedItem(attr); if (attrN == null) { attrN = node.getOwnerDocument().createAttribute(attr); map.setNamedItem(attrN); } attrN.setNodeValue(value); } }