Project

Profile

Help

Serialization question (#2)

Added by Anonymous about 15 years ago

Legacy ID: #7269076 Legacy Poster: David Lee (daldei)

This is a further discusion of the thread "XdmNode toString, Processor.writeXdmValue prb " but it was getting so indented its hard to read. I ran into another related problem in searializing using Processor.writeXmmValue and XdmValue.toString() and also using the xquery run() method. Suppose I have a document with declared namespaces: -------- <t:test xmlns:t="http://xproc.org/ns/testsuite" xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:err="http://www.w3.org/ns/xproc-error"> <t:input port="source"> <t:document> <doc>Text</doc> </t:document> </t:input> </t:test> ---------- If I run the xquery '//doc' and serialize with XQueryEvaluator.run() or with Processor.writeXdmValue() I get ------ <doc xmlns:t="http://xproc.org/ns/testsuite" xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:err="http://www.w3.org/ns/xproc-error&quot;&gt;Text&lt;/doc> ----- My first question is: Is this the expected output ? Should the unused namespace declarations be output on this node ? Second, if instead I use my own serializer using the ComplexContentOutputter I get ----- <doc>Text</doc> ---- This is what I would nievely assume is correct. Now here's the fun part. If instead I run the xquery <wrap>{//doc}</wrap> Using my serializer I get -------- <wrap> <doc xmlns:t="http://xproc.org/ns/testsuite" xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:err="http://www.w3.org/ns/xproc-error&quot;&gt;Text&lt;/doc> </wrap> --------- And when I run document { //doc } I get ------ <doc xmlns:t="http://xproc.org/ns/testsuite" xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:err="http://www.w3.org/ns/xproc-error&quot;&gt;Text&lt;/doc> -------- SO what appears to be happening to me is that the ComplexContentOutputter is only removing redundant namespace declarations if they appear on the root node (either an element or a document). My questions are 1) What is the expected behaviour ? Is it expected that unused namespace declarations be output ? 2) Any suggestions on a seraialization strategy which universally removes unused namespace declarations from all child elements ? Is that a reasonable thing to expect possible ? Thanks for any suggestions -David


Replies (2)

RE: Serialization question (#2) - Added by Anonymous about 15 years ago

Legacy ID: #7269104 Legacy Poster: Michael Kay (mhkay)

>My first question is: Is this the expected output ? Should the unused namespace declarations be output on this node ? Yes, it is correct. The XDM data model effectively replicates the namespaces on all elements where they are in scope. It's not implemented like that internally in Saxon, but that's the model. >if instead I use my own serializer using the ComplexContentOutputter I can't really comment on what your code is doing without studying it in detail. >Any suggestions on a seraialization strategy which universally removes unused namespace declarations from all child elements ? Architecturally, it's not the job of the serializer to add or remove namespaces. That's a transformation task. Internally, however, it can be done at a low level using the different options of the NodeInfo.copy() method.

RE: Serialization question (#2) - Added by Anonymous about 15 years ago

Legacy ID: #7269248 Legacy Poster: David Lee (daldei)

Thank you. Knowing whats expected output is a great help. I'll take a look at the NodeInfo.copy method.

    (1-2/2)

    Please register to reply