Atomic values are not associated with any position in the source document, so they do not have a line number. If you want to know where in the document the atomic value came from, then you need to return the node rather than its value.
 
When your query selects an element, it returns a reference to that element, without any changes. One of the properties of an element is the set of namespaces that are in-scope for that element. When you serialize (display) the node, then the default serialization shows all the in-scope namespaces. To get rid of them you need to make a modified copy of the element, which can be expensive, so it really depends whether the issue is just a cosmetic one, or whether your application really needs a copy of the element without its namespaces.
 
(You should also consider whether the source document really needs to declare all these namespaces anyway. I think people sometimes declare every imaginable namespace in every document just in case it's needed. That's not a practice I would recommend.)
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

 


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

Hi,

I am able to get line numbers  of the results which are instances of Nodeinfo. But for the results which are atomic values i am not able to retreive line numbers.  How can i get line numbers of text content or atomic values.

Also the results contain namespace decalartion for each element retrurned.Why does this occur. For example:

<bvf:StockholdersEquityBeforeComprehensiveIncomeNetOfTax xmlns="http://www.xbrl.org/2003/instance"
                                                         xmlns:link="http://www.xbrl.org/2003/linkbase"
                                                         xmlns:xlink="http://www.w3.org/1999/xlink"
                                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                         xmlns:iso4217="http://www.xbrl.org/2003/iso4217"
                                                         xmlns:xbrli="http://www.xbrl.org/2003/instance"
                                                         xmlns:xbrldi="http://xbrl.org/2006/xbrldi"
                                                         xmlns:ap="http://xbrl.us/dis/ap/2009-01-31"
                                                         xmlns:dei="http://xbrl.us/dei/2009-01-31"
                                                         xmlns:us-gaap="http://xbrl.us/us-gaap/2009-01-31"
                                                         xmlns:bvf="http://www.biovail.com/2008-12-31"
                                                         id="DIM830"
                                                         contextRef="I2008"
                                                         unitRef="USD"
                                                         decimals="-3">1038608000</bvf:StockholdersEquityBeforeComprehensiveIncomeNetOfTax>

I get all the namespace declarations for every elements returned.

Thanks
Sweta

On Tue, Oct 20, 2009 at 6:58 PM, <saxon-help-request@lists.sourceforge.net> wrote:
Send saxon-help mailing list submissions to
       saxon-help@lists.sourceforge.net

To subscribe or unsubscribe via the World Wide Web, visit
       https://lists.sourceforge.net/lists/listinfo/saxon-help
or, via email, send a message with subject or body 'help' to
       saxon-help-request@lists.sourceforge.net

You can reach the person managing the list at
       saxon-help-owner@lists.sourceforge.net

When replying, please edit your Subject line so it is more specific
than "Re: Contents of saxon-help digest..."


Today's Topics:

  1. Re: How can i get line numbers for each result returned in
     XQuery. (Sweta Kedia)
  2. Re: Providing additional information to an extension      function
     (Norman Walsh)
  3. Re: saxon-help Digest, Vol 41, Issue 23 (Michael Kay)


----------------------------------------------------------------------

Message: 1
Date: Tue, 20 Oct 2009 18:22:12 +0530
From: Sweta Kedia <swetakedia@gmail.com>
Subject: Re: [saxon] How can i get line numbers for each result
       returned in     XQuery.
To: saxon-help@lists.sourceforge.net
Message-ID:
       <5cd259e50910200552x68fdb240y5a9d53556bc0889c@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

>
> Hi,
>
> 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.
>
> Thanks
>
Sweta




> ------------------------------
>
> Message: 4
> Date: Tue, 20 Oct 2009 09:30:46 +0530
> From: Sweta Kedia <swetakedia@gmail.com>
> Subject: [saxon] How can i get line numbers for each result returned
>        in      XQuery.
> To: saxon-help@lists.sourceforge.net
> Message-ID:
>        <5cd259e50910192100i412b8578gb5db547785bf13d3@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> 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)
> xqueryConnection.getConnection();
>            con.getStaticContext().declareNamespace("xbrli", "
> http://www.xbrl.org/2003/instance");
>            con.getStaticContext().declareNamespace("bvf", "
> http://www.biovail.com/2008-12-31");
>            con.getStaticContext().declareNamespace("xsi", "
> http://www.w3.org/2001/XMLSchema-instance");
>            con.getStaticContext().declareNamespace("xlink", "
> http://www.w3.org/1999/xlink");
>            con.getStaticContext().setDefaultElementTypeNamespace("
> http://www.xbrl.org/2003/linkbase");
>            con.getStaticContext().setDefaultElementTypeNamespace("
> http://www.w3.org/2001/XMLSchema");
>
>            String queryFile="for $s in
>
> fn:doc(\"C:/Users/A/Documents/Sweta/users/sweta231119791251796126671/Other/2008/Quarterly/2nd
> Quarterly/bvf-20081231/bvf-20081231.xml\")" +
>            "//bvf:StockholdersEquityBeforeComprehensiveIncomeNetOfTax, "+
>             " $c in
>
> fn:doc(\"C:/Users/A/Documents/Sweta/users/sweta231119791251796126671/Other/2008/Quarterly/2nd
> Quarterly/bvf-20081231/bvf-20081231.xsd\")" +
>             "//element[@name=local-name($s)]  "+
>            " return($s, data($c/@name))";
>            SaxonXQPreparedExpression expr = (SaxonXQPreparedExpression)
> con.prepareExpression(queryFile);
>
>            SaxonXQForwardSequence rs = (SaxonXQForwardSequence)
> expr.executeQuery();
>
>            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();
>            con.close();
>        }
>        catch (javax.xml.xquery.XQException xq) {
>            xq.printStackTrace();
>            System.out.println(xq.getStackTrace().toString());
>        }
>        catch (Exception ex) {
>            ex.printStackTrace();
>        }
>    }
>
>
> }
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
> 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'"
>        <saxon-help@lists.sourceforge.net>
> 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.
>
> Regards,
>
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay
>

Message: 3
Date: Tue, 20 Oct 2009 14:14:23 +0100
From: "Michael Kay" <mike@saxonica.com>
Subject: Re: [saxon] saxon-help Digest, Vol 41, Issue 23
To: "'Mailing list for the SAXON XSLT and XQuery processor'"
       <saxon-help@lists.sourceforge.net>
Message-ID: <4CD76B77E72143B78D6791A8A734EFDD@Sealion>
Content-Type: text/plain; charset="us-ascii"

Sorry, I meant XQItem, not XdmItem. You can call getItem() on the
XQResultSequence to get the current item, and then getSaxonItem to get the
underlying Saxon Item, which in this case will be a NodeInfo.

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

Use the collection() function. See

http://www.saxonica.com/documentation9.2/sourcedocs/collections.html

for how Saxon handles collections.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay


 _____

From: Sweta Kedia [mailto:swetakedia@gmail.com]
Sent: 20 October 2009 13:45
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] saxon-help Digest, Vol 41, Issue 23



Hi,

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.

Thanks


Sweta