I have an XML like this:
1
Declaration of Human Rights
You should read it recursively, some time ago I had the same question and solve with this code:
public void proccessMenuNodeList(NodeList nl, JMenuBar menubar) {
for (int i = 0; i < nl.getLength(); i++) {
proccessMenuNode(nl.item(i), menubar);
}
}
public void proccessMenuNode(Node n, Container parent) {
if(!n.getNodeName().equals("menu"))
return;
Element element = (Element) n;
String type = element.getAttribute("type");
String name = element.getAttribute("name");
if (type.equals("menu")) {
NodeList nl = element.getChildNodes();
JMenu menu = new JMenu(name);
for (int i = 0; i < nl.getLength(); i++)
proccessMenuNode(nl.item(i), menu);
parent.add(menu);
} else if (type.equals("item")) {
JMenuItem item = new JMenuItem(name);
parent.add(item);
}
}
Probably you can adapt it for your case.