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;
}
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());
}
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();
}
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());
}
}
Aggregations