Hello, I would like to use XQuery to pose queries on an XML document using Java (JDOM). Which are the tools and the techniques necessary for that? If it is possible, I will like a document which treats an example on how using and testin Xquery with an XML document, the whole with Java.
Thank u Claudio.
I wrote this class to test XQuery request with the SAXON processor. But it always posts me an error of compilation in the class Configuration, although all my classes all are under the same repertory as the class Xquery hand (in java/jdk1.5/bin).
Xquery.java
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 (<Root> <Hello>Hi! "
+ "</Hello> <Name>Nice</Name> </Root>) "
+ "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();
}
}
}