[configuration] certain format with XmlConfiguration

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[configuration] certain format with XmlConfiguration

Sven Schliesing-2
Hi,

I'm trying to achieve a format for my config-file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <users>
    <user>
      <name>John</name>
      <password>abc123</password>
    </user>
    <user>
      <name>Mary</name>
      <password>xyz123</password>
    </user>
  </users>
</configuration>

or like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <users>
    <user name="John" password="abc123"/>
    <user name="Mary" password="xyz123"/>
  </users>
</configuration>

But I'm totally stuck in the XmlConfiguration's methods. Is this format
possible at all?

Any help is appreciated!

Thanks,

Sven


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [configuration] certain format with XmlConfiguration

Oliver Heger-3
Hi Sven,

Sven Schliesing wrote:

> Hi,
>
> I'm trying to achieve a format for my config-file that looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration>
>   <users>
>     <user>
>       <name>John</name>
>       <password>abc123</password>
>     </user>
>     <user>
>       <name>Mary</name>
>       <password>xyz123</password>
>     </user>
>   </users>
> </configuration>
>
> or like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration>
>   <users>
>     <user name="John" password="abc123"/>
>     <user name="Mary" password="xyz123"/>
>   </users>
> </configuration>
>
> But I'm totally stuck in the XmlConfiguration's methods. Is this format
> possible at all?

Both formats are possible. After you have created a XMLConfiguration
instance (e.g. by passing your configuration file to the constructor)
you can use the various getXXX() methods for obtain the values of your
properties.

For the first format you can do something like that:

XMLConfiguration config = new XMLConfiguration("myconfigfile.xml");
String usr1 = config.getString("users.user(0).name");
String pwd1 = config.getString("users.user(0).password");

For the second user just use the numeric index 1 (you will probably
iterate over your configuration in a loop and construct the keys for
getString() dynamically; you can exit the loop if getString() returns null).

With the second format it is similar. Here you can use keys of the
following form for getString():
users.user(0)[@name] and users.user(0)[@password] respective.

>
> Any help is appreciated!
>
> Thanks,
>
> Sven
>

HTH
Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [configuration] certain format with XmlConfiguration

Sven Schliesing-2
Hi Oliver,

Works perfect. Thanks!

Sven

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [configuration] certain format with XmlConfiguration

Randall S Horwitz
In reply to this post by Sven Schliesing-2
Sven,

this format is quite possible. I've used a similar one before, been able
to read values, etc. Exactly what are you trying to do? Is it that you
can't see any values? Have a look at the XML howto. That was very helpful
in getting me started.

Randy

Randy Horwitz
IBM Human Ability & Accessibility Center
Internal: w3.ibm.com/able
External: www.ibm.com/able
Internet: [hidden email]
Phone: (512) 838 8416
Tie Line (internal to IBM): 678 8416

"It is the easy things that damn you, not the hard."
-- Joseph R Garber "Vertical Run"





"Sven Schliesing" <[hidden email]>
05/24/2006 08:36 AM
Please respond to
"Jakarta Commons Users List"


To
"Jakarta Commons Users List" <[hidden email]>
cc

Subject
[configuration] certain format with XmlConfiguration






Hi,

I'm trying to achieve a format for my config-file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <users>
    <user>
      <name>John</name>
      <password>abc123</password>
    </user>
    <user>
      <name>Mary</name>
      <password>xyz123</password>
    </user>
  </users>
</configuration>

or like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <users>
    <user name="John" password="abc123"/>
    <user name="Mary" password="xyz123"/>
  </users>
</configuration>

But I'm totally stuck in the XmlConfiguration's methods. Is this format
possible at all?

Any help is appreciated!

Thanks,

Sven


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]