вівторок, 27 листопада 2007 р.

JSR 225 XQuery API for Java

Этот JSR определяет АПИ для выполнения Xquery вызовов и для работы с результатами. XQJ представляет для Xquery тоже что и JDBC для SQL. АПИ XQJ имеет много общего с высокоуровневыми концепциями JDBC ( DataSource, Connection и др.) но также поддерживает специфические концепции Xquery — такие как статические и динамические фазы, XML-ориентированное получение данных и др.
Пример:
...
// establish a connection to the XQuery engine
XQConnection conn = xqds.getConnection();
// create an expression object that is later used
// to execute an XQuery expression
XQExpression expr = conn.createExpression();
// the XQuery expression to be executed
String es = "for $n in fn:doc('catalog.xml')//item " +
"return fn:data($n/name)";
// execute the XQuery expression
XQResultSequence result = expr.executeQuery(es);
// process the result (sequence) iteratively
while (result.next()) {
// retrieve the current item of the sequence as a String
String str = result.getAtomicValue();
System.out.println("Product name: " + str);
}
// free all resources allocated for the result
result.close();
// free all resources allocated for the expression
expr.close();
// free all resources allocated for the connection
conn.close();
...

Немає коментарів: