Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] adding NamespaceContext.getNamespaces()

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Michael Kay" <mike AT saxonica.com>
  • To: "'Wolfgang Hoschek'" <wolfgang.hoschek AT mac.com>, "'Elliotte Harold'" <elharo AT metalab.unc.edu>
  • Cc: 'xom-interest' <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] adding NamespaceContext.getNamespaces()
  • Date: Tue, 31 Oct 2006 19:12:34 -0000

> The way the saxon binding works is to predeclare
> all ns declarations on XQuery setup, rather than via a
> lookup(String) callback, as in Jaxen or JAXP. That's why I'd
> need something like
> getNamespaces() rather than lookup(String).

The main reason Saxon needs access to all the in-scope namespaces, rather
than just a prefix-to-uri lookup method, is so that it can compile code to
do the prefix-to-uri mapping at run-time, without retaining references to
compile-time objects. There are only two constructs in standard XQuery that
need the mapping at run-time, namely computed element and attribute
constructors, but there are a lot more in XSLT and of course Saxon uses the
same mechanisms; there are also extensions such as saxon:evaluate() that use
the namespace context dynamically.

Saxon's StaticQueryContext does in fact have a
setExternalNamespaceResolver() method, which will be used to look up any
namespace prefixes that have not been actively declared: but looking at the
code I'm not sure that it currently supports these run-time uses of
namespace prefixes. And in any case the NamespaceResolver interface itself
has an iteratePrefixes() method which doesn't map onto anything in XOM's
XPathContext.

(If you want to see a really badly designed interface, look at JAXP's
javax.xml.namespace.NamespaceContext which for some weird reason allows you
to iterate over all the prefixes bound to a particular URI, but doesn't
allow you to get all the in-scope prefixes!)

Michael Kay





Archive powered by MHonArc 2.6.24.

Top of Page