1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import java.io.*;
import Configuration.java;
import NodeInfo.java;
import DynamicQueryContext.java;
import StaticQueryContext.java;
import XQueryExpression.java;
import XPathException.java;
public class Xquery {
public static void main(String[] args) {
Configuration conf = new Configuration();
StaticQueryContext staticContext = new StaticQueryContext(conf);
String query = "for $q in ( Hi! "
+ " Nice ) "
+ "return <HelloExample>{xs:string($q/Hello)} "
+ "{xs:string($q/Name)}</HelloExample> ";
//QueryProcessor qp = new QueryProcessor(conf, staticContext);
try {
XQueryExpression xqe = staticContext.compileQuery(query);
DynamicQueryContext dc = new DynamicQueryContext(conf);
NodeInfo ob = (NodeInfo) xqe.evaluateSingle(dc);
System.out.print(ob.getRoot());
// It prints Hi! Nice in console
} catch (XPathException e) {
e.printStackTrace();
}
}
} |
Partager