Project

Profile

Help

Bug #4353

closed

Extra namespaces present when serializing XdmValue using Serializer API

Added by Radu Coravu about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Serialization
Sprint/Milestone:
-
Start date:
2019-10-21
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
9.9
Fix Committed on Branch:
9.9
Fixed in Maintenance Release:
Platforms:

Description

I have an "net.sf.saxon.s9api.XdmValue" which resulted from an XQuery update operation. I create a serializer "net.sf.saxon.s9api.Processor.newSerializer(Writer)" and then use it to serialize the value:

serializer.serializeXdmValue(rootElement);

Problem is that with Saxon 9.9 I get extra not-necessary namespaces serialized, something like:

  <p:url href="http://www.example.com" xmlns:p="http://www.oxygenxml.com/ns/samples/personal"/>

so I would prefer somehow to have an extra namespace reducer when writing the content.

I looked at the implementation of "net.sf.saxon.s9api.Processor.writeXdmValue(XdmValue, Destination)" which seems to be adding a namespace reducer on the "else" clause so I used the following workaround on my side:

      processor.writeXdmValue(rootElement, new AbstractDestination() {
        
        @Override
        public Receiver getReceiver(PipelineConfiguration pipe, SerializationProperties params)
            throws SaxonApiException {
          return serializer.getReceiver(pipe, params);
        }
        
        @Override
        public void close() throws SaxonApiException {
          serializer.close();
        }
      });

to force the code on the "else" branch and add that extra namespace reducer. But maybe "serializer.serializeXdmValue(rootElement);" could by default somehow use an namespace reducer by default.

Actions #1

Updated by Radu Coravu about 5 years ago

To refine my XML example, the fully serialized XML fragment using the default Serializer approach looks like this:

<p:personnel xmlns:p="http://www.oxygenxml.com/ns/samples/personal">
  <p:person id="harris.anderson" photo="personal-images/harris.anderson.jpg">
    <extra><p:url href="http://www.example.com" xmlns:p="http://www.oxygenxml.com/ns/samples/personal"/></extra>
  </p:person>
</p:personnel>

so that "p:url" element has an extra xmlns:p="http://www.oxygenxml.com/ns/samples/personal" declaration which is also on the root element.

Actions #2

Updated by Michael Kay about 5 years ago

It would be interesting to know how the redundant namespace declaration got into the XdmValue in the first place; perhaps the right fix would be to stop that happening.

We've made some efforts to formalize the interface between the "transformation" and "destination" sides of the Receiver interface: see the Javadoc for class RegularSequenceChecker. The rules (in 9.9) don't say they're can't be redundant namespaces. In 10.0 the interface changes so that the startElement() event includes a NamespaceMap object which must include all in-scope namespaces for an element; that puts the onus firmly on the destination side to eliminate duplicates when serializing.

This means that any solution for 9.9 can afford to be a bit pragmatic, and I'm inclined to tackle it by adding a NamespaceReducer to the Receiver returned by QueryResult.serializeSequence(), which underpins Serializer.serailize(XdmValue).

Actions #3

Updated by Michael Kay about 5 years ago

  • Category set to Serialization
  • Status changed from New to Resolved
  • Assignee set to Michael Kay
  • Applies to branch 9.9 added
  • Fix Committed on Branch 9.9 added

I've patched 9.9 to add a NamespaceReducer in QueryResult.serializeSequence(), as suggested. Regression tested only, since we don't have a repro.

Actions #4

Updated by Radu Coravu about 5 years ago

Thanks Michael.

Actions #5

Updated by O'Neil Delpratt almost 5 years ago

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

Patch committed to the Saxon 9.9.1.6 maintenance release.

Please register to edit this issue

Also available in: Atom PDF