Re: [xml] Using Xpath with default namespace and null prefix

Le 8 févr. 10 à 14:03, Daniel Veillard a écrit :

On Mon, Feb 08, 2010 at 01:14:22PM +0100, Iñaki Baz Castillo wrote:
El Lunes, 8 de Febrero de 2010, Daniel Veillard escribió:

Does it mean that Xpath 2.0 allows the behavior I meant (present in RFC 4825)?

 I don't know, I doubt it.

No XPath 2.0 does not allow this kind of ambiguity.
If a "Default element/type namespace" property exists in the static context, this URI is used for "for any unprefixed QName appearing in a position where an element or type name is expected."
(but how can I reach elements without namespace? )

And the RFC 5261 section 4.2.2 says more precisely:

"The prefix matching rules described previously in this section are
   different from those required in XPath 1.0 and 2.0
   [W3C.REC-xpath20-20070123].  In XPath 1.0, a "bar" selector always
locates an unqualified <bar> element. In XPath 2.0, a "bar" selector
   not only matches an unqualified <bar> element, but also matches a
   qualified <bar> element that is in scope of a default namespace
In contrast, in this specification, a selector without
   a prefix only matches one element, and it may match an element with
or without a prefix but only if the namespace it's qualified with (or
   none) is an exact match."

That's clear!
Less clear is how can I reach elements without namespace in Xpath 2.0?

I agree with Daniel, XPath 1.0 is very clear.
On the other hand, considering XPath and xhtml, in most cases you have to invent an irrelevant prefix to build correct XPath expressions. In this context, it is rather uncommon to have elements without namespace.
Thus the XPath 2.0 rule is perhaps relevant, and
I think that it should be easy to add the "Default element/type namespace" property to the xmlXPathContext; this could simplify Xpath expressions for xhtml.

By the way (prefix and namespace), I have a request about exslt.
Some useful functions like exsltStrXpathCtxtRegister have been added.
But they require a non-null prefix, which is not convenient in my case.

exsltStrXpathCtxtRegister (xmlXPathContextPtr ctxt, const xmlChar *prefix)
    if (ctxt
        && prefix
        && !xmlXPathRegisterNs(ctxt,
        && !xmlXPathRegisterFuncNS(ctxt,
                                   (const xmlChar *) "encode-uri",...

could be replaced with

exsltStrXpathCtxtRegister (xmlXPathContextPtr ctxt, const xmlChar *prefix)
    if (!ctxt)return -1;
if(prefix && xmlXPathRegisterNs(ctxt,prefix,(const xmlChar *) EXSLT_STRINGS_NAMESPACE))return -1;
                                   (const xmlChar *) "encode-uri",...


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]