Code example for Element

Methods: getAttribute, getParentNode

0
     * Recursive method to find a given attribute value 
     */ 
    public static String recursiveGetAttributeValue(Element element, String attributeName) {
        String answer = null;
        try { 
            answer = element.getAttribute(attributeName);
        } catch (Exception e) {
            e.printStackTrace();
        } 
        if (answer == null || answer.length() == 0) {
            Node parentNode = element.getParentNode();
            if (parentNode instanceof Element) {
                return recursiveGetAttributeValue((Element) parentNode, attributeName);
            } 
        } 
        return answer;
    } 
 
}