First of all Thanks for your replay.
As per your suggestion to bind multiple documents, I tried it and it's works for me.
 
But now I stuck at one point. I bind a document and get result from it and now I want to use this result for next query.
I means I want to pass this result as an input for next query. I tried below code but it gives me an error.
 

FileInputStream reader =

new
FileInputStream(fileName);

XQItem itemDoc = con.createItemFromDocument(reader, null, null);

 

XQPreparedExpression exp = con.prepareExpression("declare variable $lab external;<result>{$lab}</result>");

exp.bindItem(

new QName("lab") , itemDoc);

XQResultSequence result = exp.executeQuery();

System.

out.println("result=\n" + result.getSequenceAsString(null));

/*   I got whole document as result in result tag

   Now I want to process on this result */

 

XQPreparedExpression copy = con.prepareExpression(

".");

XQItem xqi= result.getItem();

copy.bindItem(XQConstants.

CONTEXT_ITEM, xqi);

XQSequence result2 = copy.executeQuery();

System.

out.println("Result = \n" + result2.getSequenceAsString(null));

 

/* But I am getting below error

The XQSequence is positioned before the first item

Can you suggest me how can I process on this result set */

And one more thing I want to load multiple documents once and wants to use those documents on different queries no. of times.

So how can I do it in efficient way ?

can you suggest me any way ?

Thanks,

Kunal Chauhan

 

 

 



 
On Thu, Mar 3, 2011 at 2:33 AM, Hans-Juergen Rennau <hrennau@yahoo.de> wrote:
Hi Kunal,

this question were better asked on a general XQuery list (e.g.
talk@x-query.com), as it is not Saxon specific. It is not Saxon specific as you
are using a standard API - the XQJ - rather than Saxon's S9API. But here come
some suggestions.

The context item can only be a single item - for example a single XML document,
or a single string. In order to let a query process more than one input item,
you can use external variables, declared like this:
declare variable $foo external;

A variable can be bound to a sequence of items. How to provide this sequence
depends on the API you use. You use, as the snippet showed, the XQJ API.
There, you have to provide an XQSequence object...

In the simplest case the object is the result of another query - than you do not
have to construct it yourself. Otherwise, you use this method offered by the
XQConnection object:
   createSequence(java.util.Iterator i)

Here comes a full example:

SaxonXQDataSource ds = new SaxonXQDataSource();
XQConnection co = ds.getConnection();
 
// procure nodes ...
Document d1 = ...;
Document d2 = ...;
 
// build an XQSequence object
List<Node> docList = new ArrayList<Node>();
docList.add(d1);
docList.add(d2);
XQSequence docs = co.createSequence(docList.iterator());
 
// bind XQSequence object to an external variable
XQExpression ex = co.createExpression();
ex.bindSequence(new QName("", "docs"), docs);
 
// execute query
XQSequence result = ex.executeQuery(
"declare variable $docs external; <result>{$docs}</result>");
 
System.out.println("result=\n" + result.getSequenceAsString(null));
 
~~~
 
In the common case that the documents are read from files and you do not want to
build DOM objects yourself, it would be a little more complicated. This would
work:
 
FileInputStream is1 = new FileInputStream("foo.xml");
FileInputStream is2 = new FileInputStream("bar.xml");
XQItem i1 = co.createItemFromDocument(is1, null, null);
XQItem i2 = co.createItemFromDocument(is2, null, null);
List<XQItem> itemList = new ArrayList<XQItem>();
itemList.add(i1);
itemList.add(i2);
XQSequence items = co.createSequence(itemList.iterator());
 
~~~
 
But an alternative would be to provide only the file URIs to the query and let
the query itself retrieve the documents. This would then be like so:
 List<String> fileNameList = new ArrayList<String>();
fileNameList.add("foo.xml");
fileNameList.add("bar.xml");
XQSequence fileNames = co.createSequence(fileNameList.iterator());
With kind regards,
Hans-Juergen
 
>>> You wrote:
  
From: Kunal Chauhan <mail4ck@gmail.com>
Subject: [saxon] saxon-help
To: saxon-help@lists.sourceforge.net

Can any one suggest me that how can we bind multiple xml file as
input source to SaxonXQExpression

for ex:
xqe = (SaxonXQExpression)con.createExpression();
xqe.bindItem(XQConstants.CONTEXT_ITEM, itemDoc);
xqe.bindItem(XQConstants.CONTEXT_ITEM, itemDocLab);


as above example i want to bind 2 document itemDoc and itemDocLab to a
single SaxonXQExpression object



------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help