From: "Erwin Bolwidt" <[EMAIL PROTECTED]>
> On Fri, 21 Sep 2001, James Strachan wrote:
>
> > You can bind the empty prefix to a namespace URI. Its often called the
> > 'default namespace'.
> >
> > e.g.
> >
> > <foo xmlns="someURI">
> >     <bar/>
> > </foo>
> >
> > In the above document the XPath expression /foo/bar will not work unless
you
> > explicitly setup a NamespaceContext to set the default namespace URI to
be
> > "someURI". If you map empty prefix, "", to "someURI" in your
> > NamespaceContext then /foo/bar will work.
>
> That would have been convenient if it were possible, but there are two
> problems:
>
> * xpath explicitly disallows it, in section 2.3:
> "A QName in the node test is expanded into an expanded-name using the
> namespace declarations from the expression context. This is the same way
> expansion is done for element type names in start and end-tags except
> that the default namespace declared with xmlns is not used: if the
> QName does not have a prefix, then the namespace URI is null (this is the
> same way attribute names are expanded). It is an error if the QName has a
> prefix for which there is no namespace declaration in the expression
> context."
>
> * a practical one: functions and variables are also qualified names; if
> you were to rebind the empty prefix to some namespace, then you wouldn't
> be able to call any of the built-in xpath functions, since they have no
> namespace URI. Jaxen simply won't be able to find the functions or
> variables.

Ah OK. Thats a huge shame but I guess to work with non-namespaced functions
and variables it has to be like that.

Thanks for clearing that up - I stand corrected. The only way to properly
evaluate that XPath expression is then this ugly huge thing...

/*[local-name()='foo' and namespace-uri()='someURI']//*[local-name()='bar'
and namespace-uri()='someURI']/

Though I suppose you could map your own new prefix to the URI instead. So
rather than mapping "" to "someURI" you could map "x" to "someURI" and then
do

/x:foo/x:bar

which should work.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to