Project

Profile

Help

Bug #3578

closed

How to use XQuery and Serializer on .NET to output a map respectively how to ensure that output options in XQuery are used by Serializer

Added by Martin Honnen almost 7 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Category:
.NET API
Sprint/Milestone:
-
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?

Actions #1

Updated by Michael Kay almost 7 years ago

I've been doing work on this area recently for XSLT - but only on the development branch. Basically, i think the evaluator.run(serializer); always invokes Sequence Normalization, which fails if the raw result contains a map. You need to use the evaluate() method to return an XdmValue, and then serialize that. I will review this.

Actions #2

Updated by O'Neil Delpratt almost 7 years ago

  • Assignee set to Michael Kay

Monitor changes in the Java code to transfer to .NET code base.

Actions #3

Updated by Joe Wicentowski over 6 years ago

I thought I'd note that this issue came up today when I was reviewing Martin's XQueryFiddle tool and noticed that the following query (also posted at http://xqueryfiddle.liberty-development.net/pPgCcok) returns with an XML declaration:

xquery version "3.1";

declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";

declare option output:method "xml";
declare option output:omit-xml-declaration "yes";

<x/>

The query returns:

<?xml version="1.0" encoding="UTF-8"?>
<x/>

See also the discussion at https://mobile.twitter.com/XSLT_knowmad/status/995722387978104832.

Is there any ETA for addressing this issue? I ask because I'm pointing the readers of my forthcoming book on XQuery for non-programmers to use this site for testing out basic queries. But at the moment it doesn't work as a tool for learning XQuery serialization options. Thanks in advance!

Actions #4

Updated by O'Neil Delpratt over 6 years ago

  • Tracker changed from Support to Bug
  • Category set to .NET API
  • Status changed from New to In Progress
  • Assignee changed from Michael Kay to O'Neil Delpratt
  • Applies to branch 9.8 added

Thanks for reporting the issue, which we have reproduced. Investigating the issue now.

Actions #5

Updated by O'Neil Delpratt over 6 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100
  • Fix Committed on Branch 9.8, trunk added

Bug fixed and committed to svn branches: 9.8 and trunk. This will be applied in the next maintenance release.

Actions #6

Updated by Debbie Lockett over 6 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 9.8.0.14 added

Bug fix applied in the Saxon 9.8.0.14 maintenance release.

Please register to edit this issue

Also available in: Atom PDF