Here you can find the source of getNodeAttribute(Node thisNode, String key)
Parameter | Description |
---|---|
thisNode | the Node for which to find desired attribute |
key
= attribute, trimmed, or null if there is not a valid name.
public static String getNodeAttribute(Node thisNode, String key)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /**/* ww w . j a v a 2 s.c o m*/ * Utility method to look for any key=value attribute for a Node and returns * null if the attribute does not exist or contains the empty string. * * @param thisNode the Node for which to find desired attribute * @return String corresponding to the <code>key</code>= attribute, * trimmed, or null if there is not a valid name. */ public static String getNodeAttribute(Node thisNode, String key) { if (null == thisNode) { return null; } NamedNodeMap attributes = thisNode.getAttributes(); if (null == attributes) { return null; } Node node = attributes.getNamedItem(key); if (null == node) { return null; } String value = node.getNodeValue(); if (null == value || (null != value && value.trim().length() == 0)) { return null; } assert value != null; // value NOT null at this point return value.trim(); } }