commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
Subject Re: [configuration] iterating over structured XML
Date Thu, 22 Dec 2005 20:14:06 GMT
Quoting Oliver Heger <oliver.heger@t-online.de>:

> Jacob Kjome wrote:
>
> >I'm wondering if there's a better way to iterate over structured XML?
> Here's
> >how I'm currently doing it...
> >
> >int i = 0;
> >while (true)
> >{
> >    String subset = new
> >StringBuffer(18).append("tables.table(").append(i++).append(")").toString();
> >    SubsetConfiguration sc = (SubsetConfiguration) config.subset(subset);
> >    if (sc.isEmpty()) break;
> >
> >    //do stuff with subset configuration here....
> >}
> >
> >...which works, but it seems like I should be able to just do an iteration
> over
> >the subconfigurations.  Maybe something like this?...
> >
> >for (Iterator iter = config.getList("tables.table").iterator();
> iter.hasNext();)
> >{
> >    SubsetConfiguration sc = (SubsetConfiguration) iter.next();
> >
> >    //do stuff with subset configuration here....
> >}
> >
> >However, that doesn't work because config.getList() returns a list of string
> >contents of the table elements (which returns a list of size 0, since
> <table>
> >elements are only for structure, not for text content).  That's not what I'm
> >aiming for.  Isn't there a way that I can iterate over a list of subset
> >configurations so I don't have to resort to generating a dynamic key?  This
> >would make my code more clean.  I hope I'm just missing something.
> >
> >thanks,
> >
> >Jake
> >
> >
> I'm sorry, but there is no integrated, elegant way of iterating over
> structured properties ATM. This is something I was already thinking
> about, but have not come to a conclusion yet. I am sure this is an often
> needed use case.
>
> Maybe something in the line of a functor? I am open to any suggestions...
>
> Oliver

I'm guessing that you have some more robust and flexible solutions in mind than
I do.  By "functor", are you referring to the concept or using commons-functor
( http://jakarta.apache.org/commons/sandbox/functor/ )?  I guess, I was
thinking that since there is already a config.subset(String) method that
returns a SubsetConfiguration (although it declares a return type only of the
Configuration interface), why not have config.subsets(String) that returns
either a list or an iterator of SubsetConfigurationS?  That would be the most
straightforward way to approach it, no?

Jake




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message