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

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

Description

get Atrribute Value

License

LGPL

Declaration

public static String getAtrributeValue(Node node, String attribute) 

Method Source Code

//package com.java2s;
/*/*  w  w  w  .  j  a  v  a2  s.c  om*/
 * JFox - The most lightweight Java EE Application Server!
 * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
 *
 * JFox is licenced and re-distributable under GNU LGPL.
 */

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import org.w3c.dom.Text;

public class Main {
    public static String getAtrributeValue(Node node, String attribute) {
        Node _node = node.getAttributes().getNamedItem(attribute);
        return getNodeValue(_node);
    }

    public static String getNodeValue(Node node) {
        if (node == null) {
            return null;
        } else if (node instanceof Text) {
            return node.getNodeValue().trim();
        } else if (node instanceof Element) {
            node.normalize();
            Node temp = node.getFirstChild();
            if (temp != null && (temp instanceof Text))
                return temp.getNodeValue().trim();
            else
                return "";
        } else {
            return node.getNodeValue().trim();
        }
    }
}

Related

  1. getAttr(Element e, String name)
  2. getAttr(Element elem, String name)
  3. getAttr(final Node n, final String attr)
  4. getAttr(final Node n, final String attrName)