I am working on a class to load the configuration of an XML file, and this class is distributed from XMLConfiguration.
The configuration file looks like this:
<?xml version="1.0" encoding="UTF-8"?> <root> <global> <reloadInterval>5</reloadInterval> </global> <definitions> <definition> <id>1</id> <name>Test name</name> <messages> <message id="1">Help menu opt 1</message> <message id="2">Help menu opt 2</message> <message id="3">Help menu opt 3</message> </messages> </definition> </definitions> </root>
How do I repeat this and download the following:
private void updateDefinitions() { this.definitions.clear(); List<SubnodeConfiguration> lstDefinitions = getListConfig("definitions"); for(SubnodeConfiguration definition : lstDefinitions) { DefinitionBean aDefinition = new DefinitionBean(); aDefinition.setId(definition.getInt("Definition.id", -1)); aDefinition.setName(definition.getString("Definition.name", "")); List<MessageBean> messages = new ArrayList<MessageBean>(); List<SubnodeConfiguration> lstMessages = definition.configurationsAt("definition.messages"); for(SubnodeConfiguration messageBean : lstMessages) { MessageBean message = new MessageBean(); message.setId(messageBean.getString("message")); messages.add(message); } definition.setMessages(messages); this.definitions.put(aDefinition.getId(), aDefinition); } }
The code works fine, however the problem is to get the id attribute for each <message> element, I donβt know how to get it. None of the recipients for SubnodeConfiguration give this, or maybe I'm not doing it the right way.
Any help would be appreciated.
source share