lire xml jdom et retour x
Bonjour les amis :)
j'ai besoin de l'aide
dans cet class je peux lire l'attribut x qui je veux
mais comment retourne une valeur x pour l’utiliser dans un autre classe
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class Jdom {
public Jdom() throws DataConversionException, SAXException, IOException, ParserConfigurationException{
DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
// création d'un constructeur de documents
DocumentBuilder constructeur = fabrique.newDocumentBuilder();
// lecture du contenu d'un fichier XML avec DOM
File xml = new File("Default.xml" );
org.w3c.dom.Document document = constructeur.parse(xml);
DOMBuilder db=new DOMBuilder();
Document dc=db.build(document);
Element racine=dc.getRootElement();
List listeKeypads =racine.getChildren("Keypads");
for (int i=0 ;i<listeKeypads.size();i++)
{
Element Keypads=(Element) listeKeypads.get(i);
List listeKeypad = Keypads.getChildren("Keypad");
for (int j=0;j<listeKeypad.size();j++){
Element Keypad =(Element) listeKeypad.get(j);
String name=Keypad.getAttribute("Name").getValue();
if("Mots".equals(name)){
List listeKeys=Keypad.getChildren("Keys");
for(int f=0;f<listeKeys.size();f++){
Element Keys=(Element) listeKeys.get(f);
System.out.println(Keys);
List listeKey=Keys.getChildren("Key");
for(int g=0;g<listeKey.size();g++){
Element Key=(Element) listeKey.get(g);
System.out.println(Key.getAttribute("Rows"));
JButton button = new JButton();
// Key.getAttributeValue("Row");
int x=Key.getAttribute("Row").getIntValue();
}
}}}}
}} |