📄 xpathtestbase.java
字号:
List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "doc-id[@regsrc='AP' and @id-string='D76UIMO80']"); } } public void testid54534() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/nitf.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/nitf/head", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "meta[@name='ap-cycle']"); assertCountXPath(1, context, "meta[@content='AP']"); assertCountXPath(8, context, "meta[@name and @content]"); assertCountXPath(1, context, "meta[@name='ap-cycle' and @content='AP']"); assertCountXPath(7, context, "meta[@name != 'ap-cycle']"); } } public void testid54570() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/nitf.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, "/nitf/head/meta[@name='ap-cycle']"); assertCountXPath(1, context, "/nitf/head/meta[@content='AP']"); assertCountXPath(8, context, "/nitf/head/meta[@name and @content]"); assertCountXPath(1, context, "/nitf/head/meta[@name='ap-cycle' and @content='AP']"); assertCountXPath(7, context, "/nitf/head/meta[@name != 'ap-cycle']"); } } public void testid54614() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/moreover.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, "/child::node()"); assertCountXPath(1, context, "/*"); assertCountXPath(20, context, "/*/article"); assertCountXPath(221, context, "//*"); assertCountXPath(20, context, "//*[local-name()='article']"); assertCountXPath(20, context, "//article"); assertCountXPath(20, context, "/*/*[@code]"); assertCountXPath(1, context, "/moreovernews/article[@code='13563275']"); DOMXPath xpath = new DOMXPath("/moreovernews/article[@code='13563275']"); List results = xpath.selectNodes(getContext(context)); Object result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("/*/article[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("//article[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("//*[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("/child::node()/child::node()[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("/*/*[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); } } /* test other node types */ public void testNodeTypes() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/contents.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(3, context, "processing-instruction()"); assertCountXPath(3, context, "/processing-instruction()"); assertCountXPath(1, context, "/comment()"); assertCountXPath(1, context, "comment()"); assertCountXPath(2, context, "/child::node()/comment()"); assertCountXPath(2, context, "/*/comment()"); assertCountXPath(3, context, "//comment()"); } } /* test positioning */ public void testPositioning() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/fibo.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(9, context, "/*/fibonacci[position() < 10]"); assertValueOfXPath("196417", context, "sum(//fibonacci)"); assertValueOfXPath("325", context, "sum(//fibonacci/@index)"); assertValueOfXPath("1", context, "/*/fibonacci[2]"); assertValueOfXPath("75025", context, "/*/fibonacci[ count(/*/fibonacci) ]"); assertValueOfXPath("46368", context, "/*/fibonacci[ count(/*/fibonacci) - 1 ]"); } } /* test number functions */ /* test Axes */ public void testid54853() 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(); assertCountXPath(19, context, "descendant-or-self::*"); assertCountXPath(19, context, "descendant::*"); assertCountXPath(19, context, "/descendant::*"); assertCountXPath(19, context, "/descendant-or-self::*"); assertCountXPath(2, context, "/descendant::servlet"); assertCountXPath(2, context, "/descendant-or-self::servlet"); assertCountXPath(2, context, "descendant-or-self::servlet"); assertCountXPath(2, context, "descendant::servlet"); assertCountXPath(2, context, "/*/servlet"); assertValueOfXPath("2", context, "count(/*/servlet)"); assertCountXPath(2, context, "//servlet"); assertValueOfXPath("2", context, "count(//servlet)"); } } public void testid54932() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/web-app", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(2, context, "/descendant::servlet"); assertCountXPath(2, context, "/descendant-or-self::servlet"); assertCountXPath(2, context, "descendant-or-self::servlet"); assertCountXPath(2, context, "descendant::servlet"); } } public void testCountFunction() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/much_ado.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(5, context, "/descendant::ACT"); assertCountXPath(5, context, "descendant::ACT"); assertValueOfXPath("Much Ado about Nothing", context, "/PLAY/TITLE"); assertValueOfXPath("4", context, "2+2"); assertValueOfXPath("21", context, "5 * 4 + 1"); assertValueOfXPath("5", context, "count(descendant::ACT)"); assertValueOfXPath("35", context, "10 + count(descendant::ACT) * 5"); assertValueOfXPath("75", context, "(10 + count(descendant::ACT)) * 5"); } } public void testCountFunctionMore() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/much_ado.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/PLAY/ACT[2]/SCENE[1]", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(5, context, "/descendant::ACT"); assertCountXPath(5, context, "../../descendant::ACT"); assertCountXPath(141, context, "/PLAY/ACT[2]/SCENE[1]/descendant::SPEAKER"); assertCountXPath(141, context, "descendant::SPEAKER"); assertValueOfXPath("646", context, "count(descendant::*)+1"); assertValueOfXPath("142", context, "count(descendant::SPEAKER)+1"); assertValueOfXPath("2", context, "count(ancestor::*)"); assertValueOfXPath("1", context, "count(ancestor::PLAY)"); assertValueOfXPath("3", context, "count(ancestor-or-self::*)"); assertValueOfXPath("1", context, "count(ancestor-or-self::PLAY)"); assertValueOfXPath("6", context, "5+count(ancestor::*)-1"); } } public void testCorrectPredicateApplication() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/much_ado.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(); /* Test correct predicate application */ assertValueOfXPath("5", context, "count(/PLAY/ACT/SCENE[1])"); } } /* test axis node ordering */ public void testAxisNodeOrdering() 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(); /* Reported as Jira issue JAXEN-24 */ assertCountXPath(1, context, "//servlet-mapping/preceding::*[1][name()='description']"); assertCountXPath(1, context, "/web-app/servlet//description/following::*[1][name()='servlet-mapping']"); assertCountXPath(1, context, "/web-app/servlet//description/following::*[2][name()='servlet-name']"); } } /* test document function */ public void testDocumentFunction1() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/text.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(); Object result = assertCountXPath2(1, context, "document('xml/web.xml')"); assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name"); assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name/text()"); assertValueOfXPath("snoop", context, "document('xml/web.xml')/web-app/servlet[1]/servlet-name"); } } /* Test to check if the context changes when an extension function is used. First test is an example, second is the actual test. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -