Code Examples
A repository of 155 code examples for BeepBeep
XPathExample.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package xml;
19 
20 import ca.uqac.lif.cep.xml.XPathFunction;
21 import ca.uqac.lif.cep.xml.ParseXml;
22 import ca.uqac.lif.xml.XmlElement;
23 
24 /**
25  * Evaluate JPath expressions on JSON elements.
26  * @author Sylvain HallĂ©
27  */
28 public class XPathExample
29 {
30  public static void main(String[] args)
31  {
32  ///
33  Object[] out = new Object[1];
34  ParseXml.instance.evaluate(new Object[]{
35  "<doc>\n"
36  + "<a><b>1</b><c>10</c></a>\n"
37  + "<a><b>2</b><c>15</c></a>\n"
38  + "<d>123</d>\n"
39  + "</doc>"}, out);
40  XmlElement x = (XmlElement) out[0];
41  System.out.println(
42  new XPathFunction("doc/d/text()").getValue(x));
43  System.out.println(
44  new XPathFunction("doc/a/b").getValue(x));
45  System.out.println(
46  new XPathFunction("doc/a[b=2]/c").getValue(x));
47  ///
48  }
49 }
Evaluate JPath expressions on JSON elements.