Project

Profile

Help

Maintenance: Planio will be observing a scheduled maintenance window this Sunday, November 10, 2024 from 20:00 UTC until 21:00 UTC to perform important network maintenance in our primary data center. Your Planio account will be unavailable for a few minutes during this maintenance window.

XdmValue.toString() for SaxonJ versus XdmValue::toString for SaxonC

Added by Martin Honnen over 2 years ago

Is it an intended difference between SaxonJ and SaxonC (tested with 11.1 in both cases) that the toString() method on XdmValue in the Java case outputs a newline/linebreak as a separator between the items in the XdmValue while for SaxonC and C++ the ->toString() gives a long line with all items' serialization concatenated without any separator? Both API documentations talk about adpative serialization of the sequence/XdmValue being used.

So while Java

        Processor processor = new Processor(true);

        XdmValue results = processor.newXPathCompiler().evaluate("1, 'string', true(), parse-xml-fragment(string-join((1 to 3) ! ('<item>' || . || '</item>')))/node(), array { 1 to 5 }, map { 'key1' : 1, 'key2' : 'foo' }", null);

        System.out.println(results.toString());

gives several readable lines of outputs:

1
"string"
true()
<item>1</item>
<item>2</item>
<item>3</item>
[1,2,3,4,5]
map{"key1":1,"key2":"foo"}

C++ meanwhile

	XdmValue * resultValues = xpath->evaluate("1, 'string', true(), parse-xml-fragment(string-join((1 to 3) ! ('<item>' || . || '</item>')))/node(), array { 1 to 5 }, map { 'key1' : 1, 'key2' : 'foo' }");
	
	
	if(resultValues == nullptr) {
		printf("result is null \n");
        SaxonApiException * exception = xpath->getException();
        if(exception != nullptr) {
            const char *message = xpath->getErrorMessage();
            cout << "Error Message = " << message << endl;
            xpath->exceptionClear();
        }
        sresult->failure++;
        sresult->failureList.push_back("testXPathValues2");

	} else {
		cout<<"Number of items="<<resultValues->size()<<endl;
		cout<<"toString()="<<resultValues->toString()<<endl;

gives a long, hard to read line of all items concatenated without any separator:

Number of items=8
toString()=1stringtrue<item>1</item><item>2</item><item>3</item>[1,2,3,4,5]map{"key1":1,"key2":"foo"}

This also trickles down to the Python API where the print(somePyXdmValue) also shows a long line without any item separator.

It is kind of hard to read the C++ or Python result, can it be improved to use an item separator, like Java seems to do?


Replies (2)

RE: XdmValue.toString() for SaxonJ versus XdmValue::toString for SaxonC - Added by O'Neil Delpratt over 2 years ago

It is not intended for the XdmValue.toString() to be different in SaxonC and SaxonJ. SaxonC constructs the string from the individual XdmItems in the C++ code. I will look at aligning the output of SaxonC with SaxonJ.

RE: XdmValue.toString() for SaxonJ versus XdmValue::toString for SaxonC - Added by O'Neil Delpratt over 2 years ago

I hope to add a patch to this issue in the next maintenance release. Bug issue added: #5305

    (1-2/2)

    Please register to reply