Java XML Attribute Add addAttribute(final Document doc, final Element parent, final String name, final String value)

Here you can find the source of addAttribute(final Document doc, final Element parent, final String name, final String value)

Description

Adds an attribute to the specified document element.

License

Open Source License

Parameter

Parameter Description
doc the document.
parent the parent element.
name the attribute name.
value the attribute value.

Return

the attribute.

Declaration

public static Attr addAttribute(final Document doc, final Element parent, final String name,
        final String value) 

Method Source Code

//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;
    }
}

Related

  1. addAttribute(Document document, String AttribName, String attribValue, Element element)
  2. addAttribute(Document xmlDoc, Node node, String attrName, String attrValue)
  3. addAttribute(Element el, String name, String val)
  4. addAttribute(Element elem, String name, String value)
  5. addAttribute(final AttributesImpl attributes, final String localName, final Object value)
  6. addAttribute(final Element element, final String attributeName, final String value)
  7. addAttribute(final Node e, final String name, final String value)
  8. addAttribute(final Node node, final Attr attribute)
  9. addAttribute(Node parent, String name, String value)