Sur cette page, la personne qui a posé sa question semble avoir la même erreur que toi. En espérant que cela puisse t'aider...
++
Version imprimable
Sur cette page, la personne qui a posé sa question semble avoir la même erreur que toi. En espérant que cela puisse t'aider...
++
c'est un simple fichier xml que je l'ai pris sur internet juste pour tester le programme je pense pas qu'il y a un problem dedans
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <?xml version="1.0" encoding="ISO-8859-1"?> <database name="infos"> <table name="codeDepartement"> <record> <field name="ID" type="string">01</field> <field name="NOM" type="string">Ain</field> </record> <record> <field name="ID" type="string">02</field> <field name="NOM" type="string">Aisne</field> </record> <record> <field name="ID" type="string">03</field> <field name="NOM" type="string">Allier</field> </record> </table> </database>
Ton fichier ne passe pas les validateurs xml (Exemple ici)
bonjours tout le monde
bon Shiva Skunk ,j'ai suivi tes conseille effectivement le fichier n'est pas valider donc j'ai changer pas mal de fois mon fichier xml et toujours la meme chose "il n'est pas valider"
et j'ai chercher sur internet et j'ai trouver ca
en haut de la page le validator present marche de la meme facon que celui que vous m'avez donnez , mais en bas de page il y a "Validate Your XML Against a DTD" et la mon fichier est valide mais comme meme en compilant mon parser sur eclipse les meme faute sont là !!
vraiment c'est etonant et bizars!!
bonjours
s'il vous plait est-ce que quelqu'un de vous peut executer ce petit programme et me dit qu'estce qui ce passe avec
et utilisez un simple fichier xml que vous le nommez "bdd.xml"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
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
134
135 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); File f =new File(filename); saxParser.parse( f, 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); } }
moi en le compilant avec eclipse et en mettant le fichier "bdd.xml" dans le workspace j'ai trouvé ces erreurs qui me semble bizar!!
et merci pour votre aideCode:
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: C:\Documents and Settings\AnisKhalifa\Desktop\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\projetparser\bdd.xml (The system cannot find the file specified) java.io.FileNotFoundException: C:\Documents and Settings\AnisKhalifa\Desktop\eclipse-SDK-3.3.1.1-win32\eclipse\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:27) at VSX.main(VSX.java:128)
en changeant le fichier xml je trouve chaque fois la meme erreur q'avant mais la en choisisant ce fichier
j'ai eu cette erreur:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?xml version="1.0" encoding="UTF-8"?> <annuaire> <personne id="0"> <nom>nom0</nom> <prenom>prenom0</prenom> <adresse>adresse0</adresse>> </personne> <personne id="1"> <nom>nom1</nom> <prenom>prenom1</prenom>> <adresse>adresse1</adresse> </personne> </annuaire>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 File Read Error: org.xml.sax.SAXParseException: The element type "personne" must be terminated by the matching end-tag "</personne>". org.xml.sax.SAXParseException: The element type "personne" must be terminated by the matching end-tag "</personne>". at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(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:27) at VSX.main(VSX.java:128)
Bonjour,
bon je ne sais pas expliqer ton erreur. Mais je viens de creer un projet Eclipse avec ta classe Java et ton fichier bdd.xml et ca marche tres bien. Je t'envoie le projet Eclipse.
Test et dis nous si ca marche.
Angelo
merci beaucoup pour ton aide le programme marche mais avec des exceptions.
quand je lance le projet que vous m'avez envoyer la fenetre affiche l'arboressence du fichier XML et met entre parenthese la faute trouver dans le fichier, comme exemple
et ca c'est tres bien.Code:
1
2
3 personne(>) // ce qui signifie qu'il y a une ">" en plus dans le fichier dans la balise "personne"
mais le fait de faire d'autre faute expré pour tester le programme comme la suppression par exemple d'un "</personne>" ou ajouter "<", la fenetre s'affiche avec le mot "error" dedans et la console d'eclipse sort le message suivant
en lisant ce rapport en vois bien qu'il dit que la balise "personne"doit terminer avec un </personne>, et moi je veux que cette faute soit elle aussi vu dans la fenetre. est-ce que vous avez une idée ?Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 File Read Error: org.xml.sax.SAXParseException: The element type "personne" must be terminated by the matching end-tag "</personne>". org.xml.sax.SAXParseException: The element type "personne" must be terminated by the matching end-tag "</personne>". at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(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:26) at VSX.main(VSX.java:127)
Il faudrait que tu lises les specifications XML.
le contenu XML
est un contenu XML valide.Code:
1
2
3 <prenom>prenom0</prenom> <adresse>adresse0</adresse>> </personne>
Par contre
n'est pas un contenu XML valide. Aucun parser XML (SAX, DOM...) ne pourra te parser ce XML.Code:
1
2
3 <prenom>prenom0</prenom> <adresse>adresse0</adresse>< </personne>
Si tu rajoutes le code :
dans ta classe XMLTreeHandler, tu verras que le FATAL error est appele (voir ErrorHandler de SAX) et le parseur stoppe son parsing.Code:
1
2
3
4
5
6
7
8
9
10
11 public void error(SAXParseException saxparseexception) throws SAXException { System.out.println("Error"); } public void fatalError(SAXParseException saxparseexception) throws SAXException { System.out.println("FATAL error"); }
Angelo
j'ai bien compris ce que vous vennez de m'expliquerazerr, merci beaucoup.
en fait moi je veux bien avoir, en parsant un fichier xml, les erreur qui ce trouve dedans quelque soit la faute et l'affiché dans la fenetre aprés avoir executer le programme, est-ce que cette tache et infesable?
t.n.b.g,
Je ne pense pas que ca soit très bénéfique que je te fasse le code. La tu as tous les elements pour afficher l'erreur.
Soit tu le fait apres la catch (en remplacant error par la stack trace de e :
soit le fait dans le fatalError.Citation:
} catch (Exception e) {
System.err.println("File Read Error: " + e);
e.printStackTrace();
return new DefaultTreeModel(new DefaultMutableTreeNode("error" + e));
}
Angelo
merci beaucoup pour ton aide :king:
je te dirai apres qu'est ce que c'est passer avec
:merci: