Java XML Attribute Exist hasAttribute(Element element, String attribute)

Here you can find the source of hasAttribute(Element element, String attribute)

Description

has Attribute

License

Open Source License

Return

true if the specified attribute is present and not empty or null in the element

Declaration

public static boolean hasAttribute(Element element, String attribute) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;

public class Main {
    /**//from  w w  w.j a v  a 2s.com
     * @return true if the specified attribute is present and not empty or null in the element
     */
    public static boolean hasAttribute(Element element, String attribute) {
        String s = element.getAttribute(attribute);
        if (s == null || "".equals(s)) {
            return false;
        } else {
            return true;
        }
    }
}

Related

  1. hasAttribute(Element e, String s)
  2. hasAttribute(Element ele, String attrName)
  3. hasAttribute(Element element, String namespace, String name)
  4. hasAttribute(Element element, String value)
  5. hasAttribute(final Node node, final String name)
  6. hasAttribute(final Node node, final String name)