Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] New XPath issue: what to do with non-nodes?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: Elliotte Harold <elharo AT metalab.unc.edu>
  • Cc: xom-interest AT lists.ibiblio.org, John Cowan <jcowan AT reutershealth.com>, Nils_Kilden-Pedersen AT Countrywide.Com
  • Subject: Re: [XOM-interest] New XPath issue: what to do with non-nodes?
  • Date: Wed, 12 Jan 2005 19:57:01 -0800

I admit, it was a poor example. How about compound calculations where the output does not reflect list size? Say, growth of revenue wrt. last year's quarter? Might lean a little towards XQuery.

In any case, I recently added an efficient convenience method for common cases with which one can do the same thing if desired:

int count = XQueryUtil.xquery(contextNode, "//*").size();

It is just a little convenience method and does not obsolete the more powerful API underneath.

On Jan 12, 2005, at 4:32 PM, Elliotte Harold wrote:

Wolfgang Hoschek wrote:


int count = Integer.parseInt(new XQuery("count(//*)", null).execute(contextNode).next().getValue());

I had to really think to parse that one, and initially thought it was incorrect. (The two glasses of wine I just had with dinner probably didn't help, though :-) ) In XOM as it exists in CVS we'd do the same query like this:

Nodes result = contextNode.query("//*");
int count = result.size();

I'm getting a bit of deja vu here. have we had this discussion before? (Then again, maybe it's the two glasses of wine.)

In any case, I think the XOM solution is more obvious. It's two method calls instead of five. I prefer to put the two calls in separate statements, but if you really like method chaining, that works too:

int count = contextNode.query("//*").size();

--
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