Search in sources :

Example 6 with FilterAxis

use of org.sirix.axis.filter.FilterAxis in project sirix by sirixdb.

the class NestedAxisTest method testNestedAxisTest2.

@Test
public void testNestedAxisTest2() throws SirixException {
    final XdmNodeReadTrx rtx = holder.getReader();
    // Find descendants starting from nodeKey 0L (root).
    rtx.moveToDocumentRoot();
    // XPath expression /[:a/b/@p:x]
    // Part: /p:a
    final Axis childA = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "p:a"));
    // Part: /b
    final Axis childB = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "b"));
    // Part: /@x
    final Axis attributeX = new FilterAxis(new AttributeAxis(rtx), new NameFilter(rtx, "p:x"));
    // Part: /p:a/b/@p:x
    final Axis axis = new NestedAxis(new NestedAxis(childA, childB), attributeX);
    AbsAxisTest.testIAxisConventions(axis, new long[] { 10L });
}
Also used : NameFilter(org.sirix.axis.filter.NameFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) FilterAxis(org.sirix.axis.filter.FilterAxis) Axis(org.sirix.api.Axis) FilterAxis(org.sirix.axis.filter.FilterAxis) Test(org.junit.Test)

Example 7 with FilterAxis

use of org.sirix.axis.filter.FilterAxis in project sirix by sirixdb.

the class NestedAxisTest method testNestedAxisTest.

@Test
public void testNestedAxisTest() throws SirixException {
    final XdmNodeReadTrx rtx = holder.getReader();
    // Find descendants starting from nodeKey 0L (root).
    rtx.moveToDocumentRoot();
    // XPath expression /p:a/b/text()
    // Part: /p:a
    final Axis childA = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "p:a"));
    // Part: /b
    final Axis childB = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "b"));
    // Part: /text()
    final Axis text = new FilterAxis(new ChildAxis(rtx), new TextFilter(rtx));
    // Part: /p:a/b/text()
    final Axis axis = new NestedAxis(new NestedAxis(childA, childB), text);
    AbsAxisTest.testIAxisConventions(axis, new long[] { 6L, 12L });
}
Also used : NameFilter(org.sirix.axis.filter.NameFilter) TextFilter(org.sirix.axis.filter.TextFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) FilterAxis(org.sirix.axis.filter.FilterAxis) Axis(org.sirix.api.Axis) FilterAxis(org.sirix.axis.filter.FilterAxis) Test(org.junit.Test)

Example 8 with FilterAxis

use of org.sirix.axis.filter.FilterAxis in project sirix by sirixdb.

the class ConcurrentAxisTest method testSeriellNew.

/**
 * Test seriell.
 */
// @Bench
@Test
public void testSeriellNew() throws Exception {
    /* query: //regions/africa//location */
    final int resultNumber = 55;
    final Axis axis = new NestedAxis(new NestedAxis(new FilterAxis(new DescendantAxis(holder.getReader(), IncludeSelf.YES), new NameFilter(holder.getReader(), "regions")), new FilterAxis(new ChildAxis(holder.getReader()), new NameFilter(holder.getReader(), "africa"))), new FilterAxis(new DescendantAxis(holder.getReader(), IncludeSelf.YES), new NameFilter(holder.getReader(), "location")));
    for (int i = 0; i < resultNumber; i++) {
        assertEquals(true, axis.hasNext());
        axis.next();
    }
    assertEquals(false, axis.hasNext());
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) NameFilter(org.sirix.axis.filter.NameFilter) NestedAxis(org.sirix.axis.NestedAxis) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) NestedAxis(org.sirix.axis.NestedAxis) ChildAxis(org.sirix.axis.ChildAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) Test(org.junit.Test)

Example 9 with FilterAxis

use of org.sirix.axis.filter.FilterAxis in project sirix by sirixdb.

the class ConcurrentAxisTest method testPartConcurrentDescAxis1.

/**
 * Test concurrent.
 *
 * @throws SirixXPathException
 */
// @Bench
@Test
public void testPartConcurrentDescAxis1() throws Exception {
    /* query: //regions/africa//location */
    final int resultNumber = 55;
    final XdmNodeReadTrx firstConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
    final Axis axis = new NestedAxis(new NestedAxis(new ConcurrentAxis(firstConcurrRtx, new FilterAxis(new DescendantAxis(holder.getReader(), IncludeSelf.YES), new NameFilter(holder.getReader(), "regions"))), new FilterAxis(new ChildAxis(firstConcurrRtx), new NameFilter(firstConcurrRtx, "africa"))), new FilterAxis(new DescendantAxis(firstConcurrRtx, IncludeSelf.YES), new NameFilter(firstConcurrRtx, "location")));
    for (int i = 0; i < resultNumber; i++) {
        assertEquals(true, axis.hasNext());
        axis.next();
    }
    assertEquals(false, axis.hasNext());
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) NameFilter(org.sirix.axis.filter.NameFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) NestedAxis(org.sirix.axis.NestedAxis) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) NestedAxis(org.sirix.axis.NestedAxis) ChildAxis(org.sirix.axis.ChildAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) Test(org.junit.Test)

Example 10 with FilterAxis

use of org.sirix.axis.filter.FilterAxis in project sirix by sirixdb.

the class StAXSerializer method getElementText.

@Override
public String getElementText() throws XMLStreamException {
    final XdmNodeReadTrx rtx = mAxis.getTrx();
    final long nodeKey = rtx.getNodeKey();
    /*
     * The cursor has to move back (once) after determining, that a closing tag would be the next
     * event (precond: closeElement and either goBack or goUp is true).
     */
    if (mCloseElements && mToLastKey) {
        rtx.moveTo(mLastKey);
    }
    if (mEvent.getEventType() != XMLStreamConstants.START_ELEMENT) {
        rtx.moveTo(nodeKey);
        throw new XMLStreamException("getElementText() only can be called on a start element");
    }
    final FilterAxis textFilterAxis = new FilterAxis(new DescendantAxis(rtx), new TextFilter(rtx));
    final StringBuilder strBuilder = new StringBuilder();
    while (textFilterAxis.hasNext()) {
        textFilterAxis.next();
        strBuilder.append(rtx.getValue());
    }
    rtx.moveTo(nodeKey);
    return XMLToken.escapeContent(strBuilder.toString());
}
Also used : TextFilter(org.sirix.axis.filter.TextFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) XMLStreamException(javax.xml.stream.XMLStreamException) DescendantAxis(org.sirix.axis.DescendantAxis) FilterAxis(org.sirix.axis.filter.FilterAxis)

Aggregations

FilterAxis (org.sirix.axis.filter.FilterAxis)17 DescendantAxis (org.sirix.axis.DescendantAxis)13 NameFilter (org.sirix.axis.filter.NameFilter)13 Axis (org.sirix.api.Axis)12 ChildAxis (org.sirix.axis.ChildAxis)10 Test (org.junit.Test)7 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)7 NestedAxis (org.sirix.axis.NestedAxis)5 TextFilter (org.sirix.axis.filter.TextFilter)5 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)4 PostOrderAxis (org.sirix.axis.PostOrderAxis)4 PathKindFilter (org.sirix.axis.filter.PathKindFilter)4 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)4 XPathAxis (org.sirix.service.xml.xpath.XPathAxis)4 XMLStreamException (javax.xml.stream.XMLStreamException)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 NodeFilter (org.sirix.axis.filter.NodeFilter)2 PathLevelFilter (org.sirix.axis.filter.PathLevelFilter)2 ElementNode (org.sirix.node.ElementNode)2 NameNode (org.sirix.node.interfaces.NameNode)2