Code example for Element

Methods: getAttributegetElementsByTagName

     * Returns the test described by the given {@code <test>} element. Such 
     * tests come in one of three varieties: 
     * <ul> 
     *   <li>Expected failures. 
     *   <li>String matches. These tests have a nested {@code <valueOf>} element 
     *       that sub-selects an expected text. 
     *   <li>Count matches. These tests specify how many nodes are expected to 
     *       match. 
     * </ul> 
    private static TestCase createFromTest(
            final XPath xpath, final Context context, final Element element) {
        final String select = element.getAttribute("select"); 
        /* Such as <test exception="true" select="..." count="0"/> */ 
        if (element.getAttribute("exception").equals("true")) { 
            return new XPathTest(context, select) { 
                @Override void test(Node contextNode) { 
                    try { 
                        xpath.evaluate(select, contextNode); 
                        fail("Expected exception!"); 
                    } catch (XPathExpressionException expected) { 
        /* a <test> with a nested <valueOf>, both of which have select attributes */ 
        NodeList valueOfElements = element.getElementsByTagName("valueOf"); 
        if (valueOfElements.getLength() == 1) { 
            final Element valueOf = (Element) valueOfElements.item(0); 
            final String valueOfSelect = valueOf.getAttribute("select"); 
            return new XPathTest(context, select) { 
                @Override void test(Node contextNode) throws XPathExpressionException {
                    Node newContext = (Node) xpath.evaluate(
                            select, contextNode, XPathConstants.NODE);
                            xpath.evaluate(valueOfSelect, newContext, XPathConstants.STRING));
Connect your IDE to all the code out there  Get Codota for Java