getRef function
Parses xpath into a TreeReference, turning numeric predicates into
multiplicities: /data/child[2] refers to the second child
(multiplicity 1), [-1] means unbound and [@template] the template.
To compare with references from the engine, give every step a
multiplicity (/data/q[1]), because a step without one could be an
unbound repeat.
Port of org.javarosa.test.Scenario.getRef.
Implementation
TreeReference getRef(String xpath) {
if (javaTrim(xpath).isEmpty) return const TreeReference.relative();
var ref = (parseXPath(xpath) as XPathPathExpr).toTreeReference();
for (var i = 0; i < ref.size; i++) {
final multiplicity = _multiplicityFromPredicate(ref.predicatesAt(i));
if (multiplicity != null) {
ref = ref.withMultiplicity(i, multiplicity).removePredicates(i);
}
}
return ref;
}