I setRetainLineNumbers("true") on SaxonXQDataSource.
But I am not able to understand how should I escape from xqj and call getSaxonItem() on XdmItem(). Is it done on XQResultSequence.Please explain with code.

I also want to ask, if I have to query multiple xml files in a folder , can it be done through s9API and how.



Message: 5
Date: Tue, 20 Oct 2009 09:21:07 +0100
From: "Michael Kay" <mike@saxonica.com>
Subject: Re: [saxon] How can i get line numbers for each result
       returned        inXQuery.
To: "'Mailing list for the SAXON XSLT and XQuery processor'"
Message-ID: <FDA3E4877AC44CF2AD6036481C574455@Sealion>
Content-Type: text/plain; charset="us-ascii"

First you need to ensure that line numbers are maintained when Saxon builds
document trees using the doc() function. You can do this by calling
setRetainLineNumbers() on the SaxonXQDataSource object.

In your result, your query is returning alternate nodes and atomic values.
To get the line number of a node, you have to escape from XQJ into Saxon
interfaces: call getSaxonItem() on the XdmItem(), and if it is a node, the
result will be an instance of net.sf.saxon.om.NodeInfo, which has a
getLineNumber() method.

Generally, unless you want the portability benefits that come from using XQJ
(that is, you want to write applications that work with multiple XQuery
engines), I would recommend writing Saxon applications using the s9api
interface. It provides access to more of Saxon's capabilities, and is a
better fit to Saxon's architecture. However, I've tried to provide "escape
hatches" so that you can escape from XQJ interfaces into lower level Saxon
interfaces when necessary.


Michael Kay


From: Sweta Kedia [mailto:swetakedia@gmail.com]
Sent: 20 October 2009 05:01
To: saxon-help@lists.sourceforge.net
Subject: [saxon] How can i get line numbers for each result returned


I am trying to use net.saxon.xqj package for Xquery. I am using the result
Sequence to get Item as Stream  and then get its location. But I am getting
-1 everytime. Please help, should i use s9Api    or i can get line number
through Xqj also.

   public void runQuery() {

       try {
           SaxonXQConnection con = (SaxonXQConnection)



           String queryFile="for $s in
008/Quarterly/2nd Quarterly/bvf-20081231/bvf-20081231.xml\")" +
           "//bvf:StockholdersEquityBeforeComprehensiveIncomeNetOfTax, "+
            " $c in
008/Quarterly/2nd Quarterly/bvf-20081231/bvf-20081231.xsd\")" +
            "//element[@name=local-name($s)]  "+
           " return($s, data($c/@name))";
           SaxonXQPreparedExpression expr = (SaxonXQPreparedExpression)

           SaxonXQForwardSequence rs = (SaxonXQForwardSequence)

           while (rs.next()) {
               SaxonXQItem item = (SaxonXQItem) rs.getItem();
               Location local = item.getItemAsStream().getLocation();
               System.out.println(item.getItemAsString(null).toString() + "
at Line: " + local.getLineNumber());

           / rs.close();
       catch (javax.xml.xquery.XQException xq) {
       catch (Exception ex) {


-------------- next part --------------
An HTML attachment was scrubbed...


Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!


saxon-help mailing list
The saxon-help list is archived at http://saxon.markmail.org/

End of saxon-help Digest, Vol 41, Issue 23