Java XML Attribute Set setAttribute(Node pNode, String attrName)

Here you can find the source of setAttribute(Node pNode, String attrName)

Description

set Attribute

License

Apache License

Declaration

public static boolean setAttribute(Node pNode, String attrName) 

Method Source Code

//package com.java2s;
/**//from  w w w . j  a  v  a2 s  . c  o  m
 * Copyright 2010 
 *
 * 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.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {

    public static boolean setAttribute(Node pNode, String attrName) {
        NamedNodeMap name = pNode.getAttributes();
        if (name.getLength() > 0) {
            Node thenode = name.getNamedItem(attrName);
            if (thenode != null) {
                thenode.setNodeValue(attrName);
                return true;
            } else {
                return false;
            }
        }
        return false;
    }
}

Related

  1. setAttribute(final Element element, final String name, final String value)
  2. setAttribute(Node n, String name, String value)
  3. setAttribute(Node node, String attName, String val)
  4. setAttribute(Node node, String attr, String value)
  5. setAttribute(Node node, String key, String value)
  6. setAttribute(String name, String value, Element el)
  7. setAttributeNS(Element node, String namespaceURI, String prefix, String nodeName, String value)
  8. setAttributeValue(Element element, String attribute, String value)
  9. setAttributeValue(final Element target, final String attributeName, final String value)