本文整理汇总了Java中org.jaxen.BaseXPath类的典型用法代码示例。如果您正苦于以下问题:Java BaseXPath类的具体用法?Java BaseXPath怎么用?Java BaseXPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BaseXPath类属于org.jaxen包,在下文中一共展示了BaseXPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIDFunctionSelectsNothingInDocumentWithNoIds
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testIDFunctionSelectsNothingInDocumentWithNoIds()
throws JaxenException {
BaseXPath xpath = new DOMXPath("id('p1')");
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"));
Attr id = doc.createAttribute("id");
id.setNodeValue("p1");
x2.setAttributeNode(id);
List result = xpath.selectNodes(doc);
assertEquals(0, result.size());
}
示例2: testFindMultipleElementsByMultipleIDs
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testFindMultipleElementsByMultipleIDs()
throws JaxenException, SAXException, IOException {
BaseXPath xpath = new DOMXPath("id(//id)");
String text = "<!DOCTYPE root [<!ATTLIST a id ID #REQUIRED>]><root><id>p1</id><id>p2</id><id>p3</id><a id='p1'/><a id='p2'/></root>";
StringReader reader = new StringReader(text);
InputSource in = new InputSource(reader);
Document doc = builder.parse(in);
List result = xpath.selectNodes(doc);
assertEquals(2, result.size());
Element a1 = (Element) result.get(0);
Element a2 = (Element) result.get(1);
assertEquals("a", a1.getNodeName());
assertEquals("a", a2.getNodeName());
}
示例3: testAncestorAxis
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testAncestorAxis() throws JaxenException {
BaseXPath xpath = new DOMXPath("ancestor::*");
org.w3c.dom.Element root = doc.createElementNS("", "root");
org.w3c.dom.Element parent = doc.createElementNS("", "parent");
doc.appendChild(root);
org.w3c.dom.Element child = doc.createElementNS("", "child");
root.appendChild(parent);
parent.appendChild(child);
List result = xpath.selectNodes(child);
assertEquals(2, result.size());
assertEquals(root, result.get(0));
assertEquals(parent, result.get(1));
}
示例4: testPrecedingSiblingAxisIsInDocumentOrder
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testPrecedingSiblingAxisIsInDocumentOrder() throws JaxenException {
BaseXPath xpath = new DOMXPath("preceding-sibling::*");
org.w3c.dom.Element root = doc.createElementNS("", "root");
doc.appendChild(root);
org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
root.appendChild(child1);
org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
root.appendChild(child2);
org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
root.appendChild(child3);
List result = xpath.selectNodes(child3);
assertEquals(2, result.size());
assertEquals(child1, result.get(0));
assertEquals(child2, result.get(1));
}
示例5: testPrecedingAxisIsInDocumentOrder
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testPrecedingAxisIsInDocumentOrder() throws JaxenException {
BaseXPath xpath = new DOMXPath("preceding::*");
org.w3c.dom.Element root = doc.createElementNS("", "root");
doc.appendChild(root);
org.w3c.dom.Element parent1 = doc.createElementNS("", "parent1");
root.appendChild(parent1);
org.w3c.dom.Element parent2 = doc.createElementNS("", "parent2");
root.appendChild(parent2);
org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
parent2.appendChild(child1);
org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
parent2.appendChild(child2);
org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
parent2.appendChild(child3);
List result = xpath.selectNodes(child3);
assertEquals(3, result.size());
assertEquals(parent1, result.get(0));
assertEquals(child1, result.get(1));
assertEquals(child2, result.get(2));
}
示例6: testPrecedingAxisWithPositionalPredicate
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testPrecedingAxisWithPositionalPredicate() throws JaxenException {
BaseXPath xpath = new DOMXPath("preceding::*[1]");
org.w3c.dom.Element root = doc.createElementNS("", "root");
doc.appendChild(root);
org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
root.appendChild(child1);
org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
root.appendChild(child2);
org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
root.appendChild(child3);
List result = xpath.selectNodes(child3);
assertEquals(1, result.size());
assertEquals(child2, result.get(0));
}
示例7: testAncestorAxisWithPositionalPredicate
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testAncestorAxisWithPositionalPredicate() throws JaxenException {
BaseXPath xpath = new DOMXPath("ancestor::*[1]");
org.w3c.dom.Element root = doc.createElementNS("", "root");
doc.appendChild(root);
org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
root.appendChild(child1);
org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
child1.appendChild(child2);
org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
child2.appendChild(child3);
List result = xpath.selectNodes(child3);
assertEquals(1, result.size());
assertEquals(child2, result.get(0));
}
示例8: testAncestorOrSelfAxis
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testAncestorOrSelfAxis() throws JaxenException {
BaseXPath xpath = new DOMXPath("ancestor-or-self::*");
org.w3c.dom.Element root = doc.createElementNS("", "root");
org.w3c.dom.Element parent = doc.createElementNS("", "parent");
doc.appendChild(root);
org.w3c.dom.Element child = doc.createElementNS("", "child");
root.appendChild(parent);
parent.appendChild(child);
List result = xpath.selectNodes(child);
assertEquals(3, result.size());
assertEquals(root, result.get(0));
assertEquals(parent, result.get(1));
assertEquals(child, result.get(2));
}
示例9: 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));
}
示例10: testAncestorAxisWithAttributes
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testAncestorAxisWithAttributes() throws JaxenException {
BaseXPath xpath = new DOMXPath("ancestor::*/@*");
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 x3 = doc.createElementNS("", "x");
b.appendChild(x3);
Attr a1 = doc.createAttribute("name");
a1.setNodeValue("1");
a.setAttributeNode(a1);
Attr a2 = doc.createAttribute("name");
a2.setNodeValue("2");
b.setAttributeNode(a2);
Attr a3 = doc.createAttribute("name");
x3.setNodeValue("3");
x3.setAttributeNode(a3);
List result = xpath.selectNodes(x3);
assertEquals(2, result.size());
assertEquals(a1, result.get(0));
assertEquals(a2, result.get(1));
}
示例11: testDuplicateNodes
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testDuplicateNodes() throws JaxenException {
BaseXPath xpath = new DOMXPath("//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(6, result.size());
}
示例12: testUnionOfEmptyNodeSetWithNonNodes
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testUnionOfEmptyNodeSetWithNonNodes() throws JaxenException {
BaseXPath xpath = new DOMXPath("//y | count(//*)");
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");
b.appendChild(x2);
x2.appendChild(doc.createTextNode("2"));
try {
xpath.selectNodes(doc);
fail("Allowed union with non-node-set");
}
catch (JaxenException ex) {
assertNotNull(ex.getMessage());
}
}
示例13: testAddNamespaceWithNonSimpleNamespaceContext
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testAddNamespaceWithNonSimpleNamespaceContext() throws JaxenException {
BaseXPath xpath = new DOMXPath("/b/c");
xpath.setNamespaceContext(new NamespaceContext() {
public String translateNamespacePrefixToUri(String prefix) {
return prefix;
}
});
try {
xpath.addNamespace("pre", "foo");
fail("Added namespace");
}
catch (JaxenException ex) {
assertNotNull(ex.getMessage());
}
}
示例14: testLangFunction
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testLangFunction()
throws JaxenException {
BaseXPath xpath = new DOMXPath("//*[lang('en')]");
Element a = doc.createElementNS("", "a");
Element b = doc.createElementNS("", "b");
b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "en");
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(3, result.size());
assertEquals(b, result.get(0));
assertEquals(x2, result.get(1));
assertEquals(x3, result.get(2));
}
示例15: testLangFunctionSelectsNothing
import org.jaxen.BaseXPath; //导入依赖的package包/类
public void testLangFunctionSelectsNothing()
throws JaxenException {
BaseXPath xpath = new DOMXPath("//*[lang('fr')]");
Element a = doc.createElementNS("", "a");
Element b = doc.createElementNS("", "b");
b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "en");
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());
}