Java XML Attribute Get getAttribute(Node node, String attribute)

Here you can find the source of getAttribute(Node node, String attribute)

Description

Returns null if the attribute doesn't exist, otherwise returns the attribute.

License

Apache License

Parameter

Parameter Description
node a parameter
attribute a parameter

Declaration

public static String getAttribute(Node node, String attribute) 

Method Source Code


//package com.java2s;
/*//from   ww w . j  a  v  a 2s  . co  m
 * Copyright 2009-2016 DigitalGlobe, Inc.
 *
 * 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.*;

public class Main {
    /**
     * Returns null if the attribute doesn't exist, otherwise returns the attribute.
     * @param node
     * @param attribute
     * @return
     */
    public static String getAttribute(Node node, String attribute) {
        Node attributeNode = node.getAttributes().getNamedItem(attribute);

        if (attributeNode == null) {
            return null;
        }
        return node.getNodeValue();
    }
}

Related

  1. getAttribute(Node node, String attr)
  2. getAttribute(Node node, String attr)
  3. getAttribute(Node node, String attr)
  4. getAttribute(Node node, String attr)
  5. getAttribute(Node node, String attribName)
  6. getAttribute(Node node, String attributeName)
  7. getAttribute(Node node, String attributeName)
  8. getAttribute(Node node, String attributeName)
  9. getAttribute(Node node, String attributeName)