public static String getAttributeValue(final Node elementNode, final String attrName)
    {
        if (null == elementNode)
        {
            throw new IllegalStateException(
                "element node is null when looking for attribute: " + attrName);
        }

        final NamedNodeMap attributes = elementNode.getAttributes();
        final Node attrNode = attributes.getNamedItemNS(null, attrName);
        if (null == attrNode)
        {
            throw new IllegalStateException(
                "element '" + elementNode.getNodeName() + "' has missing attribute: " + attrName);
        }

        final String nodeValue = attrNode.getNodeValue();
        if (Strings.isEmpty(nodeValue))
        {
            throw new IllegalStateException(
                "element '" + elementNode.getNodeName() + "' has empty attribute: " + attrName);
        }

        return nodeValue;
    }
Helper function that throws an exception when the attribute is not set.

@param elementNode that should have the attribute.
@param attrName    that is to be looked up.
@return value of the attribute.
@throws IllegalStateException if the attribute is not present.
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java