Java XML Attribute Get getAttribute(Node targetElem, String keyName, String defaultValue)

Here you can find the source of getAttribute(Node targetElem, String keyName, String defaultValue)

Description

get Attribute

License

Open Source License

Declaration

public static String getAttribute(Node targetElem, String keyName,
            String defaultValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Bruno Medeiros and other Contributors.
 * 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://from ww  w  .  j ava  2  s.com
 *     Bruno Medeiros - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Node;

public class Main {
    public static String getAttribute(Node targetElem, String keyName,
            String defaultValue) {
        Node attribute = targetElem.getAttributes().getNamedItem(keyName);
        if (attribute == null) {
            return defaultValue;
        }
        return attribute.getTextContent();
    }
}

Related

  1. getAttribute(Node node, String name)
  2. getAttribute(Node node, String name, String defVal)
  3. getAttribute(Node node, String name, String defVal)
  4. getAttribute(Node pNode, String attrName)
  5. getAttribute(Node pNode, String pName)
  6. getAttribute(String aAttrName, Node aNode)
  7. getAttribute(String attribute, Node node)
  8. getAttribute(String attribute, Node node)
  9. getAttribute(String attribute, Node node)