|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
How to use XQuery from s9apiHi,
I'm still working on my search engine for XML documents... When I make a request my search engine find relevant elements from an index data structure and return a list of XML element URIs: ex: document("./path/to/document.xml")//path/to/element So I think to use XQueries to fetch all relevant elements in one result XML tree. I try this Java code but an exception rise and I don't know how to handle it... String xQuery = "for $n in document('./collection/d001.xml')//p\n" + "return $n"; Processor processor = new Processor(false); XQueryCompiler compiler = processor.newXQueryCompiler(); XQueryExecutable xqueryExecutable = null; try { xqueryExecutable = compiler.compile(xQuery); } catch (SaxonApiException e) { // TODO Auto-generated catch block e.printStackTrace(); } XQueryEvaluator xqueryEvaluator = xqueryExecutable.load(); XdmValue xdmValue = null; try { xdmValue = xqueryEvaluator.evaluate(); } catch (SaxonApiException e) { // TODO Auto-generated catch block e.printStackTrace(); } XdmSequenceIterator iterator = xdmValue.iterator(); while(iterator.hasNext()) { System.out.println(iterator.next().toString()); } System.out.println("End of execution..."); Best regards, Bruno. ------------------------------------------------------------------------------ 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@... https://lists.sourceforge.net/lists/listinfo/saxon-help |
|
|
Re: How to use XQuery from s9apiFirst, some general advice about problem solving. (a) generally, if an error occurs, there will be an error message. The message is designed to help you understand the cause of the error. If it doesn't help you, then it will probably help someone else who knows the software better than you do. If you want help understanding an error, then showing them the error message is always a useful first step. (b) it's also useful to know when the error occurs. XQuery distinguishes between static errors and dynamic errors. The stack trace you are outputting will distinguish the two cases. Again, if you want help, providing this kind of information would be useful. (c) a more specific point: unless you take steps to do otherwise (which you haven't done in this program) Saxon will output error information to the System.err output destination. In a console application, this will appear on the console. In a GUI application, unless you take steps to display it in some window, it won't appear at all. The first thing to do before trying to solve an exception like this is to make sure that either (a) the System.err output is visible, or (b) you direct the error information somewhere else. I'm afraid that from the information given, I have absolutely no idea why your query is failing. The most obvious reason would be that it is trying to read a source file that does not exist, or exists at a different location from the one specified. I've just noticed that you call the document() function rather than doc(). The document() function is defined in XSLT but not in XQuery. That's another possible cause. A third possible cause: your call to document() uses a relative URI. This is interpreted relative to the base URI of the query. But you haven't specified a base URI for the query. To do this, call setBaseURI() on the XQueryCompiler. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > > I'm still working on my search engine for XML documents... > When I make a request my search engine find relevant elements > from an index data structure and return a list of XML element URIs: > > ex: > > document("./path/to/document.xml")//path/to/element > > So I think to use XQueries to fetch all relevant elements in > one result XML tree. > I try this Java code but an exception rise and I don't know > how to handle it... > > > String xQuery = "for $n in > document('./collection/d001.xml')//p\n" + > "return $n"; > > Processor processor = new Processor(false); > XQueryCompiler compiler = processor.newXQueryCompiler(); > XQueryExecutable xqueryExecutable = null; > try { > xqueryExecutable = compiler.compile(xQuery); > } catch (SaxonApiException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > XQueryEvaluator xqueryEvaluator = > xqueryExecutable.load(); > XdmValue xdmValue = null; > try { > xdmValue = xqueryEvaluator.evaluate(); > } catch (SaxonApiException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > XdmSequenceIterator iterator = xdmValue.iterator(); > while(iterator.hasNext()) { > System.out.println(iterator.next().toString()); > } > System.out.println("End of execution..."); > > > Best regards, > > Bruno. > > -------------------------------------------------------------- > ---------------- > 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@... > 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@... https://lists.sourceforge.net/lists/listinfo/saxon-help |
|
|
|
| Free embeddable forum powered by Nabble | Forum Help |