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)[EMAIL PROTECTED] and users.user(0)[EMAIL PROTECTED] respective.


Any help is appreciated!

Thanks,

Sven


HTH
Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to