Search in sources :

Example 41 with NodeInfo

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);
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.Test)

Example 42 with NodeInfo

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);
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.Test)

Example 43 with NodeInfo

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);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Element(nu.xom.Element)

Example 44 with NodeInfo

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());
}
Also used : XPathExpression(net.sf.saxon.sxpath.XPathExpression) Item(net.sf.saxon.om.Item) List(java.util.List) XPathDynamicContext(net.sf.saxon.sxpath.XPathDynamicContext) AbstractNode(com.puppycrawl.tools.checkstyle.xpath.AbstractNode) Configuration(net.sf.saxon.Configuration) XPathException(net.sf.saxon.trans.XPathException) Collectors(java.util.stream.Collectors) XPathEvaluator(net.sf.saxon.sxpath.XPathEvaluator) NodeInfo(net.sf.saxon.om.NodeInfo) XPathExpression(net.sf.saxon.sxpath.XPathExpression) Item(net.sf.saxon.om.Item) NodeInfo(net.sf.saxon.om.NodeInfo) XPathEvaluator(net.sf.saxon.sxpath.XPathEvaluator) XPathDynamicContext(net.sf.saxon.sxpath.XPathDynamicContext)

Example 45 with NodeInfo

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();
    }
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.jupiter.api.Test)

Aggregations

NodeInfo (net.sf.saxon.om.NodeInfo)52 Test (org.junit.Test)21 XPathExpression (javax.xml.xpath.XPathExpression)16 Test (org.junit.jupiter.api.Test)14 Processor (net.sf.saxon.s9api.Processor)8 Configuration (net.sf.saxon.Configuration)7 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)5 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)5 NameTest (net.sf.saxon.pattern.NameTest)4 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)4 XQueryCompiler (net.sf.saxon.s9api.XQueryCompiler)3 XQueryExecutable (net.sf.saxon.s9api.XQueryExecutable)3 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Item (net.sf.saxon.om.Item)2 Serializer (net.sf.saxon.s9api.Serializer)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 NodeList (org.w3c.dom.NodeList)2