Java Utililty Methods XML Attribute Exist

List of utility methods to do XML Attribute Exist

Description

The list of methods to do XML Attribute Exist are organized into topic(s).

Method

booleanhasAttribute(Node node, String attributeName, String className)
Checks the presence of an attribute value in attributes that contain whitespace-separated lists of values.
String attr = readAttribute(node, attributeName);
for (String c : attr.split("\\s+"))
    if (c.equalsIgnoreCase(className))
        return true;
return false;
booleanhasAttributeValue(final Element element, final String attributeName)
has Attribute Value
final String attributeValue = element.getAttribute(attributeName);
return attributeValue != null && !attributeValue.isEmpty();
booleanhasAttributeValue(Node node, String attributeName, String attributeValue)
has Attribute Value
if (node == null || attributeName == null) {
    return false;
String value = getAttributeValue(node, attributeName);
if (value == null) {
    return (attributeValue == null) ? true : false;
if (value.equals(attributeValue)) {
...
booleanhasAttributeValue(String expected, String attribute, Element element)
has Attribute Value
Node node = getAttributeOrNull(attribute, element);
return node != null && expected.equals(node.getTextContent());
booleanhasElementWithAttr(Element modsroot, String nodename, String attrname, String attrvalue)
has Element With Attr
boolean found = false;
NodeList list = modsroot.getElementsByTagName(nodename);
for (int i = 0; i < list.getLength(); i++) {
    Node node = (Node) list.item(i);
    NamedNodeMap attrs = node.getAttributes();
    Attr attr = (Attr) attrs.getNamedItem(attrname);
    if (attr != null) {
        if (attr.getValue().equals(attrvalue)) {
...
booleanisAttribute(Node node)
is Attribute
return node.getNodeType() == Node.ATTRIBUTE_NODE;
booleanisAttribute(Object obj)
Checks if the class field is XML attribute.
boolean ret = false;
if (null != obj) {
    Class<?> clazz = obj.getClass();
    Annotation annotation = clazz.getAnnotation(XmlAnyAttribute.class);
    if (null != annotation) {
        ret = true;
return ret;
booleanisAttributePresent(XMLStreamReader reader, String name)
Test if an attribute is explicitly set
return reader.getAttributeValue(null, name) != null;