Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Scope of namespaces

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: peter murray-rust <pm286 AT cam.ac.uk>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Scope of namespaces
  • Date: Mon, 06 Feb 2006 08:13:00 -0500

peter murray-rust wrote:

Personally as a user of XOM I would find it much easier if all namespaces were easily available in all their descendant elements.

You can get a list of the namespaces in scope on an element using an XPath query such as

Nodes namespaces = element.query("namespace::node()");

This still ascends the tree, but at least you don't have to write your own code for doing so.

I've written a simple benchmark to see just how bad the various methods for iterating over namespaces really are.

https://xom.dev.java.net/source/browse/xom/src/nu/xom/benchmarks/NamespaceLister.java?rev=1.1&view=markup

I'm not finished yet, but so far I'm not sure there's a practical problem here. In my tests against http://www.rddl.org/ this code is able to retrieve each and every namespace URI, both in scope and declared, for every element in the document in between .1 and .3 seconds. No caching is done. i.e. each element is treated independently of the others. Thus the time to retrieve namespaces declared or in scope for just one element would be a small fraction of that.

I have not yet profiled this benchmark, so it's still possible that it's spending most of its time in something irrelevant like System.out.println(). However I think it does set a fairly low upper bound on the amount of time it takes to retrieve all namespaces declared or in scope, despite the aggressively suboptimal implementation.

There are definitely some optimizations I could make to getNamespacePrefix(int) and related methods. So far though it's not obvious this is worth doing. In practice, I suspect parsing, serializing, or simple I/O is likely to swamp any improvements I make in this method. Is anyone's code actually spending enough time here that this becomes the hot spot?

--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim




Archive powered by MHonArc 2.6.24.

Top of Page