use of org.sirix.api.Axis in project sirix by sirixdb.
the class DBNode method expandString.
/**
* Filter text nodes.
*
* @return concatenated String of text node values
*/
private String expandString() {
final StringBuilder buffer = new StringBuilder();
final Axis axis = new DescendantAxis(mRtx);
while (axis.hasNext()) {
axis.next();
if (mRtx.isText()) {
buffer.append(mRtx.getValue());
}
}
return buffer.toString();
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class XPathParser method parsePathExpr.
/**
* Parses the the rule PathExpr according to the following production rule:
* <p>
* [25] PathExpr ::= ("/" RelativePathExpr?) | ("//" RelativePathExpr) | RelativePathExpr .
* </p>
*
* @throws SirixXPathException
*/
private void parsePathExpr() throws SirixXPathException {
if (is(TokenType.SLASH, true)) {
// path expression starts from the root
mPipeBuilder.addStep(new DocumentNodeAxis(getTransaction()));
final TokenType type = mToken.getType();
if (type != TokenType.END && type != TokenType.COMMA) {
// all immediately following keywords or '*' are nametests, not
// operators
// leading-lone-slash constrain
parseRelativePathExpr();
}
} else if (is(TokenType.DESC_STEP, true)) {
// path expression starts from the root with a descendant-or-self
// step
mPipeBuilder.addStep(new DocumentNodeAxis(getTransaction()));
final Axis mAxis = new DescendantAxis(getTransaction(), IncludeSelf.YES);
mPipeBuilder.addStep(mAxis);
parseRelativePathExpr();
} else {
parseRelativePathExpr();
}
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class XPathParser method parseForwardAxis.
/**
* Parses the the rule ForwardAxis according to the following production rule:
* <p>
* [30] ForwardAxis ::= <"child" "::"> | <"descendant" "::"> | <"attribute" "::"> | <"self" "::">
* | <"descendant-or-self" "::"> | <"following-sibling" "::"> | <"following" "::"> | <"namespace"
* "::"> .
* </p>
*
* @return axis
* @throws SirixXPathException
*/
private Axis parseForwardAxis() throws SirixXPathException {
final Axis axis;
if (is("child", true)) {
axis = new ChildAxis(getTransaction());
} else if (is("descendant", true)) {
axis = new DescendantAxis(getTransaction());
} else if (is("descendant-or-self", true)) {
axis = new DescendantAxis(getTransaction(), IncludeSelf.YES);
} else if (is("attribute", true)) {
axis = new AttributeAxis(getTransaction());
} else if (is("self", true)) {
axis = new SelfAxis(getTransaction());
} else if (is("following", true)) {
axis = new FollowingAxis(getTransaction());
} else if (is("following-sibling", true)) {
axis = new FollowingSiblingAxis(getTransaction());
} else {
is("namespace", true);
throw EXPathError.XPST0010.getEncapsulatedException();
}
consume(TokenType.COLON, true);
consume(TokenType.COLON, true);
return axis;
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class XPathParser method parseRelativePathExpr.
/**
* Parses the the rule RelativePathExpr according to the following production rule:
* <p>
* [26] RelativePathExpr ::= StepExpr (("/" | "//") StepExpr)* .
* </p>
*
* @throws SirixXPathException
*/
private void parseRelativePathExpr() throws SirixXPathException {
parseStepExpr();
while (mToken.getType() == TokenType.SLASH || mToken.getType() == TokenType.DESC_STEP) {
if (is(TokenType.DESC_STEP, true)) {
final Axis axis = new DescendantAxis(getTransaction(), IncludeSelf.YES);
mPipeBuilder.addStep(axis);
} else {
// in this case the slash is just a separator
consume(TokenType.SLASH, true);
}
parseStepExpr();
}
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class MultipleCommitTest method testAttributeRemove.
@Test
public void testAttributeRemove() throws SirixException {
DocumentCreater.create(holder.getWriter());
holder.getWriter().commit();
holder.getWriter().moveToDocumentRoot();
final AbstractAxis postorderAxis = new PostOrderAxis(holder.getWriter());
while (postorderAxis.hasNext()) {
postorderAxis.next();
if (holder.getWriter().getKind() == Kind.ELEMENT && holder.getWriter().getAttributeCount() > 0) {
for (int i = 0, attrCount = holder.getWriter().getAttributeCount(); i < attrCount; i++) {
holder.getWriter().moveToAttribute(i);
holder.getWriter().remove();
}
}
}
holder.getWriter().commit();
holder.getWriter().moveToDocumentRoot();
int attrTouch = 0;
final Axis descAxis = new DescendantAxis(holder.getWriter());
while (descAxis.hasNext()) {
descAxis.next();
if (holder.getWriter().getKind() == Kind.ELEMENT) {
for (int i = 0, attrCount = holder.getWriter().getAttributeCount(); i < attrCount; i++) {
if (holder.getWriter().moveToAttribute(i).hasMoved()) {
attrTouch++;
} else {
throw new IllegalStateException("Should never occur!");
}
}
}
}
assertEquals(0, attrTouch);
}
Aggregations