本文整理汇总了Java中org.jaxen.BaseXPath.selectNodes方法的典型用法代码示例。如果您正苦于以下问题:Java BaseXPath.selectNodes方法的具体用法?Java BaseXPath.selectNodes怎么用?Java BaseXPath.selectNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jaxen.BaseXPath
的用法示例。
在下文中一共展示了BaseXPath.selectNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLastFunction
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testLastFunction()
throws JaxenException {
BaseXPath xpath = new DOMXPath("//x[position()=last()]");
org.w3c.dom.Element a = doc.createElementNS("", "a");
org.w3c.dom.Element b = doc.createElementNS("", "b");
doc.appendChild(a);
a.appendChild(b);
org.w3c.dom.Element x2 = doc.createElementNS("", "x");
org.w3c.dom.Element x3 = doc.createElementNS("", "x");
org.w3c.dom.Element x4 = doc.createElementNS("", "x");
a.appendChild(x4);
b.appendChild(x2);
b.appendChild(x3);
x2.appendChild(doc.createTextNode("2"));
x3.appendChild(doc.createTextNode("3"));
x4.appendChild(doc.createTextNode("4"));
List result = xpath.selectNodes(doc);
assertEquals(2, result.size());
assertEquals(x3, result.get(0));
assertEquals(x4, result.get(1));
}
示例2: testXMLNamespaceAttributeOrderOnAncestorAxis
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testXMLNamespaceAttributeOrderOnAncestorAxis()
throws JaxenException {
org.w3c.dom.Element superroot = doc.createElement("superroot");
doc.appendChild(superroot);
org.w3c.dom.Element root = doc.createElement("root");
superroot.appendChild(root);
org.w3c.dom.Attr p0 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id");
p0.setValue("p0");
superroot.setAttributeNodeNS(p0);
org.w3c.dom.Attr p1 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id");
p1.setValue("p1");
root.setAttributeNodeNS(p1);
org.w3c.dom.Element child = doc.createElement("child312");
root.appendChild(child);
BaseXPath xpath = new DOMXPath("ancestor::*/@xml:*");
List result = xpath.selectNodes(child);
assertEquals(2, result.size());
assertEquals(p0, result.get(0));
assertEquals(p1, result.get(1));
}
示例3: testLangFunctionSelectsNonEmptyNodeSet
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testLangFunctionSelectsNonEmptyNodeSet()
throws JaxenException {
BaseXPath xpath = new DOMXPath("//*[lang(x)]");
Element a = doc.createElementNS("", "a");
Element b = doc.createElementNS("", "b");
b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA");
doc.appendChild(a);
a.appendChild(b);
Element x2 = doc.createElementNS("", "x");
Element x3 = doc.createElementNS("", "x");
Element x4 = doc.createElementNS("", "x");
a.appendChild(x4);
b.appendChild(x2);
b.appendChild(x3);
x2.appendChild(doc.createTextNode("fr"));
x3.appendChild(doc.createTextNode("3"));
x4.appendChild(doc.createTextNode("4"));
List result = xpath.selectNodes(doc);
assertEquals(1, result.size());
assertEquals(b, result.get(0));
}
示例4: testHyphenRequiredAtEnd
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testHyphenRequiredAtEnd()
throws JaxenException {
BaseXPath xpath = new DOMXPath("//*[lang('f')]");
Element a = doc.createElementNS("", "a");
Element b = doc.createElementNS("", "b");
b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA");
doc.appendChild(a);
a.appendChild(b);
Element x2 = doc.createElementNS("", "x");
Element x3 = doc.createElementNS("", "x");
Element x4 = doc.createElementNS("", "x");
a.appendChild(x4);
b.appendChild(x2);
b.appendChild(x3);
x2.appendChild(doc.createTextNode("2"));
x3.appendChild(doc.createTextNode("3"));
x4.appendChild(doc.createTextNode("4"));
List result = xpath.selectNodes(doc);
assertEquals(0, result.size());
}
示例5: testLangFunctionAppliedToNonElement
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testLangFunctionAppliedToNonElement()
throws JaxenException {
BaseXPath xpath = new DOMXPath("//text()[lang('fr')]");
Element a = doc.createElementNS("", "a");
Element b = doc.createElementNS("", "b");
b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA");
doc.appendChild(a);
a.appendChild(b);
Element x2 = doc.createElementNS("", "x");
Element x3 = doc.createElementNS("", "x");
Element x4 = doc.createElementNS("", "x");
a.appendChild(x4);
b.appendChild(x2);
b.appendChild(x3);
x2.appendChild(doc.createTextNode("fr"));
x3.appendChild(doc.createTextNode("3"));
x4.appendChild(doc.createTextNode("4"));
List result = xpath.selectNodes(doc);
assertEquals(2, result.size());
assertEquals(x2.getFirstChild(), result.get(0));
assertEquals(x3.getFirstChild(), result.get(1));
}
示例6: testBooleanFunctionRequiresExactlyOneArgument
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testBooleanFunctionRequiresExactlyOneArgument()
throws JaxenException {
BaseXPath xpath = new DOMXPath("floor(2.2, 1.2)");
try {
xpath.selectNodes(doc);
fail("Allowed floor function with two arguments");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}
示例7: testNotFunctionRequiresExactlyOneArgument
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testNotFunctionRequiresExactlyOneArgument()
throws JaxenException {
BaseXPath xpath = new DOMXPath("not('', '')");
try {
xpath.selectNodes(doc);
fail("Allowed not() function with two arguments");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}
示例8: testCountFunctionRequiresAtLeastOneArgument
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testCountFunctionRequiresAtLeastOneArgument()
throws JaxenException {
BaseXPath xpath = new DOMXPath("count()");
try {
xpath.selectNodes(doc);
fail("Allowed count function with no arguments");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}
示例9: testUnionUsesDocumentOrder
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testUnionUsesDocumentOrder() throws JaxenException {
BaseXPath xpath = new DOMXPath("/descendant::x | /a | /a/b");
org.w3c.dom.Element a = doc.createElementNS("", "a");
org.w3c.dom.Element b = doc.createElementNS("", "b");
doc.appendChild(a);
org.w3c.dom.Element x1 = doc.createElementNS("", "x");
x1.appendChild(doc.createTextNode("1"));
a.appendChild(x1);
a.appendChild(b);
org.w3c.dom.Element x2 = doc.createElementNS("", "x");
org.w3c.dom.Element x3 = doc.createElementNS("", "x");
org.w3c.dom.Element x4 = doc.createElementNS("", "x");
a.appendChild(x4);
b.appendChild(x2);
b.appendChild(x3);
x2.appendChild(doc.createTextNode("2"));
x3.appendChild(doc.createTextNode("3"));
x4.appendChild(doc.createTextNode("4"));
List result = xpath.selectNodes(doc);
assertEquals(6, result.size());
assertEquals(a, result.get(0));
assertEquals(x1, result.get(1));
assertEquals(b, result.get(2));
assertEquals(x2, result.get(3));
assertEquals(x3, result.get(4));
assertEquals(x4, result.get(5));
}
示例10: testCeilingFunctionRequiresAtMostOneArgument
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testCeilingFunctionRequiresAtMostOneArgument()
throws JaxenException {
BaseXPath xpath = new DOMXPath("ceiling(2.2, 1.2)");
try {
xpath.selectNodes(doc);
fail("Allowed ceiling function with two arguments");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}
示例11: testSubstringBeforeFunctionRequiresAtMostTwoArguments
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testSubstringBeforeFunctionRequiresAtMostTwoArguments()
throws JaxenException {
BaseXPath xpath = new DOMXPath("substring-before('a', 'a', 'a')");
try {
xpath.selectNodes(doc);
fail("Allowed substring-before function with three arguments");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}
示例12: testAncestorFollowedByChildren
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testAncestorFollowedByChildren() throws JaxenException {
BaseXPath xpath = new DOMXPath("/a/b/x/ancestor::*/child::x");
org.w3c.dom.Element a = doc.createElementNS("", "a");
org.w3c.dom.Element b = doc.createElementNS("", "b");
doc.appendChild(a);
org.w3c.dom.Element x1 = doc.createElementNS("", "x");
x1.appendChild(doc.createTextNode("1"));
a.appendChild(x1);
a.appendChild(b);
org.w3c.dom.Element x2 = doc.createElementNS("", "x");
org.w3c.dom.Element x3 = doc.createElementNS("", "x");
org.w3c.dom.Element x4 = doc.createElementNS("", "x");
a.appendChild(x4);
b.appendChild(x2);
b.appendChild(x3);
x2.appendChild(doc.createTextNode("2"));
x3.appendChild(doc.createTextNode("3"));
x4.appendChild(doc.createTextNode("4"));
List result = xpath.selectNodes(doc);
assertEquals(4, result.size());
assertEquals(x1, result.get(0));
assertEquals(x2, result.get(1));
assertEquals(x3, result.get(2));
assertEquals(x4, result.get(3));
}
示例13: testCeilingFunctionRequiresAtLeastOneArgument
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testCeilingFunctionRequiresAtLeastOneArgument()
throws JaxenException {
BaseXPath xpath = new DOMXPath("ceiling()");
try {
xpath.selectNodes(doc);
fail("Allowed ceiling function with no arguments");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}
示例14: testStartsWithFunctionRequiresAtLeastTwoArguments
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testStartsWithFunctionRequiresAtLeastTwoArguments()
throws JaxenException {
BaseXPath xpath = new DOMXPath("starts-with('a')");
try {
xpath.selectNodes(doc);
fail("Allowed starts-with function with one argument");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}
示例15: testStartsWithFunctionRequiresAtMostTwoArguments
import org.jaxen.BaseXPath; //导入方法依赖的package包/类
public void testStartsWithFunctionRequiresAtMostTwoArguments()
throws JaxenException {
BaseXPath xpath = new DOMXPath("starts-with('a', 'a', 'a')");
try {
xpath.selectNodes(doc);
fail("Allowed starts-with function with three arguments");
}
catch (FunctionCallException ex) {
assertNotNull(ex.getMessage());
}
}