Java Utililty Methods XML Node Value Check

List of utility methods to do XML Node Value Check

Description

The list of methods to do XML Node Value Check are organized into topic(s).

Method

booleanisCommentAllowed(Node node)
is Comment Allowed
short type = node.getNodeType();
return type == Node.ELEMENT_NODE || type == Node.TEXT_NODE;
booleanisCommentNode(Node node)
Checks if the given Node is Comment Node
if (node == null)
    return false;
return (node.getNodeType() == Node.COMMENT_NODE);
booleanisContainerElement(Node node)
is Container Element
if (node == null || node.getNodeType() != Node.ELEMENT_NODE) {
    return false;
final String ns = node.getNamespaceURI();
final String ln = node.getLocalName();
final Set<String> containerElementNames = CONTAINER_ELEMENTS.get(ns);
return (containerElementNames != null && containerElementNames.contains(ln));
booleanisCreateInstanceSet(Node node)
Checks whether the optional attribute createInstance is set for a specific node.
boolean createInstance = false;
if (node.getAttributes().getNamedItem("createInstance") != null) {
    if (node.getAttributes().getNamedItem("createInstance").getNodeValue().equalsIgnoreCase("yes"))
        createInstance = true;
return createInstance;
booleanisElementNodeExist(Node root, String nodeString)
is Element Node Exist
NodeList nlist = root.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++) {
    if (nlist.item(i) instanceof Element) {
        if (nlist.item(i).getNodeName().equalsIgnoreCase(nodeString)) {
            return true;
        if (nlist.item(i).hasChildNodes() && isElementNodeExist(nlist.item(i), nodeString)) {
            return true;
...
booleanisElementNodeOfType(final Node n, final String type)
is Element Node Of Type
return n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(type);
booleanisElementType(Node _node)
Shortcut for checking if given node is of type Element .
return _node instanceof Element;
booleanisEmpty(Node node)
Returns true if the specified node is null or has no children.
return (node == null);
booleanisEmptyTag(Node p_node)
is Empty Tag
boolean isEmptyTag = (p_node == null) ? true : (p_node.getFirstChild() == null ? true : false);
return isEmptyTag;
booleanisEqual(Node a, Node b)
Test two DOM nodes for equality, if both nodes are not equal to null then they are compared via Node#isEqualNode(Node)
return (a == null) ? b == null : b != null && a.isEqualNode(b);