Java XML Attribute Exist hasAttributeValue(String expected, String attribute, Element element)

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

Description

has Attribute Value

License

Open Source License

Declaration

public static boolean hasAttributeValue(String expected, String attribute, Element element) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.*;

public class Main {
    public static boolean hasAttributeValue(String expected, String attribute, Element element) {
        Node node = getAttributeOrNull(attribute, element);
        return node != null && expected.equals(node.getTextContent());
    }// w  w w .j  av a 2s  .c o  m

    public static Node getAttributeOrNull(String attribute, Element element) {
        if (!element.hasAttributes()) {
            return null;
        }
        NamedNodeMap attributes = element.getAttributes();
        return attributes.getNamedItem(attribute);
    }
}

Related

  1. hasAttribute(Node node, String attributeName)
  2. hasAttribute(Node node, String attributeName)
  3. hasAttribute(Node node, String attributeName, String className)
  4. hasAttributeValue(final Element element, final String attributeName)
  5. hasAttributeValue(Node node, String attributeName, String attributeValue)
  6. hasElementWithAttr(Element modsroot, String nodename, String attrname, String attrvalue)
  7. isAttribute(Node node)
  8. isAttribute(Object obj)
  9. isAttributePresent(XMLStreamReader reader, String name)