salezica
salezica

Reputation: 76909

Java, Apache Commons Configuration XML attributes

I'm reading config from an XML file using Apache's commons.configuration. In one of the sections, I have several lines in the form of:

<bla attr1="something" attr2="something else" />

Ideally, I would like to do something like this:

List blas = config.getList("section.bla");
String attr1 = blas.get(0).getAttribute("attr1");

(The code above does not work, obviously)

Is this possible somehow, or do I have to query each attribute separately in the XPath-like notation, iterating myself through the list?

Upvotes: 1

Views: 1674

Answers (2)

user1448668
user1448668

Reputation: 79

I think this is what you are looking for:

http://commons.apache.org/proper/commons-configuration/userguide-1.2/howto_xml.html

It would be something like this:

config.getString("bla(0)[@attr1]")

Upvotes: 1

salezica
salezica

Reputation: 76909

Well, I ended up manually iterating and querying for everything separately.

Upvotes: 0

Related Questions