Search in sources :

Example 41 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class Matching method containedDescendants.

/**
 * Counts the number of descendant nodes in the subtrees of x and y that are also in the matching.
 *
 * @param nodeX first subtree root node
 * @param nodeY second subtree root node
 * @return number of descendant which have been matched
 */
public long containedDescendants(@Nonnegative final long nodeX, @Nonnegative final long nodeY) {
    long retVal = 0;
    mRtxOld.moveTo(nodeX);
    for (final Axis axis = new DescendantAxis(mRtxOld, IncludeSelf.YES); axis.hasNext(); ) {
        axis.next();
        retVal += mIsInSubtree.get(nodeY, partner(mRtxOld.getNodeKey())) ? 1 : 0;
        if (mRtxOld.getKind() == Kind.ELEMENT) {
            for (int i = 0, nspCount = mRtxOld.getNamespaceCount(); i < nspCount; i++) {
                mRtxOld.moveToNamespace(i);
                retVal += mIsInSubtree.get(nodeY, partner(axis.getTrx().getNodeKey())) ? 1 : 0;
                mRtxOld.moveToParent();
            }
            for (int i = 0, attCount = mRtxOld.getAttributeCount(); i < attCount; i++) {
                mRtxOld.moveToAttribute(i);
                retVal += mIsInSubtree.get(nodeY, partner(axis.getTrx().getNodeKey())) ? 1 : 0;
                mRtxOld.moveToParent();
            }
        }
    }
    return retVal;
}
Also used : DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) DescendantAxis(org.sirix.axis.DescendantAxis)

Example 42 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class StAXDiffSerializer method getElementText.

@Override
public String getElementText() throws XMLStreamException {
    final NodeReadTrx rtx = mAxis.getTransaction();
    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(mAxis.getTransaction().getValue());
    }
    rtx.moveTo(nodeKey);
    return XMLToken.escapeContent(strBuilder.toString());
}
Also used : TextFilter(org.sirix.axis.filter.TextFilter) NodeReadTrx(org.sirix.api.NodeReadTrx) XMLStreamException(javax.xml.stream.XMLStreamException) DescendantAxis(org.sirix.axis.DescendantAxis) FilterAxis(org.sirix.axis.filter.FilterAxis)

Example 43 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class NodeWrapper method expandString.

/**
 * Filter text nodes.
 *
 * @return concatenated String of text node values
 */
private String expandString() {
    final FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.SMALL);
    try {
        final NodeReadTrx rtx = createRtxAndMove();
        final FilterAxis axis = new FilterAxis(new DescendantAxis(rtx), new TextFilter(rtx));
        while (axis.hasNext()) {
            axis.next();
            fsb.append(rtx.getValue());
        }
        rtx.close();
    } catch (final SirixException exc) {
        LOGGER.error(exc.toString());
    }
    return fsb.condense().toString();
}
Also used : TextFilter(org.sirix.axis.filter.TextFilter) FastStringBuffer(net.sf.saxon.tree.util.FastStringBuffer) NodeReadTrx(org.sirix.api.NodeReadTrx) SirixException(org.sirix.exception.SirixException) DescendantAxis(org.sirix.axis.DescendantAxis) FilterAxis(org.sirix.axis.filter.FilterAxis)

Example 44 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class NodeCompTest method testAtomize.

@Test
public void testAtomize() throws SirixXPathException {
    Axis axis = new LiteralExpr(holder.getReader(), -2);
    axis.hasNext();
    axis.next();
    AtomicValue[] value = comparator.atomize(axis);
    assertEquals(value.length, 1);
    assertEquals(holder.getReader().getNodeKey(), value[0].getNodeKey());
    assertEquals("xs:integer", value[0].getType());
    try {
        axis = new DescendantAxis(holder.getReader());
        axis.hasNext();
        comparator.atomize(axis);
    } catch (SirixXPathException e) {
        assertEquals("err:XPTY0004 The type is not appropriate the expression or" + " the typedoes not match a required type as specified by the " + "matching rules.", e.getMessage());
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Aggregations

DescendantAxis (org.sirix.axis.DescendantAxis)44 Axis (org.sirix.api.Axis)27 Test (org.junit.Test)18 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)17 FilterAxis (org.sirix.axis.filter.FilterAxis)16 ChildAxis (org.sirix.axis.ChildAxis)14 QNm (org.brackit.xquery.atomic.QNm)7 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)7 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)7 NameFilter (org.sirix.axis.filter.NameFilter)7 NestedAxis (org.sirix.axis.NestedAxis)6 PostOrderAxis (org.sirix.axis.PostOrderAxis)6 PathSummaryReader (org.sirix.index.path.summary.PathSummaryReader)6 AbstractAxis (org.sirix.axis.AbstractAxis)5 AncestorAxis (org.sirix.axis.AncestorAxis)5 FollowingAxis (org.sirix.axis.FollowingAxis)5 FollowingSiblingAxis (org.sirix.axis.FollowingSiblingAxis)5 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)5 ParentAxis (org.sirix.axis.ParentAxis)5 PrecedingAxis (org.sirix.axis.PrecedingAxis)5