You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Zsolt Koppany <zk...@intland.com> on 2005/03/14 21:47:41 UTC

How to parse this configuration?

Hi,

how can I parse the following configuration?

<file>
	<group description="Web" extensions="asp,aspx,phtml,shtml,php"
		parser="-" type="w"/>

      <group description="XML" extensions="xml,tld" parser="-" type="x"/>
</file>

My code is:

	XMLConfiguration config = new XMLConfiguration(configFile);

I would like to get the "file.group" tags as a list or as an array but I
need the corresponding "description", "parser" etc.

I had no success with config.getList().

I use common-configuration-1.0 with jdk-1.4.2-07

Zsolt




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


AW: How to parse this configuration?

Posted by Zsolt Koppany <zk...@intland.com>.
Thank you Oliver,

I investigated several hours until I found out that it doesn't work with 1.0
final but 1.1-RC2.

Zsolt

> -----Ursprüngliche Nachricht-----
> Von: Oliver Heger [mailto:hegero@med.uni-marburg.de]
> Gesendet: Dienstag, 15. März 2005 07:56
> An: Jakarta Commons Users List
> Betreff: Re: How to parse this configuration?
> 
> The following code should solve your problem (not really tested):
> 
> String desc;
> int idx = 0;
> 
> do {
>    desc = config.getString("file.group(" + idx + ")[@description]");
>    if(desc != null) {
>      String ext = config.getString("file.group(" + idx +
> ")[@extensions]");
>      ...
>      idx++;
>    }  // if
> }while(desc != null);
> 
> Basically you use keys of the form
> file.group(<index>)[@<attributeName>]
> where index is a numeric index starting from 0. If you reach the end of
> the list, null will be returned.
> 
> Note: I don't know if <file> is the top level element of your XML file.
> If this is the case, you must strip the file prefix from your keys
> (because the top level element's name is not evaluated), your keys then
> may look like
> group(0)[@description]
> 
> HTH
> Oliver
> 
> Zsolt Koppany wrote:
> > Hi,
> >
> > how can I parse the following configuration?
> >
> > <file>
> > 	<group description="Web" extensions="asp,aspx,phtml,shtml,php"
> > 		parser="-" type="w"/>
> >
> >       <group description="XML" extensions="xml,tld" parser="-"
> type="x"/>
> > </file>
> >
> > My code is:
> >
> > 	XMLConfiguration config = new XMLConfiguration(configFile);
> >
> > I would like to get the "file.group" tags as a list or as an array but I
> > need the corresponding "description", "parser" etc.
> >
> > I had no success with config.getList().
> >
> > I use common-configuration-1.0 with jdk-1.4.2-07
> >
> > Zsolt
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
> 
> 
> --
> Dipl.-Inform. Oliver Heger
> Zentrale Informationsverarbeitung (ZIV) / Bereich Anwenderverfahren
> Klinikum der Philipps-Universität Marburg
> Baldingerstraße,
> D-35037 Marburg
> Tel: +49 6421 28-66923
> mailto:oliver.heger@med.uni-marburg.de
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org



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


Re: How to parse this configuration?

Posted by Oliver Heger <he...@med.uni-marburg.de>.
The following code should solve your problem (not really tested):

String desc;
int idx = 0;

do {
   desc = config.getString("file.group(" + idx + ")[@description]");
   if(desc != null) {
     String ext = config.getString("file.group(" + idx + ")[@extensions]");
     ...
     idx++;
   }  // if
}while(desc != null);

Basically you use keys of the form
file.group(<index>)[@<attributeName>]
where index is a numeric index starting from 0. If you reach the end of 
the list, null will be returned.

Note: I don't know if <file> is the top level element of your XML file. 
If this is the case, you must strip the file prefix from your keys 
(because the top level element's name is not evaluated), your keys then 
may look like
group(0)[@description]

HTH
Oliver

Zsolt Koppany wrote:
> Hi,
> 
> how can I parse the following configuration?
> 
> <file>
> 	<group description="Web" extensions="asp,aspx,phtml,shtml,php"
> 		parser="-" type="w"/>
> 
>       <group description="XML" extensions="xml,tld" parser="-" type="x"/>
> </file>
> 
> My code is:
> 
> 	XMLConfiguration config = new XMLConfiguration(configFile);
> 
> I would like to get the "file.group" tags as a list or as an array but I
> need the corresponding "description", "parser" etc.
> 
> I had no success with config.getList().
> 
> I use common-configuration-1.0 with jdk-1.4.2-07
> 
> Zsolt
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 
Dipl.-Inform. Oliver Heger
Zentrale Informationsverarbeitung (ZIV) / Bereich Anwenderverfahren
Klinikum der Philipps-Universität Marburg
Baldingerstraße,
D-35037 Marburg
Tel: +49 6421 28-66923
mailto:oliver.heger@med.uni-marburg.de

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