code: public static Node getNextParentNodeWithAttr(final Node parent, final String attrName) {
          Node parentNode = parent;
          Element parendElement = (Element) parentNode;
          Node valueNode = parendElement.getAttributes().getNamedItem(attrName);
          while (valueNode == null) {
              parentNode = parentNode.getParentNode();
              if (parentNode != null) {
                  if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
                      parendElement = (Element) parentNode;
                      valueNode = parendElement.getAttributes().getNamedItem(attrName);
                  }
              } else {
                  break;
              }
          }
  
          return parendElement;
      }
docs: Returns the next parent node which has the specific attribute name defined.
  
  @param parent
  the w3c node from which the search will start.
  @param attrName
  the attribute name which is searched for.
  @return a parent node, if the attribute is found, otherwise null.