Yes, it's true that empty elements don't appear in the list.

I am not sure if I fully understand your problem. Am I right that your XML file looks something like

...
<element attr="xxx"/>
<element attr="yyy">
 Some content
</element>
<element attr="zzz"/>
...

i.e. the attribute is always defined, but the content may or may not?

If this is the case you could count the elements using the getMaxIndex() method of HierarchicalConfiguration specifying the attribute key. This should look roughly like that:

int count = config.getMaxIndex("[EMAIL PROTECTED]");
for(int i = 0; i <= count; i++) {
 String elemContent = config.getString("element(" + i + ")");
 if(elemContent != null) { ... }
}

I did not test that, but the principle should work.

HTH
Oliver

Stephen Duncan wrote:

In writing my test, it seems my interpretation of the problem is
incorrect.  Sorry.  What actually happens is that my elements are not
counted if they are empty.  Since getList is supposed to be the string
content of the element, this makes sense, I guess.

My configuration xml file is a lot like the log4j xml configuration
file: frequently, all the data is in the attributes of an element, and
there is content to the element.  Is there a way to get the number of
such elements, so that I can then loop and address each by index?

-Stephen Duncan Jr


On Thu, 27 Jan 2005 15:52:18 +0100, Oliver Heger
<[EMAIL PROTECTED]> wrote:


Any chance that you provide a test case which demonstrates this
behavior? Best way is to open an error report in our bug tracking system
bugzilla (http://issues.apache.org/bugzilla/) and attach your test code.
This makes it easier for us to reproduce the problem.

I will have a look at it. Btw, which version of [configuration] do you use?

Oliver

Stephen Duncan wrote:



I'm using the hierarchicalXml configuration.

I have an element that will appear in my congifuration one or more
times.  If there are two or more, config.getList() returns the list as
I expect.  However, if there's only of these elements, then I get an
empty list.

Is there a way to fix this/get around this?  If not, what's the best
practice to deal with this?  Check for size 0 and do a simple retrieve
instead?



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










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



Reply via email to