XPath and default namespaces

Reading the XPath specs treatment of default namespaces has me a bit
confused. By not using the contextually "appropriate" default namespace
for unprefixed element names in generating an expanded name it seems
to make it impossible to get at nodes that use a default namespace
without using cumbersome namespace-uri()="mumble" perdicates at every
location step.

This means that if I have a working XPath application that say takes
a simple document like

   <meds>
     <antidepressant>Prozac</antidepressant>
   </meds>

and uses a Location Path like '/meds/antidepressant' it would be broken
if the person sending me the XML decided to do me a "favor" by making the
namespace explicit on the document tag (a seemingly good thing to do):

   <meds xmlns="http://drugsco.com/ourspace">
     <antidepressant>Prozac</antidepressant>
   </meds>

My Location Path would evaluate a null namespace name for both the 'meds'
and the 'antidepressant' local names but the DOM would have a namespace
name of 'http://drugsco.com/ourspace' for each of these elements so now
my application is busted. Even worse, because there's no prefix associated
with the default namespace I have to jump through some serious hoops
involving predicates using namespace-uri and local-name functions (I
won't embarass myself any more than I already have by trying to compose
the appropriate Location Path) to get at what I used to get at so
easily.

Am I missing something here? I'll quote James Clark a bit out of context
(the context can be found at
http://lists.w3.org/Archives/Public/www-xpath-comments/2001JanMar/0014.html)
in what seems to confirm both my reading of the XPath spec and its
undesirability:

> (I think this is probably a bug in XPath. Although XSLT chooses not to
> apply the default namespace to element names in XPath expressions, there
> is no reason for XPath to require all referencing specs that use XPath
> to do the same; it should be dependent on how referencing specs specify
> that the namespace bindings part of the XPath expression context is set
> up.)

So does that mean its kosher to use the (contextually appropriate?)
default namespace in an XPath implementation and still be XPath compliant
even though it seems to be at odds with what's in the spec?

Thanks

Alex Kodat
Sirius Software
Cambridge, MA

Received on Saturday, 3 November 2001 13:38:46 UTC