derekzhangv wrote:
> i have a xml configuration file like this:
> how i get the config of the table user?It seems that i can only access the
> user table config by index (here is 0),but how can i know that index?
> <database>
> <tables>
> <table name="user">
> <fields>
> <field>
> <name>uid</name>
> <type>long</type>
> </field>
> <field>
> <name>uname</name>
> <type>java.lang.String</type>
> </field>
> </fields>
> </table>
> <table name="address">
> <fields>
> <field>
> <name>docid</name>
> <type>long</type>
> </field>
> <field>
> <name>name</name>
> <type>java.lang.String</type>
> </field>
> <field>
> <name>version</name>
> <type>int</type>
> </field>
> </fields>
> </table>
> </tables>
> </database>
>
In the current 1.2 release you are indeed limited to accessing
properties by an index. If you don't know the index, your only chance is
to iterate over your data in a loop incrementing the index, e.g. as follows:
int idx = 0;
while(true)
{
if("users".equals(
config.getString("tables.table(" + idx + ")@[name]"))
{
// do something
break;
}
}
Since the 1.2 release development has continued. The current version in
SVN now supports so called "expression engines", which allow to plug in
different query languages. There is also an XPATH expression engine,
which can be used for querying properties in XPATH syntax. With this you
can write something like that:
String firstUsrField = config.getString(
"/database/tables[@name='users']/fields/field[1]/name");
or use other features provided by XPATH to navigate through your
configuration. The user guide (in the SVN version) was updated to cover
these new facilities.
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
|