Ok, I used to use apache commons config years ago a little, and have probably forgotten some things.
I'm a little baffled by what's going on, and it seems counter-intuitive to me.
So, here's my code:
public static void main(String[] args) throws ConfigurationException {
XMLConfiguration config = new XMLConfiguration("config/base-config.xml");
config.setExpressionEngine(new XPathExpressionEngine());
List<Object> recipients;
recipients = config.getList("emailRecipients/recipient");
System.out.println("Recipients: " + recipients.size());
for (Object recipient : recipients) {
System.out.println("\tRecipient: " + recipient);
}
}
And here's my xml config file:
<?xml version="1.0" encoding="UTF-8"?>
<emailRecipients>
<recipient>me@email.com</recipient>
<recipient>you@email.com</recipient>
</emailRecipients>
However, my code won't read the recipient tags as I expect.
Instead, I have to modify my config file to look like so:
<?xml version="1.0" encoding="UTF-8"?>
<arbitrary-outer-tag>
<emailRecipients>
<recipient>me@email.com</recipient>
<recipient>you@email.com</recipient>
</emailRecipients>
</arbitrary-outer-tag>
So, it seems like whatever the outermost tag is has to be disregarded in the XPath expression when looking for the configuration items I need.
Why is that? Is this by design? Am I doing something incorrectly?