20 import ca.uqac.lif.cep.xml.XPathFunction;
21 import ca.uqac.lif.cep.fol.ForAll;
22 import ca.uqac.lif.cep.functions.ContextVariable;
23 import ca.uqac.lif.cep.functions.FunctionTree;
24 import ca.uqac.lif.cep.util.Bags;
25 import ca.uqac.lif.cep.util.Numbers;
26 import ca.uqac.lif.cep.xml.ParseXml;
27 import ca.uqac.lif.xml.XmlElement;
35 public static void main(String[] args)
41 FunctionTree d =
new FunctionTree(
42 new Bags.ApplyToAll(Numbers.numberCast),
43 new XPathFunction(
"doc/a/b/text()"));
44 FunctionTree f =
new FunctionTree(Numbers.isLessThan,
45 new ContextVariable(
"z"),
46 new FunctionTree(Numbers.numberCast,
47 new FunctionTree(Bags.anyElement,
48 new XPathFunction(
"doc/a[b=$z]/c/text()"))));
49 ForAll fa =
new ForAll(
"z", d, f);
54 Object[] out =
new Object[1];
55 XmlElement x = ParseXml.instance.getValue(
"<doc>\n" 56 +
"<a><b>1</b><c>10</c></a>\n" 57 +
"<a><b>2</b><c>15</c></a>\n" 59 fa.evaluate(
new Object[] {x}, out);
60 System.out.println(out[0]);
64 x = ParseXml.instance.getValue(
"<doc>\n" 65 +
"<a><b>1</b><c>10</c></a>\n" 66 +
"<a><b>20</b><c>15</c></a>\n" 68 fa.evaluate(
new Object[] {x}, out);
69 System.out.println(out[0]);
Evaluate JPath expressions on JSON elements.