Code example for Element

Methods: getAttribute, getElementsByTagName

0
     *       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);
                    assertEquals(valueOf.getTextContent(), 
                            xpath.evaluate(valueOfSelect, newContext, XPathConstants.STRING));
                } 
            }; 
        } 
 
        /* Such as <test select="..." count="5"/> */ 
        final String count = element.getAttribute("count");
        if (count.length() > 0) { 
            return new XPathTest(context, select) { 
                @Override void test(Node contextNode) throws XPathExpressionException {
                    NodeList result = (NodeList) xpath.evaluate(
                            select, contextNode, XPathConstants.NODESET);