That looks reasonable at first glance.
 

Regards,

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



From: Geet Gangwar [mailto:geetgangwar@gmail.com]
Sent: 23 March 2010 14:27
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] Firing multiple Xquery on a single file

Hi Michael

I suggested by you I have changed my code, can u tell me is it the write way to do it: I am mentioned my code below

            xqc.getStaticContext().declareNamespace("link", "http://www.xbrl.org/2003/linkbase");
            xqc.getStaticContext().declareNamespace("xlink", "http://www.w3.org/1999/xlink");
            xqc.getStaticContext().declareNamespace("xbrli", "http://www.xbrl.org/2003/instance");

            Document doc = XMLReader.getReader("D:/biovail/bvf-20081231.xml");
            //String filename = "D:/biovail/bvf-20081231.xml";
            FileInputStream doc1  = new  FileInputStream("D:/biovail/bvf-20081231.xml");
            XMLInputFactory factory  = XMLInputFactory.newInstance();
            XMLStreamReader reader  = factory.createXMLStreamReader(doc1);
                       
           
            sxqpe = (SaxonXQPreparedExpression) xqc.prepareExpression("declare variable $d as document-node() external; " +
                    "let $x := $d//link:schemaRef return $x[@xlink:type]");

            sxqpe.bindDocument(new QName("d"), reader, null);



On Tue, Mar 23, 2010 at 7:06 PM, Michael Kay <mike@saxonica.com> wrote:


>I did using the way you suggested, but Instead of using
connection.createItemFromDocument() I used the bindNode method.

Using the DOM with Saxon is recommended only if you already have a DOM for
some other reason. Querying a DOM is 4-10 times slower than querying Saxon's
native tree representation. So you should never create a DOM for Saxon input
unless there is a very good reason.

>Now I want to get the attribute of a particular node form my file. I am
getting an erro like:

       javax.xml.xquery.XQException: Cannot create an attribute node (type)
whose parent is a document node

       I am attaching the sample code below, Please tell me what is wrong

Your query returns an attribute node, and you then attempt to serialize it
using getItemAsString(). This is defined to do serialization as defined in
the W3C Serialization spec. Section 2 rule 7 of that spec says that
serializing an attribute node is an error. (Perhaps you just want the string
value of the attribute?) Here is the rule:

7: It is a serialization error [err:SENR0001] if an item in S6 is an
attribute node or a namespace node. Otherwise, construct a new sequence, S7,
that consists of a single document node and copy all the items in the
sequence, which are all nodes, as children of that document node.

(Saxon is doing the second part: creating a document node and copying the
attribute to it, which explains why the error message says that you can't
have an attribute node as a child of a document node)

Note also that node.getLineNumber() won't give you anything useful if the
input was a DOM - DOM nodes don't provide line number information.

Regards,

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



       SaxonXQConnection xqc = (SaxonXQConnection)
xqueryConnection.getConnection();
       SaxonXQPreparedExpression sxqpe = null;
               XQResultSequence xqs;
               try {
                   //sxqpe.bindNode(varname, value, type)
                   xqc.getStaticContext().declareNamespace("link",
"http://www.xbrl.org/2003/linkbase");
                   xqc.getStaticContext().declareNamespace("xlink",
"http://www.w3.org/1999/xlink");
                   xqc.getStaticContext().declareNamespace("xbrli",
"http://www.xbrl.org/2003/instance");

                   Document doc =
XMLReader.getReader("D:/biovail/bvf-20081231.xml");
                   sxqpe = (SaxonXQPreparedExpression)
xqc.prepareExpression("/xbrli:xbrl/link:schemaRef/@type");
                   // execute a first query and process the query results
                   sxqpe.bindNode(XQConstants.CONTEXT_ITEM, doc, null);
                   xqs = sxqpe.executeQuery();
                   // Consume results
                   while (xqs.next()) {
                       SaxonXQItem item = (SaxonXQItem) xqs.getItem();

                       if (item.getSaxonItem() instanceof NodeInfo) {
                           NodeInfo node = (NodeInfo) item.getSaxonItem();
                           System.out.println("Error in line number  " +
node.getLineNumber() + " = " + item.getItemAsString(null).toString());
                       }
                       else if (item.getSaxonItem() instanceof AtomicValue)
{
                           System.err.println("\nValidation Error in File
:" + item.getAtomicValue());
                       }
                   }
               }
               catch (Exception e) {
                   e.printStackTrace();
               }

       Regards

       Geet


       On Tue, Mar 23, 2010 at 5:38 PM, Michael Kay <mike@saxonica.com>
wrote:


               If you must use XQJ, then

               (1) create an XQConnection

               (2) do connection.createItemFromDocument() to build the
document (using any variant of this method)

               (3) create an XQPreparedExpression representing the compiled
query

               (4) on the XQPreparedExpression, use
bindItem(XQConstants.CONTEXT_ITEM, item) to set the context item to the
document built in step (2)

               (5) run the query

               (6) repeat steps 3/4/5 ad nauseam.

               The main thing to beware of is that the XQPreparedExpression
holds both the compiled query and its dynamic context, which means it cannot
be used in multiple threads. With XQJ, if you want to use the same query in
multiple threads you need to compile it once for each one.

               Regards,

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


________________________________

                                               From: Geet Gangwar
[mailto:geetgangwar@gmail.com]

                       Sent: 23 March 2010 11:41
                       To: Mailing list for the SAXON XSLT and XQuery
processor
                       Subject: Re: [saxon] Firing multiple Xquery on a
single file


                       Thanks Michael,

                       Can you tell me how to achieve the same thing using
saxonXQJ api.

                       Regards

                       Geet


                       On Tue, Mar 23, 2010 at 4:37 PM, Michael Kay
<mike@saxonica.com> wrote:


                               Of course. Which API are you using?

                               In s9api:

                               (1) create a Processor

                               (2) create a DocumentBuilder and use it to
build the source document (as an XdmNode)

                               (3) create an XQueryCompiler, compile the
query, load it, supply the document created in step (2) using
XQueryEvaluator.setContextItem(), and run the query

                               (4) repeat step (3) ad nauseam. (Or run the
same query multiple times with different parameters).

                               Regards,

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


________________________________

                                       From: Geet Gangwar
[mailto:geetgangwar@gmail.com]
                                       Sent: 23 March 2010 10:29
                                       To: saxon-help@lists.sourceforge.net
                                       Subject: [saxon] Firing multiple
Xquery on a single file


                                       Hi,

                                       Is there a way where I can load the
XML file once and can fire multiple XQuery thereafter. I am not able to
figure out how that can be done. Please help me.

                                       Regards

                                       Geet.




----------------------------------------------------------------------------
--
                               Download Intel&#174; Parallel Studio Eval
                               Try the new software tools for yourself.
Speed compiling, find bugs
                               proactively, and fine-tune applications for
parallel performance.
                               See why Intel Parallel Studio got high marks
during beta.
                               http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
                               saxon-help mailing list archived at
http://saxon.markmail.org/
                               saxon-help@lists.sourceforge.net
<http://saxon.markmail.org/%0Asaxon-help@lists.sourceforge.net>

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





----------------------------------------------------------------------------
--
               Download Intel&#174; Parallel Studio Eval
               Try the new software tools for yourself. Speed compiling,
find bugs
               proactively, and fine-tune applications for parallel
performance.
               See why Intel Parallel Studio got high marks during beta.
               http://p.sf.net/sfu/intel-sw-dev
               _______________________________________________
               saxon-help mailing list archived at
http://saxon.markmail.org/
               saxon-help@lists.sourceforge.net
<http://saxon.markmail.org/%0Asaxon-help@lists.sourceforge.net>
               https://lists.sourceforge.net/lists/listinfo/saxon-help





------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net

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