reader.parse(xpathExpression);
XPathExpr xpath = handler.getXPathExpr();
Expr expr = xpath.getRootExpr();
if (!(expr instanceof LocationPath)) {
throw new SAXPathException("Invalid XPath expression '" + xpathExpression + "'. Selector must be a LocationPath expression. Is '" + expr.getText() + "'.");
}
LocationPath path = (LocationPath) expr;
List<Step> steps = path.getSteps();
for (int i = 0; i < steps.size(); i++) {
Step step = steps.get(i);
try {
if(step.getAxis() == Axis.ATTRIBUTE && i < steps.size() - 1) {
// Attribute steps are only supported as the last step...
throw new SAXPathException("Attribute axis steps are only supported at the end of the expression. '" + step.getText() + "' is not at the end.");
} else if(step.getAxis() == Axis.DESCENDANT_OR_SELF) {
selectorSteps.add(new SelectorStep(xpathExpression, "**"));
} else if(step.getAxis() != Axis.CHILD && step.getAxis() != Axis.ATTRIBUTE) {
throw new SAXPathException("XPath step '" + step.getText() + "' not supported.");
} else {
if(i == steps.size() - 2) {
Step nextStep = steps.get(i + 1);
if(nextStep.getAxis() == Axis.ATTRIBUTE) {
selectorSteps.add(new SelectorStep(xpathExpression, step, nextStep));
// We end here. The next step is the last step and we've merged it into
// the last evaluator...
break;
} else {
selectorSteps.add(new SelectorStep(xpathExpression, step));
}
} else {
selectorSteps.add(new SelectorStep(xpathExpression, step));
}
}
} catch (SAXPathException e) {
throw new SAXPathException("Error processing XPath selector expression '" + xpathExpression + "'.", e);
} catch (Exception e) {
throw new SAXPathException("Error building step evaluator.", e);
}
}
}
if(isRooted) {