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

On Tue, Oct 20, 2009 at 1:51 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: newbie: using saxon, but configuring xalan as default
     (Andrew Welch)
  2. Re: newbie: using saxon, but configuring xalan as default
     (Michael Kay)
  3. Re: newbie: using saxon, but configuring xalan as default
     (Martin Trummer)
  4. How can i get line numbers for each result returned in
     XQuery. (Sweta Kedia)
  5. Re: How can i get line numbers for each result returned
     inXQuery. (Michael Kay)


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

Message: 1
Date: Mon, 19 Oct 2009 17:46:49 +0100
From: Andrew Welch <andrew.j.welch@gmail.com>
Subject: Re: [saxon] newbie: using saxon, but configuring xalan as
       default
To: Mailing list for the SAXON XSLT and XQuery processor
       <saxon-help@lists.sourceforge.net>
Message-ID:
       <74a894af0910190946n5e40bd30s6d3cba3b3565ae5d@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

2009/10/19 Michael Kay <mike@saxonica.com>:
> See
> http://java.sun.com/javase/6/docs/api/javax/xml/transform/TransformerFactory
> .html#newInstance() for a description of the process followed to select a
> transformation engine. The classpath comes into play when the first two
> steps fail to find anything, so the "Services API" is used, which basically
> involves an (expensive!) search of the classpath.

Is that expensive search of the classpath much different to reflection
in general?   As far as Im aware, reflection used to be expensive, but
now it's negligible...



--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/



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

Message: 2
Date: Mon, 19 Oct 2009 18:11:26 +0100
From: "Michael Kay" <mike@saxonica.com>
Subject: Re: [saxon] newbie: using saxon, but configuring xalan as
       default
To: "'Mailing list for the SAXON XSLT and XQuery processor'"
       <saxon-help@lists.sourceforge.net>
Message-ID: <7176BD42B80441CDB6967B99A364D602@Sealion>
Content-Type: text/plain;       charset="us-ascii"

> Is that expensive search of the classpath much different to reflection
> in general?   As far as Im aware, reflection used to be expensive, but
> now it's negligible...

I would have thought it's more like a class loading than reflection.

It may be my information is out of date. But it certainly has been true at
some time that instantiating a TransformerFactory the JAXP way is VERY
expensive.

Regards,

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




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

Message: 3
Date: Mon, 19 Oct 2009 20:33:32 +0200
From: "Martin Trummer" <martin.trummer@24act.com>
Subject: Re: [saxon] newbie: using saxon, but configuring xalan as
       default
To: "Mailing list for the SAXON XSLT and XQuery processor"
       <saxon-help@lists.sourceforge.net>
Message-ID:
       <9524F2E32CF01A46B4DC307EFBDD0CD508B3D5@winserv.24act.local>
Content-Type: text/plain;       charset="iso-8859-1"

@Michael

thanks for the link
now the process is very clear

I also think that setting the system property explicit to the (former) java default of
'com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl'
which can be found in:
javax.xml.transform.TransformerFactory.newInstance()
is the correct way.

Unfortunatly this was really a lot of work

Since we are using a quite complex combination of serveral tools and build managements.
Especially maven2 was a problem, because you cannot simple set system properties in the maven config files (pom.xml, profiles.xml).
And to avoid the need to always set the env-var explicitly I had to develop my own maven-plugin as a workaround.

But now everything seems to work again.

Thanks a lot

@Kermit

in eclipse
 * I directly added it to the 'Build Path' which also affects several Run-Configurations and External-Tool Configurations.
 * I had to explicitly reset the TransformerFactoryImpl again in the corresponding configurations

maven-build
 * I had to develop a new maven-plugin, so that I could set the desired env.vars

ad Concurrency/Synchronization)
I plan to create one TransformerFactory-Singleton at startup and a new Transformer for each thread.
If I understood the java-docs right, this should be ok, but please correct me, if I'm mistaken

-----Urspr?ngliche Nachricht-----
Von: Michael Kay [mailto:mike@saxonica.com]
Gesendet: Montag, 19. Oktober 2009 17:53
An: 'Mailing list for the SAXON XSLT and XQuery processor'
Betreff: Re: [saxon] newbie: using saxon, but configuring xalan as default

See
http://java.sun.com/javase/6/docs/api/javax/xml/transform/TransformerFactory
.html#newInstance()
for a description of the process followed to select a transformation engine. The classpath comes into play when the first two steps fail to find anything, so the "Services API" is used, which basically involves an (expensive!) search of the classpath.

In your situation I would recommend:

(a) set the system property javax.xml.transform.TransformerFactory so that Xalan is loaded

(b) when you want to use Saxon, instantiate its TransformerFactory explicitly, rather than via the JAXP newInstance() method : call new net.sf.saxon.TransformerFactoryImpl().

Regards,

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

> -----Original Message-----
> From: Martin Trummer [mailto:martin.trummer@24act.com]
> Sent: 19 October 2009 16:19
> To: Mailing list for the SAXON XSLT and XQuery processor
> Subject: Re: [saxon] newbie: using saxon, but configuring xalan as
> default
>
> oh - yeah, seems I have mixe dup some things here
>
> the topic should not read xalan, but xerces
>
> setting the transformer factory explicitly works, but unfortunately
> this leads to other problems.
>
> so: could you please tell me, why simply adding the saxon.jar to the
> classpath already changes the default?
>
> I thought it should be like this:
>  * I have to add the saxon.jar to the classpath
>  * and if I really want it to be the default, I have to set the
> corresponding system parameters to use it
>  * and if I don't (what I prefer), I simply pass the
> saxon-factoryClassName to the newInstance() method of the factory for
> the one special case, where I need it and everything else still works
>
>
>
> -----Urspr?ngliche Nachricht-----
> Von: Martin Honnen [mailto:Martin.Honnen@arcor.de]
> Gesendet: Montag, 19. Oktober 2009 16:53
> An: Mailing list for the SAXON XSLT and XQuery processor
> Betreff: Re: [saxon] newbie: using saxon, but configuring
> xalan as default
>
> Martin Trummer wrote:
>
> > I need to use saxon for one specific transformation, so I added the
> > saxonhe-9.0.2.2.jar to the class-path and now it seems that
> saxon is
> > the system default.
> >
> > Is this it possible at all, or did I miss something?
> >
> > If it's possible, is this the desired behaviour?
> >
> > If so: how can I change it?
> > I already tried to pass the following vars to the
> application when it
> > is
> > run:
> >
> >
> -Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces
> .internal.
> > jaxp.SAXParserFactoryImpl
> >
> >
> -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.Docu
> > me
> > ntBuilderFactoryImpl
> > but this does not seem to change anything.
>
> Well neither Saxon nor Xalan is a DOM or SAX parser, they are
> XSLT processors.
> According to
> http://java.sun.com/javase/6/docs/api/javax/xml/transform/Tran
> sformerFactory.html#newInstance()
> you need to set the property
> javax.xml.transform.TransformerFactory
> if you want to set the JAXP transformer factory.
>
>
> --
>
>       Martin Honnen
>       http://msmvps.com/blogs/martin_honnen/
>
> --------------------------------------------------------------
> ----------------
> 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!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> saxon-help mailing list archived at
> http://saxon.markmail.org/ saxon-help@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
> --
> This message was scanned by ESVA and is believed to be clean.
> Click here to report this message as spam.
> http://h0stname/cgi-bin/learn-msg.cgi?id=3D5E629608.ED9D7
>
>
>
> --------------------------------------------------------------
> ----------------
> 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!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> saxon-help mailing list archived at
> http://saxon.markmail.org/ saxon-help@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
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!
http://p.sf.net/sfu/devconference
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/saxon-help

--
This message was scanned by ESVA and is believed to be clean.
Click here to report this message as spam.
http://h0stname/cgi-bin/learn-msg.cgi?id=68AFD29608.44652





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

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


 _____

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
inXQuery.


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/2
003/linkbase
");

con.getStaticContext().setDefaultElementTypeNamespace("http://www.w3.org/200
1/XMLSchema
");

           String queryFile="for $s in
fn:doc(\"C:/Users/A/Documents/Sweta/users/sweta231119791251796126671/Other/2
008/Quarterly/2nd Quarterly/bvf-20081231/bvf-20081231.xml\")" +
           "//bvf:StockholdersEquityBeforeComprehensiveIncomeNetOfTax, "+
            " $c in
fn:doc(\"C:/Users/A/Documents/Sweta/users/sweta231119791251796126671/Other/2
008/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...

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

------------------------------------------------------------------------------
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!
http://p.sf.net/sfu/devconference

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

_______________________________________________
saxon-help mailing list
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help
The saxon-help list is archived at http://saxon.markmail.org/

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