Java XML Attribute Add addAttribute(Document xmlDoc, Node node, String attrName, String attrValue)

Here you can find the source of addAttribute(Document xmlDoc, Node node, String attrName, String attrValue)

Description

add Attribute

License

Apache License

Declaration

public static void addAttribute(Document xmlDoc, Node node, String attrName, String attrValue) 

Method Source Code

//package com.java2s;
/*// ww  w.  ja v a 2s .  c  o m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.w3c.dom.Attr;
import org.w3c.dom.Document;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    public static void addAttribute(Document xmlDoc, Node node, String attrName, String attrValue) {
        Attr newAtt = xmlDoc.createAttribute(attrName);
        newAtt.setNodeValue(attrValue);
        NamedNodeMap attrs = node.getAttributes();
        attrs.setNamedItem(newAtt);
    }

    public static void addAttribute(Node node, String attrName, String attrValue) {
        Document xmlDoc = node.getOwnerDocument();
        addAttribute(xmlDoc, node, attrName, attrValue);
    }
}

Related

  1. addAttribute(Document doc, org.w3c.dom.Element e, String index, String value)
  2. addAttribute(Document doc, String name, Element e, String value)
  3. addAttribute(Document document, Node node, String attName, String attValue)
  4. addAttribute(Document document, Node node, String name, String value)
  5. addAttribute(Document document, String AttribName, String attribValue, Element element)
  6. addAttribute(Element el, String name, String val)
  7. addAttribute(Element elem, String name, String value)
  8. addAttribute(final AttributesImpl attributes, final String localName, final Object value)
  9. addAttribute(final Document doc, final Element parent, final String name, final String value)