⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpathtestbase.java

📁 XML的解析、编译、查询等技术的JAVA源代码。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/root/c", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertValueOfXPath("d", context, "string()");        }    }    /* test for jaxen-3    */    public void testJaxen3dupe() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/jaxen3.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertCountXPath(1, context, "/Configuration/hostname/attrlist/hostname[. = 'CE-A'] ");        }    }    /* parser test cases all of which should fail    */    public void testForParserErrors() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/numbers.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            /* repeated xpaths, jaxen-35            */            assertInvalidXPath(context, "/numbers numbers");            /* invalid xpath, jaxen-34            */            assertInvalidXPath(context, "/a/b[c > d]efg");            /* invalid xpath, jaxen-27            */            assertInvalidXPath(context, "/inv/child::");            /* invalid xpath, jaxen-26            */            assertInvalidXPath(context, "/invoice/@test[abcd");            assertInvalidXPath(context, "/invoice/@test[abcd > x");            /* unterminated string            */            assertInvalidXPath(context, "string-length('a");            /* various edge cases where code threw no exception            */            assertInvalidXPath(context, "/descendant::()");            assertInvalidXPath(context, "(1 + 1");            // no ! operator            assertInvalidXPath(context, "!false()");        }    }    /* test cases for the use of underscores in names    */    public void testUnderscoresInNames() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/underscore.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertCountXPath(1, context, "/root/@a");            assertCountXPath(1, context, "/root/@_a");            assertCountXPath(1, context, "/root/b");            assertCountXPath(1, context, "/root/_b");            assertValueOfXPath("1", context, "/root/@a");            assertValueOfXPath("2", context, "/root/@_a");            assertValueOfXPath("1", context, "/root/b");            assertValueOfXPath("2", context, "/root/_b");        }    }    /* test cases for the use of = with node-sets    */    public void testNodesetEqualsString() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/web.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'file'");            assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'snoop'");        }    }    public void testNodesetEqualsNumber() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/numbers.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertValueOfXPath("true", context, "/numbers/set/nr = '-3'");            assertValueOfXPath("true", context, "/numbers/set/nr = -3");            assertValueOfXPath("true", context, "/numbers/set/nr = 24");            assertValueOfXPath("true", context, "/numbers/set/nr/@value = '9999'");            assertValueOfXPath("true", context, "/numbers/set/nr/@value = 9999.0");            assertValueOfXPath("true", context, "/numbers/set/nr/@value = 66");        }    }    /* test basic math...    */    public void testIntegerArithmetic() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/numbers.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertValueOfXPath("true", context, "(8 * 2 + 1) = 17");            assertValueOfXPath("true", context, "(1 + 8 * 2) = 17");            assertValueOfXPath("true", context, "(7 - 3 + 1) = 5");            assertValueOfXPath("true", context, "(8 - 4 + 5 - 6) = 3");            /* left-assoc tests, comments show WRONG evaluation            */            /* 3 - 2 - 1 != 2            */            assertValueOfXPath("0", context, "3 - 2 - 1");            /* 8 div 4 div 2 != 4            */            assertValueOfXPath("1", context, "8 div 4 div 2");            /* 3 mod 5 mod 7 != 1            */            assertValueOfXPath("3", context, "3 mod 7 mod 5");            /* 1=(2=2) is true            */            assertValueOfXPath("false", context, "1 = 2 = 2");            /*  2!=(3!=1) => 2!=1 => true, (2!=3)!=1 => 1!=1 => false            */            assertValueOfXPath("false", context, "2 != 3 != 1");            /* 3 > (2 > 1) is true            */            assertValueOfXPath("false", context, "3 > 2 > 1");            /* 3 >= (2 >= 2) is true            */            assertValueOfXPath("false", context, "3 >= 2 >= 2");            /* 1 < (2 < 3) is false            */            assertValueOfXPath("true", context, "1 < 2 < 3");            /* 0 <= (2 <= 3) is true            */            assertValueOfXPath("true", context, "2 <= 2 <= 3");        }    }        public void testFloatingPointArithmetic() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/numbers.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertValueOfXPath("true", context, "(8.5 * 2.0 + 1) = 18");            assertValueOfXPath("true", context, "(1.00 + 8.5 * 2) = 18.0");            assertValueOfXPath("true", context, "(7.1 - 7.1 + 1.5) = 1.5");            assertValueOfXPath("true", context, "(8.000 - 4.0 + 5 - 6.00) = 3");            assertValueOfXPath("0", context, "3.5 - 2.5 - 1.0");            assertValueOfXPath("1", context, "8.0 div 4.0 div 2.0");            assertValueOfXPath("3", context, "3.0 mod 7.0 mod 5.0");            assertValueOfXPath("false", context, "1.5 = 2.3 = 2.3");            assertValueOfXPath("false", context, "2.1 != 3.2 != 1.9");            assertValueOfXPath("false", context, "3.8 > 2.7 > 1.6");            assertValueOfXPath("false", context, "3.4 >= 2.5 >= 2.5");            assertValueOfXPath("true", context, "1.4 < 2.3 < 3.2");            assertValueOfXPath("true", context, "2.5 <= 2.5 <= 3.5");        }    }    /* test cases for preceding axis with different node types    */    public void testPrecedingSiblingAxis() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/pi2.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/a/c", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertCountXPath(1, context, "//processing-instruction()");            assertCountXPath(1, context, "preceding-sibling::*");            assertCountXPath(5, context, "preceding-sibling::node()");            assertCountXPath(1, context, "preceding-sibling::*[1]");            assertCountXPath(1, context, "preceding-sibling::processing-instruction()");            assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::processing-instruction()");            assertValueOfXPath("foo", context, "preceding-sibling::*[1]");            assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::node()[2]");        }    }    public void testVariableLookup() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/id.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        SimpleVariableContext varContext = new SimpleVariableContext();        varContext.setVariableValue(null, "foobar", "foobar");        varContext.setVariableValue(null, "foo", "foo");        getContextSupport().setVariableContext(varContext);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertValueOfXPath("foobar", context, "$foobar");            assertCountXPath(1, context, "/foo[@id=$foobar]");            assertCountXPath(0, context, "/foo[@id='$foobar']");            assertCountXPath(1, context, "/foo[concat($foo, 'bar')=@id]");            assertCountXPath(0, context, "CD_Library/artist[@name=$artist]");        }    }    public void testAttributeParent() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/id.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            /* attributes have a parent: their element            */            assertCountXPath(1, context, "/foo/@id/parent::foo");        }    }    /* attributes can also be used as context nodes    */    public void testAttributeAsContext() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/id.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/foo/@id", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();        while (iter.hasNext())        {            Object context = iter.next();            assertCountXPath(1, context, "parent::foo");        }    }    public void testid53992() throws JaxenException    {        Navigator nav = getNavigator();        String url = "xml/pi.xml";        log("Document [" + url + "]");        Object document = nav.getDocument(url);        XPath contextpath = new BaseXPath("/", nav);        log("Initial Context :: " + contextpath);        List list = contextpath.selectNodes(document);        Iterator iter = list.iterator();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -