i can´t put my xml work correctly only me give the last value
and put in all checkbox the last value
this is my code
xml file
<?xml version="1.0"?>
<gameoptions>
<opcao id="1">
<name>Your Name</name>
<value>true</value>
</opcao>
<opcao id="2">
<name>Group Friend</name>
<value>true</value>
</opcao>
<opcao id="3">
<name>Alliance Name</name>
<value>true</value>
</opcao>
<opcao id="4">
<name>NPC Names</name>
<value>true</value>
</opcao>
<opcao id="5">
<name>Friends Names</name>
<value>true</value>
</opcao>
<opcao id="6">
<name>Enemy Names</name>
<value>true</value>
</opcao>
<opcao id="7">
<name>Display Monsters Names</name>
<value>false</value>
</opcao>
</gameoptions>
configuration.java
public List<configuration>le() {
List<configuration> Historico = new ArrayList<configuration>();
try {
File fXmlFile = new File("Game_Options.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
//optional, but recommended
//read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("opcao");
System.out.println("----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
// System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
// System.out.println("Game options id : " + eElement.getAttribute("id"));
// System.out.println("Name opção : " + eElement.getElementsByTagName("name").item(0).getTextContent());
// System.out.println("value : " + eElement.getElementsByTagName("value").item(0).getTextContent());
configuration ola = new configuration();
ola.setcodocao(eElement.getAttribute("id"));
ola.setnome(eElement.getElementsByTagName("name").item(0).getTextContent());
ola.setValidacao(eElement.getElementsByTagName("value").item(0).getTextContent());
// System.out.println(nome_opcao);
//System.out.println( validade);
Historico.add(ola);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return Historico;
}
try {
List<configuration> piloto = new configuration().le();
Iterator<configuration> pilotopro = piloto.iterator();
while (pilotopro.hasNext()) {
configuration config = pilotopro.next();
// p.getcodigoopcao();
// p.getnome();
// t = Boolean.parseBoolean(p.getvalidacao());
System.err.println("Codigo de Opcao"+ config.getcodigoopcao());
System.err.println("Nome de Opcao"+ config.getnome());
System.err.println("Validação de Opcao"+config.getvalidacao());
loginPanel = new Container();
Label fg = loginPanel.addChild(new Label("Options", new ElementId("title")));
fg.setBackground(null);
Container props = loginPanel.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Last)));
props.setBackground(null);
TabbedPanel tabs = new TabbedPanel();
tab1 = tabs.addTab("Game Options", new Container(new SpringGridLayout(Axis.X, Axis.Y)));
Container name = tab1.addChild(new Container());
Label o = name.addChild(new Label("Name", new ElementId("title")));
o.setBackground(null);
Name = name.addChild(new Checkbox("Your Name"));
Group = name.addChild(new Checkbox("Group Friend"));
Aliance = name.addChild(new Checkbox("Alliance Name"));
NPC = name.addChild(new Checkbox("NPC Names"));
friends = name.addChild(new Checkbox("Friends Names"));
Enemy = name.addChild(new Checkbox("Enemy Names"));
Monsters = name.addChild(new Checkbox("Display Monsters Name"));
Name.setChecked(config.getvalidacao()); devia ser verdadeiro e me da falso
Group.setChecked(config.getvalidacao());
Aliance.setChecked(config.getvalidacao());
NPC.setChecked(config.getvalidacao());
friends.setChecked(config.getvalidacao());
Enemy.setChecked(config.getvalidacao());
Monsters.setChecked(config.getvalidacao());
}
} catch (Exception ex) {
}