Project

Profile

Help

Managed results after XQuery call from java

Added by Anonymous almost 19 years ago

Legacy ID: #3265116 Legacy Poster: bruno souche (bsouche)

Hi, First i want to apologize for my poor english, and i hope that you ll understand me. I started to learn XQuery/XPath few weeks ago, and now i encounter a problem using Saxon (not a bug, just lack of knowledges). My program is quite simple. I create all business rules and functions in XQuery, all data are stocked in XML files (all work fine, created and tested using XMLSpy 2005 Home Edition). As u can see, i use the 'portability' concept, the developper must create the user interface in his favorite language. To demonstrate how the application works, i've started to create a program using java language (Sun JDK 1.5.0_02 on XP platform) and Saxon-8.4B API. My problem occurs when i call XQuery function with Saxon, not the call itself, but i don't know how to manage my returned element! When i display it or write it to a file i only see the text() value of the element, not the element itself. In Saxonica online documentation (Result Format chapter) it's said that i ve to 'wrap' my result. But i don't find how to do in samples or on the web. I hope that u can understand my awful english and u can help me. Thanx in advance. Bruno PS:You ll find my java code at the end of this post. If you need i can send you my XQuery code. JAVA CODE ********************************************************* public void compute(){ try { Configuration config = new Configuration(); StaticQueryContext sqc new StaticQueryContext(config); XQueryExpression exp = sqc.compileQuery(new FileReader(request)); XQueryFunction temp = null; Controller controller = exp.getController();//controller UserFunction fn1 = exp.getStaticContext().getUserDefinedFunction("rml.ns", "getCritical", 3); //values to call function Value[] arglist = new Value[3]; arglist[0] = new IntegerValue(100); arglist[1] = new StringValue("E"); arglist[2] = new StringValue(filepath); //CALL ValueRepresentation result = fn1.call(arglist, controller); //Display result FileOutputStream fos = new FileOutputStream(new File("d:/test.txt")); System.out.println("getCritical("+arglist[0]+","+arglist[1] + ","+arglist[2] +") : " + result+"\n\n"); fos.write(result.toString().getBytes()); fos.close(); } catch (XPathException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } **************************************************** END JAVA CODE


Replies (1)

RE: Managed results after XQuery call from ja - Added by Anonymous almost 19 years ago

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

The interface you are using, which allows you to call a specific function in your query module, is a fairly low-level interface that was designed primarily for integrators rather than end users. It's a very efficient interface, but it achieves this partly by doing rather little checking and conversion of parameters and results. It wouldn't be my recommendation for a novice user. You can use it if you want: but you have to inspect the ValueRepresentation that comes back to see what kind of object you have got, and process it accordingly. Just doing toString() on it won't be very useful. In fact a ValueRepresentation is either a Value or a NodeInfo, so these are the only cases you need to consider. I would recommend that you use instead the approach documented at http://www.saxonica.com/documentation/using-xquery/embedding.html

    (1-1/1)

    Please register to reply