Java XML Attribute Set setAttributeValue(Node sNode, String attribName, String val)

Here you can find the source of setAttributeValue(Node sNode, String attribName, String val)

Description

Utility method to set the attribute value on the given element node

License

Open Source License

Parameter

Parameter Description
sNode a parameter
attribName a parameter
val a parameter

Declaration

public static void setAttributeValue(Node sNode, String attribName,
        String val) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    /**//from w ww.  ja v a  2s .  c om
     * Utility method to set the attribute value on the given
     * element node
     *
     * @param sNode
     * @param attribName
     * @param val
     */
    public static void setAttributeValue(Node sNode, String attribName,
            String val) {

        Node attr = sNode.getAttributes().getNamedItem(attribName);
        if (attr != null) {
            attr.setNodeValue(val);
        } else {
            attr = sNode.getOwnerDocument().createAttribute(attribName);
            attr.setNodeValue(val);
            sNode.getAttributes().setNamedItem(attr);
        }
    }
}

Related

  1. setAttributeNS(Element node, String namespaceURI, String prefix, String nodeName, String value)
  2. setAttributeValue(Element element, String attribute, String value)
  3. setAttributeValue(final Element target, final String attributeName, final String value)
  4. setAttributeValue(Node node, String attName, String attValue)
  5. setAttributeValue(Node node, String attribute, String value)
  6. setPropertyIfAttributePresent( BeanDefinitionBuilder builder, Element element, String attributeName)
  7. setPropertyReference(BeanDefinitionBuilder builder, Element element, String attribute, String property)