Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9286331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:23:31+00:00 2026-06-18T19:23:31+00:00

hi i am using saxon to run a xquery in java. i want to

  • 0

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:23:33+00:00Added an answer on June 18, 2026 at 7:23 pm

    /// Everything as above, just change the last line to….

    StringWriter stringWriter = new StringWriter();

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

    String result = stringWriter.toString();

    System.out.println(“Result: ” + result);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a chained XSLT 2.0 transformation scenario (using saxon), like this: - I1.xml
In a java program, I am using Saxon Library to parse some XQuery commands.
I'm trying to use the Saxon processor from java. I'm using the the saxon9ee.jar
I'm trying to test the last attribute value from this input XML. I'm using
I am trying to run a distinct-values XPath using Saxon. Here is my code:
What I am trying to achieve is (using Saxon-B 9.1): 1) Run XSLT transformation
I'm using Saxon-EE 9.3.0.4 for xsl transformations and found that when <xsl:result-document> is used
I'm attempting to apply a stylesheet to an XML document using Saxon. Given an
I am using Java SE 6 on Mac OS X and Saxon-HE 9.3.0.5. The
I'm transforming an XML document with mimimized br tags like this: <br/> I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.