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: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: Wolfgang Hoschek <whoschek AT lbl.gov>
  • 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:32:05 -0500

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