public static Element getElement(Node node, String query, boolean required) { Nodes nodes = node.query(query, Constants.XOM_CONTEXT); if (nodes.size() == 0) { if (required) { throw FaultRaiser.raiseBadArgumentFault("Nothing at " + query); } else { return null; } } Node n = nodes.get(0); if (!(n instanceof Element)) { throw FaultRaiser.raiseBadArgumentFault("Expected an element at " + query + " but got " + n); } return (Element) n;
public static Element getElement(Node node, String query) { return getElement(node, query, true);
    public static Element getElement(Node node,                                     String query,                                     boolean required) {        Nodes nodes = node.query(query, Constants.XOM_CONTEXT);        if (nodes.size() == 0) {            if (required) {                throw FaultRaiser.raiseBadArgumentFault("Nothing at " + query);            } else {                return null;            }        }        Node n = nodes.get(0);        if (!(n instanceof Element)) {            throw FaultRaiser.raiseBadArgumentFault("Expected an element at " +                    query                    +                    " but got " +                    n);        }        return (Element) n;    }