XdmMap as result of XPath or XQuery or XSLT in SaxonCS versus Saxon-HE: should there be a ToString method rendering the result
Added by Martin Honnen almost 3 years ago
While trying to create a .NET interactive notebook using SaxonCS I noticed that XPath or XQuery or XSLT returning XML or a sequence gives me a result that Console.WriteLine()
renders/display in some serialized way while an simple XdmMap only outputs the class name e.g. Saxon.Hej.ma.map.SingleEntryMap
.
So using Saxon-HE 10.6 .NET framework the example
var processor = new Processor();
var xpathCompiler = processor.NewXPathCompiler();
var xpathExpression1 = "map { 'items' : array { random-number-generator(current-dateTime())?permute(1 to 10) } }";
var result1 = xpathCompiler.EvaluateSingle(xpathExpression1, null);
Console.WriteLine(result1);
outputs e.g. map{"items":[4,6,8,5,7,10,2,9,3,1]}
, using SaxonCS I get Saxon.Hej.ma.map.SingleEntryMap
.
Is there a ToString()
method missing that somehow serialized the map or is there some conversion to the .NET Api missing in the transpiler so that the result is not an XdmValue that seems to have a ToString method doing the adaptive serialization (https://www.saxonica.com/html/documentation11/dotnetdoc/Saxon/Api/XdmValue.html#ToString())?
Replies (3)
Please register to reply
RE: XdmMap as result of XPath or XQuery or XSLT in SaxonCS versus Saxon-HE: should there be a ToString method rendering the result - Added by Martin Honnen almost 3 years ago
The same happens with an XdmArray, with Saxon HE with
var docBuilder = processor.NewDocumentBuilder();
docBuilder.BaseUri = new Uri("urn:from-string");
var xmlSample1 = @"<root><item>a</item><item>b</item><item>c</item></root>";
XdmNode exampleInputDoc;
using (var sr = new StringReader(xmlSample1))
{
exampleInputDoc = docBuilder.Build(sr);
}
var xpathResult = xpathCompiler.EvaluateSingle("array { random-number-generator(current-dateTime())?permute(/root/item) }", exampleInputDoc);
Console.WriteLine(xpathResult);
I get the output of e.g. [a,b,c]while SaxonCS shows
[Saxon.Hej.tree.tiny.TinyTextualElement, Saxon.Hej.tree.tiny.TinyTextualElement, Saxon.Hej.tree.tiny.TinyTextualElement]`
RE: XdmMap as result of XPath or XQuery or XSLT in SaxonCS versus Saxon-HE: should there be a ToString method rendering the result - Added by Michael Kay almost 3 years ago
In SaxonJ, XdmMap
and XdmArray
inherit XdmValue.toString()
, which produces the serialization of the value with method="adaptive".
I intend to change SaxonCS to do the same.
RE: XdmMap as result of XPath or XQuery or XSLT in SaxonCS versus Saxon-HE: should there be a ToString method rendering the result - Added by Martin Honnen almost 3 years ago
It seems, the classes XdmMap or XdmArray do inherit or use some adaptive serialization with SaxonCS, for instance if I create some instances directly from C#, like
var intXdmArray = XdmArray.MakeArray(new int[] { 3, 2, 1 });
Console.WriteLine(intXdmArray);
I get the output [3, 2, 1]
, only more complex or through XPath generated values seem to break that and show the class names like Saxon.Hej.ma.map.SingleEntryMap
or for some items in an array the class names, like [Saxon.Hej.tree.tiny.TinyTextualElement, Saxon.Hej.tree.tiny.TinyTextualElement, Saxon.Hej.tree.tiny.TinyTextualElement]
.
Please register to reply