Re: XPathNSResolver doubts (pat 2)

* Joćo Eiras wrote:
>  - is a XPathNSResolver aware of reserved prefixes, like the xml prefix,  
>which is bound to "http://www.w3.org/XML/1998/namespace" ?

One created using createNSResolver is, if you make your own resolver it
might not be. A revision of the specification might say that the imple-
mentation must never call custom resolvers with 'xmlns' or 'xml' but it
does not currently.

>  - I understand that the porpouse of a NSResolver is to associate a prefix  
>with its namespaceURI, but how to get the namespaceURI of some specific  
>context, if there's no associated prefix ? Like passing the following node  
>to a createNSResolver
>     <html xmlns="http://www.w3.org/1999/xhtml"/>
>    Should lookupNamespaceURI be invoked with an empty string ?

No, that's explicitly forbidden and the result of doing so is undefined.

>    If this case is not supported, instead of regarding passing null to  
>lookupNamespaceURI as undefined behaviour, it could enclose this  
>situation, and return the uri associated with the namespace with no prefix.

That is not useful behavior from the perspective of an XPath engine that
supports only XPath 1.0; in XPath 1.0, if an element or attribute name
test does not use a prefix, it matches only elements or attributes in no
namespace. In XPath 2.0 a default namespace can exist, whether a future
version of DOM XPath supports that and if, how exactly, has yet to be
resolved, but I will note that at the moment no format uses the current
in scope default namespace declaration to lookup the default namespace,
you rather have to declare it separately.

Generally, if you are not processing XPath expressions contained in some
document but rather just want to use the interface as query mechanism,
you would not use createNSResolver, instead you would setup your own
resolver with the prefixes you are using in your queries; that ensures,
among other things, that your scripts work independently of how the doc-
ument organizes its namespace declarations.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Received on Saturday, 3 February 2007 04:32:12 UTC