J'ai fais ceci en suivant le tutoriel sur jdom :
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
public static void mainTest(String filePath){
		try{
			lireFichier(filePath);
		}catch(Exception e){
			System.out.println("mainTest :: Erreur dans la lecture du fichier !");
			e.printStackTrace();
		}
		try{
			editElement();
		}catch(Exception e){
			System.out.println("mainTest :: Erreur dans la modif du fichier !");
			e.printStackTrace();
		}
		try{
			enregistreFichier(filePath);
		}
		catch(Exception e){
			System.out.println("mainTest :: Erreur dans la sauvegarde du fichier !");
			e.printStackTrace();
		}
	}
 
	/**
        * Parse the file. initialize the root element
        */
	private static void lireFichier(String fichier) throws Exception {
		SAXBuilder sxb = new SAXBuilder();
		File file = new File("image1.svg");
		String abspath = file.getAbsolutePath();
		/*file = new File("../image.svg");
		abspath = file.getAbsolutePath();
		file = new File("../../image.svg");
		abspath = file.getAbsolutePath();
		file = new File("../../../image.svg");
		abspath = file.getAbsolutePath();
		file = new File(fichier);
		abspath = file.getAbsolutePath();*/
		document = sxb.build(file);
		racine = document.getRootElement();
	}
 
	/**
         * Edit some elements
         */
	private static void editElement(){
		//String element ="";
		//Dans un premier temps on liste tous les étudiants
		List listEtudiant = racine.getChildren("svg");
		Iterator i = listEtudiant.iterator();
		//On parcours la liste grâce à un iterator
		while(i.hasNext()){
			Element courant = (Element)i.next();
			//Si l'etudiant possède l'Element en question on applique
			//les modifications.
			if(courant.getAttribute("id").equals("imageSVG")){
				System.out.println("!!!!!!!!!!!!!!! TROUVE !!!!!!!!!!!!!!!");
			}
			/*
			if(courant.getChild(element)!=null){
				//On supprime l'Element en question
				courant.removeChild(element);
				//On renomme l'Element père sachant qu'une balise XML n'accepte
				//ni les espaces ni les caractères spéciaux
				//"etudiant modifié" devient "etudiant_modifie"
				courant.setName("etudiant_modifie");
			}
			*/
		}
	}
 
	/**
         * On enregsitre notre nouvelle arborescence dans le fichier
         * d'origine dans un format classique.
         */
	private static void enregistreFichier(String fichier) throws Exception {
		XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
		sortie.output(document, new FileOutputStream(fichier));
	}

mainTest est appelée dans ma classe java... avec en paramètre un chemin dont actuellement on se fiche éperduement vu que j'ai mis en dur le truc :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
File file = new File("image1.svg");
		String abspath = file.getAbsolutePath();
Après vérif en mode debug le chemin absolu du fichier est le suivant :
"C:\Java\jboss-4.2.0.CR1\bin\image1.svg"
J'y ai donc mis l'image svg

Lors de l'exécution en mode debug, je m'appercois que la ligne qui donne une exception est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
document = sxb.build(file);
La stacktrace de cette exception est la suivante :
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
 
16:57:45,339 ERROR [STDERR] java.net.ConnectException: Connection timed out: connect
16:57:45,354 ERROR [STDERR] 	at java.net.PlainSocketImpl.socketConnect(Native Method)
16:57:45,354 ERROR [STDERR] 	at java.net.PlainSocketImpl.doConnect(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at java.net.PlainSocketImpl.connect(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at java.net.Socket.connect(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at java.net.Socket.connect(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.NetworkClient.doConnect(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.www.http.HttpClient.openServer(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.www.http.HttpClient.openServer(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.www.http.HttpClient.<init>(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.www.http.HttpClient.New(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.www.http.HttpClient.New(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
16:57:45,354 ERROR [STDERR] 	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
16:57:45,370 ERROR [STDERR] 	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
16:57:45,386 ERROR [STDERR] 	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
16:57:45,386 ERROR [STDERR] 	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:810)
16:57:45,386 ERROR [STDERR] 	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:789)
16:57:45,386 ERROR [STDERR] 	at thread.MyFileThread.lireFichier(MyFileThread.java:171)
16:57:45,386 ERROR [STDERR] 	at thread.MyFileThread.mainTest(MyFileThread.java:136)
16:57:45,386 ERROR [STDERR] 	at thread.MyFileThread.run(MyFileThread.java:111)
Je ne comprend pas pourquoi.... Il n'arrive pas à charger le fichier c'est ca?