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 :

parser un fichier xml


Sujet :

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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Par défaut parser un fichier xml
    bonjours ,
    je vien de faire un parser en java qui parcour un fichiers xml ,mais la en le compilant il me donne les erreur suivante et j'arrive pas a les resoudre!!
    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
     
    File Read Error: java.io.FileNotFoundException: D:\worspace\projetparser\bdd.xml (The system cannot find the file specified)
    java.io.FileNotFoundException: D:\worspace\projetparser\bdd.xml (The system cannot find the file specified)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    	at javax.xml.parsers.SAXParser.parse(Unknown Source)
    	at javax.xml.parsers.SAXParser.parse(Unknown Source)
    	at VSX.parse(VSX.java:25)
    	at VSX.main(VSX.java:126)


    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
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
     
     
    import java.io.File;
     
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeModel;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
     
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
     
    public class VSX {
     
      public TreeModel parse(String filename) {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        XMLTreeHandler handler = new XMLTreeHandler();
        try {
          // Parse the input.
          SAXParser saxParser = factory.newSAXParser();
          saxParser.parse(new File(filename), handler);
        } catch (Exception e) {
          System.err.println("File Read Error: " + e);
          e.printStackTrace();
          return new DefaultTreeModel(new DefaultMutableTreeNode("error"));
        }
        return new DefaultTreeModel(handler.getRoot());
      }
     
      public static class XMLTreeHandler extends DefaultHandler {
        private DefaultMutableTreeNode root, currentNode;
     
        public DefaultMutableTreeNode getRoot() {
          return root;
        }
     
        // SAX Parser Handler methods...
        public void startElement(String namespaceURI, String lName,
            String qName, Attributes attrs) throws SAXException {
          String eName = lName; // Element name
          if ("".equals(eName))
            eName = qName;
          Tag t = new Tag(eName, attrs);
          DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(t);
          if (currentNode == null) {
            root = newNode;
          } else {
            // Must not be the root node...
            currentNode.add(newNode);
          }
          currentNode = newNode;
        }
     
        public void endElement(String namespaceURI, String sName, String qName)
            throws SAXException {
          currentNode = (DefaultMutableTreeNode) currentNode.getParent();
        }
     
        public void characters(char buf[], int offset, int len)
            throws SAXException {
          String s = new String(buf, offset, len).trim();
          ((Tag) currentNode.getUserObject()).addData(s);
        }
      }
     
      public static class Tag {
        private String name;
     
        private String data;
     
        private Attributes attr;
     
        public Tag(String n, Attributes a) {
          name = n;
          attr = a;
        }
     
        public String getName() {
          return name;
        }
     
        public Attributes getAttributes() {
          return attr;
        }
     
        public void setData(String d) {
          data = d;
        }
     
        public String getData() {
          return data;
        }
     
        public void addData(String d) {
          if (data == null) {
            setData(d);
          } else {
            data += d;
          }
        }
     
        public String getAttributesAsString() {
          StringBuffer buf = new StringBuffer(256);
          for (int i = 0; i < attr.getLength(); i++) {
            buf.append(attr.getQName(i));
            buf.append("=\"");
            buf.append(attr.getValue(i));
            buf.append("\"");
          }
          return buf.toString();
        }
     
        public String toString() {
          String a = getAttributesAsString();
          return name + ": " + a + (data == null ? "" : " (" + data + ")");
        }
      }
     
      public static void main(String args[]) {
        JFrame frame = new JFrame("VSX Test");
        VSX parser = new VSX();
        JTree tree = new JTree(parser.parse("bdd.xml"));
        frame.getContentPane().add(new JScrollPane(tree));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 400);
        frame.setVisible(true);
      }
    }

  2. #2
    Membre chevronné Avatar de Shivaneth
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2004
    Messages
    349
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France, Loire Atlantique (Pays de la Loire)

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

    Informations forums :
    Inscription : Mai 2004
    Messages : 349
    Par défaut
    Bonjour,
    le message d'erreur est assez explicite :
    File Read Error: java.io.FileNotFoundException: D:\worspace\projetparser\bdd.xml (The system cannot find the file specified)
    Le fichier
    D:\worspace\projetparser\bdd.xml
    n'existe pas.

  3. #3
    Membre Expert

    Profil pro
    Inscrit en
    Mai 2006
    Messages
    895
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 895
    Par défaut
    Salut,
    Le problème vient peut être du fait que ton fichier n'existe pas. Lit bien le chemin qu'il t'indique dans ton message d'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    D:\worspace\projetparser\bdd.xml
    Si tu rajoutes un 'k' à worspace ça passerait peut être mieux.
    ++

  4. #4
    Membre éclairé Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Par défaut
    j'ai suivi le chemin indiquer ,et j'ai bien verifier ,le fichier "bdd.xml" se trouve bien la bas !!

    c bizar!!!

  5. #5
    Membre Expert

    Profil pro
    Inscrit en
    Mai 2006
    Messages
    895
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 895
    Par défaut
    Il ne faut pas seulement verifier le nom de ton fichier mais également celui de tes répertoires.
    Tu as mal écrit workspace, il te manque un k.

  6. #6
    Membre éclairé Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Par défaut
    oui ellene je t'ai compris , j'ai ajouté le "k" mais c la meme chose!!

    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
     
    File Read Error: java.io.FileNotFoundException: D:\workspace\projetparser\bdd.xml (The system cannot find the file specified)
    java.io.FileNotFoundException: D:\workspace\projetparser\bdd.xml (The system cannot find the file specified)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    	at javax.xml.parsers.SAXParser.parse(Unknown Source)
    	at javax.xml.parsers.SAXParser.parse(Unknown Source)
    	at VSX.parse(VSX.java:25)
    	at VSX.main(VSX.java:126)

  7. #7
    Membre chevronné Avatar de Shivaneth
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2004
    Messages
    349
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France, Loire Atlantique (Pays de la Loire)

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

    Informations forums :
    Inscription : Mai 2004
    Messages : 349
    Par défaut
    Oui mais le répertoire workspace n'est pas parametré dans le programme, c'est le dossier ou se trouve l'application. Peu importe s'il est mal nommé, il cherche dans le répertoire d'exécution.

  8. #8
    Membre éclairé Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Par défaut
    j'ai pas bien compris ce que vous venez de dire 'Shiva Skunk' , svp expliquez moi plus
    merci

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

Discussions similaires

  1. problème pour parser un fichier xml avec XML::Simple
    Par black_code dans le forum Modules
    Réponses: 3
    Dernier message: 30/01/2006, 19h32
  2. [xslt] Parser 2 fichiers XML
    Par malekms dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 30/12/2005, 12h22
  3. Parser un fichier XML
    Par Charlinecha dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 11/07/2005, 17h18
  4. [SAX] parser un fichier xml en Java
    Par royou dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 10/02/2005, 17h12
  5. parser des fichier .xml en perl
    Par djibril dans le forum Modules
    Réponses: 13
    Dernier message: 18/05/2004, 17h08

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