Mega Code Archive

 
Categories / Java / XML
 

Returns null, not , for a nonexistent attribute

import org.w3c.dom.Attr; import org.w3c.dom.Element; public class Utils {   /**    * Returns null, not "", for a nonexistent attribute.    *     * @param e    * @param attributeName    * @return    */   public static String getAttributeValueEmptyNull(Element e, String attributeName) {       Attr node = e.getAttributeNode(attributeName);       if (node == null) {           return null;       }       return node.getValue();   } }