Topic
2 replies Latest Post - ‏2012-10-18T00:59:15Z by SystemAdmin
SystemAdmin
SystemAdmin
746 Posts
ACCEPTED ANSWER

Pinned topic How to setContextItem given a string, not a document

‏2012-10-17T06:00:28Z |
Hi all,

I am trying to run a query over some XML data using XQuery, Saxon and Java.
And I would like to read the XML data from a string, not a file. I haven't figure out which classes to use, as many classes implement the Item interface. I tried a few with no luck.. maybe I am not on the right track. Please let me know what is the right way.

String stringSource = "xml input data";

final Configuration config = new Configuration();
final StaticQueryContext sqc = config.newStaticQueryContext();
final XQueryExpression exp = sqc.compileQuery(new FileReader("xquery.file"));
final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);

dynamicContext.setContextItem(new StringValue("stringSource")); //?????????????????? line that needs to be modified
final Properties props = new Properties();
//... set propos
exp.run(dynamicContext, new StreamResult(new File("output.file")), props);
Updated on 2012-10-18T00:59:15Z at 2012-10-18T00:59:15Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    746 Posts
    ACCEPTED ANSWER

    Re: How to setContextItem given a string, not a document

    ‏2012-10-17T09:50:03Z  in response to SystemAdmin
    Please raise Saxon-specific questions on the forum at http://saxonica.plan.io/, or on the saxon-help list hosted by SourceForge for the Saxon project.
    • SystemAdmin
      SystemAdmin
      746 Posts
      ACCEPTED ANSWER

      Re: How to setContextItem given a string, not a document

      ‏2012-10-18T00:59:15Z  in response to SystemAdmin
      I am sorry, I will write it there.