Java XML Attribute from Node getNodeAttribute(Node node, String name, String def)

Here you can find the source of getNodeAttribute(Node node, String name, String def)

Description

get Node Attribute

License

Open Source License

Declaration

public static String getNodeAttribute(Node node, String name, String def) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

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

public class Main {
    public static String getNodeAttribute(Node node, String name) {
        return getNamedItemNodeValue(node.getAttributes(), name, null);
    }/*from   w w w .  j  a va 2s .com*/

    public static String getNodeAttribute(Node node, String name, String def) {
        return getNamedItemNodeValue(node.getAttributes(), name, def);
    }

    static String getNamedItemNodeValue(NamedNodeMap attributes, String name, String defvalue) {
        Node namenode = attributes.getNamedItem(name);
        if (namenode == null) {
            return defvalue;
        }
        if (namenode.getNodeValue() == null) {
            return defvalue;
        }
        return namenode.getNodeValue();
    }
}

Related

  1. getNodeAttribute(Node node, String attributeName)
  2. getNodeAttribute(Node node, String attributeName, String defaultValue)
  3. getNodeAttribute(Node node, String name)
  4. getNodeAttribute(Node node, String name)
  5. getNodeAttribute(Node node, String name)
  6. getNodeAttribute(Node node, String s)
  7. getNodeAttribute(Node QueryNode, String AttrName)
  8. getNodeAttribute(Node thisNode, String key)
  9. getNodeAttributeAsInt(Node node, String attributeName, int defaultValue)