[xquery-talk] Constructing namespace nodes

David Lee dlee at calldei.com
Mon Feb 7 12:43:23 PST 2011

This may work in theory but in practice its not that easy (atleast in my


In the Saxon world there are many places NamespaceReducer is put in the
chain without being requested,
For example Serializer.getXMLStreamWriter().
There are many places in Saxon that do this without the user being able to
avoid it easily.

I'm not picking on Saxon, its just an API set I'm more familiar with than

Other API's I find 'hit and miss'.   Sometimes they remove unused namespaces
sometimes they don't.
I've found I have to try a particular API to find out, its rarely documented
and can often change from release to release.

Its one of those 'dark holes' of implementation where I've learned one cant
really rely on consistent behavior.
In almost all cases I can think of (and thinking back to the zillions of
"How can  remove these unused namespace from my document" posts,
I think this is the correct and desired behavior (remove redundant or unused
namespaces).    But sometimes its not.
That's when you have QNames in Content and the tools require the XML
namespace declarations instead of their own indicators..   
A true 'black sheep' of XML practice, IMHO.  (not that I'm innocent in this
regards either )

And I don't think you can just 'blame the user' ... Its really a dark and
scary part of XML processing realities ... you never know really what's
going on under-the-hood wrt namespaces and frequently cant control it even
if you do.

David A. Lee
dlee at calldei.com

-----Original Message-----
From: Michael Kay [mailto:mike at saxonica.com] 
Sent: Monday, February 07, 2011 4:11 AM
To: David Lee
Cc: talk at x-query.com
Subject: Re: [xquery-talk] Constructing namespace nodes

> For example if I load the serialized XML into a Saxon TinyTree then
> re-serialize it with a NamespaceReducer in the chain the unused namespace
> declarations will be gone.   Not to pick on Saxon, its doing perfectly and
> exactly what I tell it to ...   But there are other processes which do
> similar things that is either not in the control of the typical user, or
> very non-obvious.

Then you are doing something wrong. The defaults in both XSLT and XQuery 
are that namespaces are retained, unless you do something to say you 
don't need them. If you're building a low-level Saxon pipeline involving 
things such as a NamespaceReducer, then it's entirely under your control 
whether namespaces are retained or not.

Michael Kay

More information about the talk mailing list