Java XML Attribute Get getAttributeValue(Node node, String name, boolean defaultValue)

Here you can find the source of getAttributeValue(Node node, String name, boolean defaultValue)

Description

get Attribute Value

License

Open Source License

Declaration

public static boolean getAttributeValue(Node node, String name, boolean defaultValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 GoPivotal, Inc./*from   w  ww .  ja v a2s.c o  m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     GoPivotal, Inc. - initial API and implementation
 *******************************************************************************/

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

public class Main {
    public static String getAttributeValue(Node node, String attribName) {
        NamedNodeMap attribs = node.getAttributes();
        if (attribs != null) {
            Node value = attribs.getNamedItem(attribName);
            if (value != null) {
                short nodeType = value.getNodeType();
                if (nodeType == Node.ATTRIBUTE_NODE) {
                    return value.getNodeValue();
                }
            }
        }
        return null;
    }

    public static boolean getAttributeValue(Node node, String name, boolean defaultValue) {
        String str = getAttributeValue(node, name);
        if (str == null) {
            return defaultValue;
        } else {
            return "true".equals(str);
        }
    }
}

Related

  1. getAttributeValue(Node node, String attrName)
  2. getAttributeValue(Node node, String attrName)
  3. getAttributeValue(Node node, String name)
  4. getAttributeValue(Node node, String name)
  5. getAttributeValue(Node node, String name)
  6. getAttributeValue(Node node, String name, String defaultValue)
  7. getAttributeValue(Node sNode, String attribName)
  8. getAttributeValue(Node sNode, String attribName)
  9. getAttributeValue(NodeList elements, String attributeName)