Command Line to Java Program
Added by Sathya Selva about 4 years ago
Dear Team, I want to Convert the Command line process to java program
Command Line java -cp saxon.jar net.sf.saxon.Query -q:file.xquery filepath=*.xml
Replies (6)
Please register to reply
RE: Command Line to Java Program - Added by Martin Honnen about 4 years ago
I am not sure I understand your request. The code for net.sf.saxon.Query
is online https://saxonica.plan.io/projects/saxon/repository/he/revisions/master/entry/latest10/hej/net/sf/saxon/Query.java.
RE: Command Line to Java Program - Added by Martin Honnen about 4 years ago
If you don't need the complexity of the net.sf.saxon.Query
command line interface but your question is about using XQuery with Saxon and Java code then see all Query examples in the samples file e.g. https://saxonica.plan.io/projects/saxon/repository/he/revisions/master/entry/latest10/samples/java/he/S9APIExamples.java#L165 while reading https://www.saxonica.com/html/documentation/using-xquery/api-query/s9api-query.html.
RE: Command Line to Java Program - Added by Michael Kay about 4 years ago
Information about calling XQuery from Java is here:
https://saxonica.com/documentation/index.html#!using-xquery/api-query
There's a choice of two APIs: the XQJ interface, which is standardised but not particularly well matched to Saxon's capabilities, and the s9api interface which is specific to Saxon.
There are sample applications (for both APIs) in the saxon-resources download file. It starts with a very simple example:
public void run() throws SaxonApiException {
Processor proc = new Processor(false);
XQueryCompiler comp = proc.newXQueryCompiler();
XQueryExecutable exp = comp.compile("<a b='c'>{5+2}</a>");
Serializer out = proc.newSerializer(System.out);
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.INDENT, "yes");
out.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
exp.load().run(out);
}
and goes on to more complex cases.
The Javadoc API documentation is all online; start at https://saxonica.com/documentation/index.html#!javadoc/net.sf.saxon.s9api/XQueryCompiler
RE: Command Line to Java Program - Added by Sathya Selva about 4 years ago
Need to know One more Command line process to java code
java -cp "saxon-9.x.jar"
net.sf.saxon.Transform
-warnings:silent
-s:"test.xml"
-xsl:"test.xsl"
-o:"testOutput.xml"
*Text_File="testTextFile.xml"
PR_Path="testFile1.xml"2>"Log.log"*
Text_File and PR_Path is xsl param argument. I already embedded the xsl:param in xsl file
I want to give a XSL argument and also get an error on log file and Transform output also, I got the perfect output while use jar(Command Line) but need to know the java code.
Thanks in advance
RE: Command Line to Java Program - Added by Martin Honnen about 4 years ago
The samples already referenced have various "Transform..." examples, https://saxonica.plan.io/projects/saxon/repository/he/revisions/master/entry/latest9.9/samples/java/he/S9APIExamples.java#L519 shows setting a parameter, for instance.
Please register to reply