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: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • To: 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 11:16:09 -0800


On Oct 31, 2006, at 10:25 AM, Elliotte Harold wrote:

Wolfgang Hoschek wrote:

If you'd rather like to expose the namespace map in a strongly typed manner, fine. For example via getNamespaceCount(), getNamespacePrefix(int), getNamespaceURI(int).

That's what I was wondering if you're doing. We could actually cut that down to two methods, at some cost in speed by replacing getNamespaceURI(int) with a getNamespacePrefix(int) followed by a lookup. Usually there's less than a dozen mappings (often only or two) so this might not matter a great deal.

Since the XPathContext doesn't maintain the current iteration state, it must recreate it for each iteration step. Thus, advancing to the next item is O(N). Enumerating all items is O(N^2). I can live with it in this particular case, because N is small for all practical purposes, and setting up an XPathContext is probably not a high- frequency operation, but I wouldn't advocate the pattern. In general, simulating a stateful iterator in a stateless way (e.g. via a positional index) in a system that's not distributed is a counter- intuitive, complicated, non-scalable pattern, and simply overkill for what is really a trivial problem. In a distributed (or concurrent) system it can make sense because systems with less state are simpler to reason, build, maintain and recover from. But XOM isn't a distributed system.

Or I could just return a String array of prefixes, and make it one method call.

Yes, that's much better: Simple, straighforward and relatively efficient.

Wolfgang.




Archive powered by MHonArc 2.6.24.

Top of Page