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 :

Ajouter un element au fichier xml [JDOM]


Sujet :

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

  1. #1
    Nouveau membre du Club
    Inscrit en
    Septembre 2007
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 38
    Points : 32
    Points
    32
    Par défaut Ajouter un element au fichier xml
    bonjour,

    je veux ajouter un element a mon fichier xml voila le code que j'ai utilisé,
    le fichier xml existe deja
    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
      public void ajouter_article(Article art)
           {
                 System.out.print("la fonction ajouter Article");
                 Element racine;
                 org.jdom.Document document=null;
                 SAXBuilder sxb=new SAXBuilder();
                 try
                 {
                     document=sxb.build(new File("article.xml"));  
                 }
                 catch(Exception e)
                 {
                    e.printStackTrace();
                 }
                 racine=document.getRootElement(); 
                 Element article=new Element("article");
                 racine.addContent(article);
                 Element id=new Element("id");
                 id.setText(String.valueOf(art.getIdentifiant()).toString());
                 article.addContent(id);
                 Element prix=new Element("prix");
                 id.setText(String.valueOf(art.getPrix()).toString());
                 article.addContent(prix);
                 Element libelle=new Element("libelle");
                 id.setText(art.getLibelle());
                 article.addContent(libelle);
               /************ enregistrement des modifications dans le fichier **********/
                 XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
                 try
                 {
                     sortie.output(document, new FileOutputStream("article.xml"));  
                 }
                 catch(Exception e)
                 {
                       e.printStackTrace();
                 }
             System.out.print(" fin ajouter Article \n ");
           }
    il m'affiche une erreur de compilation
    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
     
     
    Exception in thread "main" java.lang.NumberFormatException: For input string: "ee"
            at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
            at java.lang.Long.parseLong(Long.java:403)
            at java.lang.Long.parseLong(Long.java:461)
            at IHM.Article.lire_article(Article.java:188)
            at article_projet.Main.main(Main.java:31)
    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "ee"
            at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
            at java.lang.Long.parseLong(Long.java:403)
            at java.lang.Long.parseLong(Long.java:461)
            at IHM.Article.lire_article(Article.java:188)
            at IHM.F_Acceuil.<init>(F_Acceuil.java:32)
            at article_projet.Main$1.run(Main.java:24)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    merci pour l'aide

  2. #2
    Membre averti Avatar de Rei Angelus
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2006
    Messages
    292
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mars 2006
    Messages : 292
    Points : 356
    Points
    356
    Par défaut
    On pourrait avoir le code de la méthode lire_article où se produit l'erreur.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ajouter un root element à un fichier XML via Java
    Par filor dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 09/09/2009, 14h57
  2. retour à la ligne après ajout element en fichier xml
    Par wajdiisi2007 dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 22/08/2007, 16h07
  3. ajouter un nouvel element dans fichier XML
    Par bgcode dans le forum VB.NET
    Réponses: 5
    Dernier message: 09/07/2007, 16h57
  4. comment ajouter des élements À un fichier XML
    Par ryoussef19 dans le forum Général Dotnet
    Réponses: 1
    Dernier message: 09/07/2007, 09h14
  5. [DOM] Ajouter des noeuds à un fichier XML
    Par Louis-Guillaume Morand dans le forum Format d'échange (XML, JSON...)
    Réponses: 2
    Dernier message: 07/04/2007, 14h55

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