J'ai un problème que je n'arrive ni à cerner ni à résoudre :
1 - Je réalise plusieurs manipulations sur un fichier XML dans un programme Java avec dom4j.
2 - Je sauvegarde ce fichier XML sur demande de l'utilisateur comme suit :
3 - Lorsque je veux charger le fichier dans un document dom4j je fais ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 FileWriter fw = new FileWriter(file.getAbsoluteFile()); fw.write(doc.asXML()); fw.flush(); fw.close();
Tou va bien si le document XML ne contient aucun accent ( ou autre caractère spécial )
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 FileReader fr = new FileReader(file); char[] c = new char[new Long(file.length()).intValue()]; fr.read(c); String xml_conf = String.valueOf(c); fr.close(); SAXReader xmlReader = new SAXReader(); try{ InputStream IS = new java.io.ByteArrayInputStream(xml_conf.getBytes("UTF-8")); xmldoc = xmlReader.read(IS);
mais par exemple j' ajoute un 'é' :
Merci d'avance pour toute aide
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 org.dom4j.DocumentException: Error on line 2 of document : Expected 'EOF'. Nested exception: Expected 'EOF'. at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.dom4j.io.SAXReader.read(SAXReader.java:343) at gdpadmin.ScenarioInternalFrame.initXMLConfigFile(ScenarioInternalFrame.java:1479) at gdpadmin.ScenarioInternalFrame.<init>(ScenarioInternalFrame.java:99) at gdpadmin.GdpAdminView.openScenarioFrame(GdpAdminView.java:288) at gdpadmin.GdpAdminView.jMenuItem3ActionPerformed(GdpAdminView.java:275) at gdpadmin.GdpAdminView.access$1000(GdpAdminView.java:34) at gdpadmin.GdpAdminView$6.actionPerformed(GdpAdminView.java:183) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:357) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1220) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1261) at java.awt.Component.processMouseEvent(Component.java:6041) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5806) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4413) at java.awt.Container.dispatchEventImpl(Container.java:2116) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2440) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) Nested exception: org.xml.sax.SAXParseException: <Line 2, Column 1118>: XML-0100: (Error) Expected 'EOF'. at oracle.xml.parser.v2.XMLError.flushErrors(XMLError.java:143) at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:270) at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:150) at org.dom4j.io.SAXReader.read(SAXReader.java:465) at org.dom4j.io.SAXReader.read(SAXReader.java:343) at gdpadmin.ScenarioInternalFrame.initXMLConfigFile(ScenarioInternalFrame.java:1479) at gdpadmin.ScenarioInternalFrame.<init>(ScenarioInternalFrame.java:99) at gdpadmin.GdpAdminView.openScenarioFrame(GdpAdminView.java:288) at gdpadmin.GdpAdminView.jMenuItem3ActionPerformed(GdpAdminView.java:275) at gdpadmin.GdpAdminView.access$1000(GdpAdminView.java:34) at gdpadmin.GdpAdminView$6.actionPerformed(GdpAdminView.java:183) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:357) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1220) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1261) at java.awt.Component.processMouseEvent(Component.java:6041) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5806) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4413) at java.awt.Container.dispatchEventImpl(Container.java:2116) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2440) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) Nested exception: org.xml.sax.SAXParseException: <Line 2, Column 1118>: XML-0100: (Error) Expected 'EOF'. at oracle.xml.parser.v2.XMLError.flushErrors(XMLError.java:143) at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:270) at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:150) at org.dom4j.io.SAXReader.read(SAXReader.java:465) at org.dom4j.io.SAXReader.read(SAXReader.java:343) at gdpadmin.ScenarioInternalFrame.initXMLConfigFile(ScenarioInternalFrame.java:1479) at gdpadmin.ScenarioInternalFrame.<init>(ScenarioInternalFrame.java:99) at gdpadmin.GdpAdminView.openScenarioFrame(GdpAdminView.java:288) at gdpadmin.GdpAdminView.jMenuItem3ActionPerformed(GdpAdminView.java:275) at gdpadmin.GdpAdminView.access$1000(GdpAdminView.java:34) at gdpadmin.GdpAdminView$6.actionPerformed(GdpAdminView.java:183) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:357) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1220) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1261) at java.awt.Component.processMouseEvent(Component.java:6041) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5806) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4413) at java.awt.Container.dispatchEventImpl(Container.java:2116) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2440) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at gdpadmin.ScenarioInternalFrame.initXMLConfigFile(ScenarioInternalFrame.java:1482) at gdpadmin.ScenarioInternalFrame.<init>(ScenarioInternalFrame.java:99) at gdpadmin.GdpAdminView.openScenarioFrame(GdpAdminView.java:288) at gdpadmin.GdpAdminView.jMenuItem3ActionPerformed(GdpAdminView.java:275) at gdpadmin.GdpAdminView.access$1000(GdpAdminView.java:34) at gdpadmin.GdpAdminView$6.actionPerformed(GdpAdminView.java:183) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:357) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1220) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1261) at java.awt.Component.processMouseEvent(Component.java:6041) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5806) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4413) at java.awt.Container.dispatchEventImpl(Container.java:2116) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2440) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Partager