This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 6152 - Superfluous Namespace Declarations
Summary: Superfluous Namespace Declarations
Status: CLOSED INVALID
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Serialization 1.0 (show other bugs)
Version: Recommendation
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Henry Zongaro
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-10 08:39 UTC by Tim Mills
Modified: 2008-10-10 09:53 UTC (History)
1 user (show)

See Also:


Attachments

Description Tim Mills 2008-10-10 08:39:42 UTC
Consider the query:

declare default element namespace 'http://www.example.org";

element a { element b {} }

or the equivalent query:

declare default element namespace 'http://www.example.org";

<a><b/></a>

We believe the serialized result of this is:

<a xmlns="http://www.example.org/">
  <b xmlns="http://www.example.org/"/>
</a>

Each namespace binding here is created as a result of the rule in Section 3.7.4 (In-scope Namespaces of a Constructed Element):

"For each namespace used in the name of the constructed element or in the names of its attributes, a namespace binding must exist. If a namespace binding does not already exist for one of these namespaces, a new namespace binding is created for it. "

and the namespace binding on element b is retained during the copying of content described in XQ 3.7.1.3 Content.  As we understand it, the namespace binding on element a is only created _after_ its content has been evaluated, following the pattern in 3.7.3.1 Computed Element Constructors:

1.  Deal with the element name
2.  Deal with the element content
3.  Create the element

Clearly the resulting namespace declaration on element b is superfluous.  However, we can't find any text in the serialization specification which would lead be to believe we are allowed to strip such superfluous namespace declarations.

The only reference I can find to removing namespace declarations is section 5 (XML Output Method) 

"The result tree MAY contain namespace nodes that are not present in the reconstructed tree, as the process of creating an instance of the data model MAY ignore namespace declarations in some circumstances. See Section 6.2.3 Construction from an InfosetDM and Section 6.2.4 Construction from a PSVIDM of [XQuery 1.0 and XPath 2.0 Data Model] for additional information."

and from the referenced documents

"Implementations may ignore namespace information items for namespaces which are not known to be used. A namespace is known to be used if:

    * It appears in the expanded QName of the node-name of the element.
    * It appears in the expanded QName of the node-name of any of the element's attributes.
    * It appears in the expanded QName of any values of type xs:QName that appear among the element's children or the typed values of its attributes."

None of these appear to apply in this case.

Section 4.6 of Canonical XML Version 1.0 (Superfluous Namespace Declarations) covers the issue, but this isn't part of the serialization process.

I would be grateful for some help with this issue.
Comment 1 Michael Kay 2008-10-10 09:46:59 UTC
>However, we can't find any text in the serialization specification which would lead [us] to believe we are allowed to strip such superfluous namespace declarations.

The serializer can do anything it likes provided that it doesn't do anything that the spec says it MUST NOT do. The spec doesn't say that it has to output redundant namespace declarations, therefore it doesn't have to do so. In particular, outputting redundant namespace declarations is not necessary to meet the primary requirement of the XML output method, which is:

"The result of serialization MUST be such that the reconstructed tree is the same as the result tree except for the following permitted differences:..."

because redundant namespace declarations will not have any effect on the reconstructed tree.

You seem to be confusing namespace bindings (=namespace nodes) with namespace declarations. There's nothing in the serialization spec that says each namespace binding in the result tree should result in a namespace declaration in the serialized output. It's not a question of "removing redundant namespace declarations", it's a question of only generating the necessary and sufficient set of namespace declarations needed to represent the namespace bindings.

It's also worth noting that a serializer that did generate redundant namespace declarations would be entirely conformant, in the same way that it would be conformant if it generates 1000 newline characters before every ">" that closes a start tag. It just wouldn't be the world's favourite serializer.

Comment 2 Tim Mills 2008-10-10 09:52:47 UTC
Thanks Mike.