Link to home
Create AccountLog in
Avatar of alice_
alice_

asked on

executing xquery and getting string as result using saxon

hi i am using saxon to run a xquery in java. i want to get the result in a strig as xml formatted to pass this result to a string variable and convert it to Json format. The issue is that i can´t get the result as string. any idea thanks.

StaticQueryContext sqc= c.newStaticQueryContext();
       DynamicQueryContext dqc =new DynamicQueryContext(c); 
//     Processor processor = new Processor(sqc);
       final XQueryExpression exp = sqc.compileQuery( queryFinal  ) ;

        InputStream is = new ByteArrayInputStream( xmlText.getBytes( Charset.defaultCharset() ) );
        InputSource XMLSource=new InputSource(is);
        SAXSource SAXs=new SAXSource(XMLSource); 
        DocumentInfo DI=sqc.buildDocument(SAXs);
        dqc.setContextNode(DI);

         Properties props=new Properties();
           props.setProperty(OutputKeys.METHOD,"xml");
           props.setProperty(OutputKeys.INDENT,"yes");

       exp.run(dqc,new StreamResult (destStream),props);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
;)