Actions
Bug #3578
closedHow to use XQuery and Serializer on .NET to output a map respectively how to ensure that output options in XQuery are used by Serializer
Start date:
2017-12-22
Due date:
% Done:
100%
Estimated time:
Legacy ID:
Applies to branch:
9.8
Fix Committed on Branch:
9.8, trunk
Fixed in Maintenance Release:
Platforms:
Description
I am having trouble to find a way to use a Serializer
on .NET to output the result of an XQuery that is not XML, like a map, when the XQuery uses declare option output:method "adaptive";
that should allow for a flexible and dynamic output method.
A reduced test case run against Saxon 9.8.0.6 HE is
Processor processor = new Processor(false);
XQueryCompiler compiler = processor.NewXQueryCompiler();
XQueryEvaluator evaluator = compiler.Compile("declare namespace output = \"http://www.w3.org/2010/xslt-xquery-serialization\"; declare option output:method \"adaptive\"; map { 'string' : 'foo', 'number' : 1, 'boolean' : true() }").Load();
Serializer serializer = processor.NewSerializer(Console.Out);
evaluator.Run(serializer);
and throws the following stack trace:
java.lang.UnsupportedOperationException occurred
HResult=0x80131500
Message=A map has no string value
Source=<Cannot evaluate the exception source>
StackTrace:
at net.sf.saxon.ma.map.HashTrieMap.getStringValueCS()
at net.sf.saxon.serialize.UncommittedSerializer.append(Item item, Location locationId, Int32 copyNamespaces)
at net.sf.saxon.expr.Literal.process(XPathContext context)
at net.sf.saxon.query.XQueryExpression.run(DynamicQueryContext env, Result result, Properties outputProperties)
at Saxon.Api.XQueryEvaluator.Run(XmlDestination destination)
at Saxon98XQueryTest.Program.Main(String[] args) in c:\users\martin honnen\documents\visual studio 2017\Projects\Saxon98XQueryTest\Saxon98XQueryTest\Program.cs:line 21
A similar Java program
Processor processor = new Processor(false);
XQueryCompiler compiler = processor.newXQueryCompiler();
XQueryEvaluator evaluator = compiler.compile("declare namespace output = \"http://www.w3.org/2010/xslt-xquery-serialization\"; declare option output:method \"adaptive\"; map { 'string' : 'foo', 'number' : 1, 'boolean' : true() }").load();
Serializer serializer = processor.newSerializer(System.out);
evaluator.run(serializer);
however runs fine and outputs the map as
map{"boolean":true(),"number":1,"string":"foo"}
What code do I need on the .NET side to write XQuery results to a Serializer
so that the output options in the code are honoured, like it works on the Java side?
Please register to edit this issue
Actions