use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.
the class TestNodeWrapperXPath method testText.
@Test
public void testText() throws Exception {
final XPathExpression findLine = xpe.compile("//b[1]/text()");
final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
// Execute XPath.
final String result = (String) findLine.evaluate(doc, XPathConstants.STRING);
assertNotNull(result);
assertEquals("foo", result);
}
use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.
the class TestNodeWrapperXPath method testText1.
@Test
public void testText1() throws Exception {
xpe.setNamespaceContext(new DocNamespaceContext());
final XPathExpression findLine = xpe.compile("//p:a[1]/text()[1]");
final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
// Execute XPath.
final String result = (String) findLine.evaluate(doc, XPathConstants.STRING);
assertNotNull(result);
assertEquals("oops1", result);
}
use of net.sf.saxon.om.NodeInfo in project teiid by teiid.
the class XOMDocumentWrapper method selectID.
/**
* Get the element with a given ID, if any
*
* @param id the required ID value
* @param getParent
* @return the element with the given ID, or null if there is no such ID
* present (or if the parser has not notified attributes as being of
* type ID).
*/
/*@Nullable*/
public NodeInfo selectID(String id, boolean getParent) {
if (idIndex == null) {
Element elem;
switch(nodeKind) {
case Type.DOCUMENT:
elem = ((Document) node).getRootElement();
break;
case Type.ELEMENT:
elem = (Element) node;
break;
default:
return null;
}
idIndex = new HashMap<String, NodeInfo>(50);
buildIDIndex(elem);
}
return idIndex.get(id);
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class XpathUtil method getXpathItems.
/**
* Returns list of nodes matching xpath expression given node context.
*
* @param xpath Xpath expression
* @param rootNode {@code NodeInfo} node context
* @return list of nodes matching xpath expression given node context
*/
public static List<NodeInfo> getXpathItems(String xpath, AbstractNode rootNode) throws XPathException {
final XPathEvaluator xpathEvaluator = new XPathEvaluator(Configuration.newConfiguration());
final XPathExpression xpathExpression = xpathEvaluator.createExpression(xpath);
final XPathDynamicContext xpathDynamicContext = xpathExpression.createDynamicContext(rootNode);
final List<Item> items = xpathExpression.evaluate(xpathDynamicContext);
return items.stream().map(item -> (NodeInfo) item).collect(Collectors.toList());
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class ReverseDescendantIteratorTest method testCorrectOrder.
@Test
public void testCorrectOrder() {
final NodeInfo startNode = findNode("CLASS_DEF");
try (ReverseDescendantIterator iterator = new ReverseDescendantIterator(startNode)) {
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("OBJBLOCK"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("RCURLY"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("METHOD_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("LCURLY"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("SLIST"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PARAMETERS"));
assertWithMessage("Node should be null").that(iterator.next()).isNull();
assertWithMessage("Node should be null").that(iterator.next()).isNull();
}
}
Aggregations