IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Format d'échange (XML, JSON...) Java Discussion :

Générer un fichier XML avec JDOM


Sujet :

Format d'échange (XML, JSON...) Java

  1. #1
    Nouveau membre du Club

    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 38
    Points
    38
    Billets dans le blog
    1
    Par défaut Générer un fichier XML avec JDOM
    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);
                }}

  2. #2
    Nouveau membre du Club

    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 38
    Points
    38
    Billets dans le blog
    1
    Par défaut
    après lire le fichier Default.xml je veux maintenant généré et enregistre dans un autre

  3. #3
    Nouveau membre du Club

    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 38
    Points
    38
    Billets dans le blog
    1
    Par défaut
    ah Ok j'ai trouve l'erreur

Discussions similaires

  1. [JDOM] enregistrer un fichier XML avec JDOM
    Par fatenatwork dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 28/09/2007, 10h42
  2. [XML] générer un fichier xml avec du php : problème de boucle
    Par freija dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 19/02/2007, 18h25
  3. [SAX] Je dois générer un fichier XML avec SAX
    Par moi95 dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 24/01/2007, 12h22
  4. [JDOM] Création d'un fichier xml avec jdom
    Par fabricew59 dans le forum Format d'échange (XML, JSON...)
    Réponses: 4
    Dernier message: 09/08/2006, 11h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo