关于XQJ方面的问题

cainiaoyunyin 2011-10-27 12:14:08

import javax.xml.namespace.QName;
import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQConstants;
import javax.xml.xquery.XQDataSource;
import javax.xml.xquery.XQException;
import javax.xml.xquery.XQExpression;
import javax.xml.xquery.XQItemType;
import javax.xml.xquery.XQResultSequence;
import net.sf.saxon.xqj.SaxonXQDataSource;
public class XQJTest {

public static void main(String args[]) {
XQConnection conn = null;
XQExpression expression = null;
XQResultSequence resultSeq = null;
final String fileName = "D:/bookstore.xml";
try {

XQDataSource dataSource = new SaxonXQDataSource();
conn = dataSource.getConnection();
StringBuffer queryStr = new StringBuffer();
queryStr.append("declare variable $docName as xs:string external;\n");
queryStr.append("for $title in reverse(doc($docName)/bookstore/book/title )");
queryStr.append(" return string($title)");
expression = conn.createExpression();
expression.bindString(new QName("docName"), fileName, conn.createAtomicType(XQItemType.XQBASETYPE_STRING));
resultSeq = expression.executeQuery(queryStr.toString());
while (resultSeq.next()) {
System.out.println(resultSeq.getAtomicValue());
resultSeq.getPosition();
}
} catch (XQException e) {
e.printStackTrace();
} finally {
closeResultSequence(resultSeq);
closeExpression(expression);
closeConnection(conn);
}

}
自从加了这句resultSeq.getPosition();就出现如下错误:
javax.xml.xquery.XQException: Sequence is forwards-only
at net.sf.saxon.xqj.SaxonXQForwardSequence.getPosition(SaxonXQForwardSequence.java:157)
at org.cjxml.xq.XQJTest.main(XQJTest.java:49)
为什么呢?请教高手....
...全文
59 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
高性能WEB开发
创建于2008-07-01

2.5w+

社区成员

高性能WEB开发
申请成为版主
帖子事件
创建了帖子
2011-10-27 12:14
社区公告
暂无公告