Here you can find the source of addAttribute(final Document doc, final Element parent, final String name, final String value)
Parameter | Description |
---|---|
doc | the document. |
parent | the parent element. |
name | the attribute name. |
value | the attribute value. |
public static Attr addAttribute(final Document doc, final Element parent, final String name, final String value)
//package com.java2s; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /**//w w w.j a va 2s . c o m * Adds an attribute to the specified document element. * @param doc the document. * @param parent the parent element. * @param name the attribute name. * @param value the attribute value. * @return the attribute. */ public static Attr addAttribute(final Document doc, final Element parent, final String name, final String value) { Attr attr = doc.createAttribute(name); attr.setNodeValue(value); parent.setAttributeNode(attr); return attr; } }