Bonjour,
après avoir lire un fichier xml et importe la valeur Attribute,qui je veux
je veux maintenant générer un nouveau fichier xml mais j'ai des problème dans cet partie mon code est le suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
static org.jdom2.Document document;
static Element racine;
static Element racineNew;
static org.jdom2.Document documentNew = new Document(racineNew);
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
 try {
                lireFichier("Default.xml");
                } catch (Exception ex) {
                Logger.getLogger(SibylleVu.class.getName()).log(Level.SEVERE, null, ex);
            }
            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)){
                        /* Récupere Nombre attribut Row*/
                        String Row=Keypad.getAttributeValue("Rows");
                        Integer row = Integer.valueOf(Row);
                        int R=row.intValue();
                        R=R+count;
                        System.out.println(""+R);
                        Keypad.removeAttribute("Rows");
                        String Rowx = Integer.toString(R);
                        Keypad.setAttribute("Rows", Rowx);
                        String Rows=Keypad.getAttributeValue("Rows");
                        Integer rrow=Integer.valueOf(Rows);
                        System.out.println(""+rrow);
                             List listeKeys=Keypad.getChildren("Keys");
                             for(int f=0;f<listeKeys.size();f++){
                             Element Keys=(Element) listeKeys.get(f);
                             Keys.removeChildren("Key");
                                 List listeKey=Keys.getChildren("Key"); 
 
                                for(int g=0;g<R;g++){
 
 
                            Element Keypadss = new Element("Keypads");
      racineNew.addContent(Keypadss);
 
 
      //On crée un nouvel Attribut classe et on l'ajoute à etudiant
     //grâce à la méthode setAttribute
      Element Keypadd = new Element("Keypad");
      Keypadss.addContent(Keypadd);
      Attribute Name  = new Attribute("Name","Mots");
      Keypadd.setAttribute(Name);
      Attribute Rowss=new Attribute("Row", "8");
      Keypadd.setAttribute(Rowss);
      Attribute Columns=new Attribute("Columns", "1");
      Keypadd.setAttribute(Columns);
      Attribute X=new Attribute("X", "610");
      Keypadd.setAttribute(X);
      Attribute Y=new Attribute("Y", "172");
      Keypadd.setAttribute(Y);
      Attribute Width=new Attribute("Width", "300");
      Keypadd.setAttribute(Width);
      Attribute Height=new Attribute("Height", "565");
      Keypadd.setAttribute(Height);
      Attribute Options=new Attribute("Options", "Word");
      Keypadd.setAttribute(Options);
      //On crée un nouvel Element nom, on lui assigne du texte
      //et on l'ajoute en tant qu'Element de etudiant
       Element Keyss = new Element("Keys");
       Keypadd.addContent(Keyss);
       String rows=Keypadd.getAttributeValue("Row");
       Integer rowx = Integer.valueOf(rows);
 
          Element Key = new Element("Key");
        Keys.addContent(Key);
        Attribute Roww  = new Attribute("Row",""+f);
        Key.setAttribute(Roww);
        Attribute Column = new Attribute("Column","0");
        Key.setAttribute(Column);
        Attribute Command = new Attribute("Command","WritePrediction");
        Key.setAttribute(Command);
        Attribute Arg0 = new Attribute("Arg0","");
        Key.setAttribute(Arg0);
        Attribute Option = new Attribute("Options","PredictedWord");
        Key.setAttribute(Option);
 
 
 
 
                     }
                 }
               }
            } 
            try {
                affiche();
                enregistreFichier("XML_résultat.xml");
            } catch (Exception ex) {
                Logger.getLogger(SibylleVu.class.getName()).log(Level.SEVERE, null, ex);
            }}