jastrachan | 22 Jul 10:12 2004
Picon

Re: GPath alternative


On 22 Jul 2004, at 09:05, Yuri Schimke wrote:

> Well I would return String if there is only one.  Or List<String|Node> 
> if there are more.
>
> Make the person consuming the XML make the decisions.
>
> If they know there can only be one they use
>
> item.title
>
> If its possible there is more then use (should work for Collection or 
> single String, right?)
>
> item.title.each {
> }

The only problem is if there may be 1..N you may want to write 
something like...

foo = item.title[0]

So if there is one, and we return a single Node, then the [0] may do 
strange things.

Maybe we should make Node looky-likey a List of 1 node with respect to 
the [] operator?

Then if we had

foo = item.title[0]

it would always return the first node whether there was 1 or more title 
nodes. i.e. adding [0] is a no-op when applied to a Node.

e.g.

a = new Node(null, "title")
b = a[0]
assert a == b && a === b
c = a[1]
assert a == null

James
-------
http://radio.weblogs.com/0112098/


Gmane