Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] adding an iterator() method to nodes

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Steve Loughran" <steve.loughran AT gmail.com>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] adding an iterator() method to nodes
  • Date: Tue, 31 Oct 2006 14:40:17 +0000

On 31/10/06, Randall R Schulz <rschulz AT sonic.net> wrote:

Don't forget to add the "implements Iterable" clause to enable the
concise iteration syntax.

I'm not so sure about that; I think that's a real design error there.
Because an object can only have return one iterator, something like an
element has to decide if it will be iterable over its child nodes,
elements, attributes or namespaces.

I make my iterators implement iterable instead:
public Iterator<Node> iterator() {
return this;
}

This lets you

for(Element e:root.elementIterator() ) { ... }
and
for(Attribute e:root.attributeIterator() ) { ... }

This will probably be considered an abuse of the interface come the
next edition of Effective Java, but, well, tough.

-steve




Archive powered by MHonArc 2.6.24.

Top of Page