Project

Profile

Help

How to pass a Xml File to XQuery?

Added by Anonymous about 16 years ago

Legacy ID: #4846354 Legacy Poster: Weily (weilera)

Hi there, i cannot figure out how to pass a XML File to Xquery DataSource? I have this implementation: XQDataSource dataSource = new SaxonXQDataSource(); XQConnection connection = dataSource.getConnection(); XQPreparedExpression expression = connection.prepareExpression("'Hello World'"); XQResultSequence resultSequence = expression.executeQuery(); Now i want to have my XML File that i parsed and saved as DataSource to excute other expressions? Thanks a lot!


Replies (4)

Please register to reply

RE: How to pass a Xml File to XQuery? - Added by Anonymous about 16 years ago

Legacy ID: #4846520 Legacy Poster: Michael Kay (mhkay)

You typically supply the document node as the value of the context item by doing bindDocument() on the PreparedExpression object. In the saxon-resources download file there is a sample application called XQJExamples which should give you some ideas. It goes something like this: XQDataSource ds = new SaxonXQDataSource(); XQConnection conn = ds.getConnection(); XQStaticContext sc = conn.getStaticContext(); XQPreparedExpression copy = conn.prepareExpression("<doc>{.}</doc>", sc); copy.bindDocument(XQConstants.CONTEXT_ITEM, new FileInputStream("source.xml") conn.createDocumentType()); XQResultSequence result2 = copy.executeQuery(); I can't say it's my favourite API! Michael Kay http://www.saxonica.com/

RE: How to pass a Xml File to XQuery? - Added by Anonymous about 16 years ago

Legacy ID: #4858347 Legacy Poster: Weily (weilera)

Thanks that worked fine. So what is the purpose of the XQDataSource? I bind the Document to the expression so how can i put my xml file as DataSource? Thanks a lot.

RE: How to pass a Xml File to XQuery? - Added by Anonymous about 16 years ago

Legacy ID: #4858380 Legacy Poster: Michael Kay (mhkay)

>So what is the purpose of the XQDataSource? XQJ uses a lot of client-server terminology; in that context, the XQDataSource is simply the server that you want to connect to. Of course this way of looking at things doesn't make much sense with Saxon where everything is done in-process. In Saxon, the XQDataSource corresponds to a Saxon Configuration.

RE: How to pass a Xml File to XQuery? - Added by Anonymous about 16 years ago

Legacy ID: #4858412 Legacy Poster: Michael Kay (mhkay)

For the benefit of the archives: the next Saxon release (9.1) will have compile() methods to compile a query from a File, an InputStream, or a Reader.

    (1-4/4)

    Please register to reply