Bonjour,
Je souhaite valider un fichier xml (fournit par un serveur), j'ai la DTD tout marche ok. Sauf lorsque je veux faire un jar et donc valider le XML par la DTD contenu dans le jar. J'ai evidemment fait une recherche et j'ai trouvé la solution EntityResolver. Je l'ai implémenter mais lors de la validation il chercher toujours ma DTD dans le repertoire courant :s
Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 public class MyEntityResolver implements EntityResolver{ public InputSource resolveEntity(String publicid, String sysid) { System.out.println("Apl de resolveEntity "+ getClass().getResource("/Omniloc_SLIA.DTD").getPath()); return new InputSource(getClass().getResourceAsStream("/Omniloc_SLIA.DTD")); } }
Le code
L'erreur que ca declenche
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 Document doc=new Document(); SAXBuilder sxb = new SAXBuilder(); StringReader strReader=new StringReader(xmlString); try { sxb.setEntityResolver(new MyEntityResolver()); doc = sxb.build(strReader); } catch (JDOMException saxe) { saxe.printStackTrace(System.err); throw new OmnilocException(OmnilocException.XMLFORMAT_ERROR); } catch (IOException io) { io.printStackTrace(System.out); System.out.println("IMPOSSIBLE DE PARSER LE StringReader"); }
Apparemment l'EntityResolver est bien en place mais il cherche tout de même le fichier local ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 Apl de resolveEntity file:/C:/Services/mmsmap.jar!/Omniloc_SLIA.DTD Avant le return java.io.FileNotFoundException: C:\Documents and Settings\juzi8222\Omniloc_SLIA.D TD (Le fichier spÚcifiÚ est introuvable) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at java.io.FileInputStream.<init>(FileInputStream.java:66) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection... .java:70)
Voici le fichier XML au cas où :
Merci d avance
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 Omniloc : CONNEXION ETABLIE <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE omniloc SYSTEM "Omniloc_SLIA.DTD"> <omniloc> <hdr> <client> <id>ammasis</id> <pwd>6436</pwd> </client> </hdr> <slia> <pos> <msid>0682576517</msid> <pd> <time utc_off="+0200">20060712140917</time> <address> <number></number> <way>Boulevard des Fr?res Voisin</way> <postalcode>92130</postalcode> <city>Issy-les-Moulineaux</city> </address> <shape> <CircularArcArea> <coord> <X>484940N</X> <Y>0021614E</Y> </coord> <inRadius>0</inRadius> <outRadius>353</outRadius> <startAngle>0</startAngle> <stopAngle>360</stopAngle> </CircularArcArea> </shape> <lev_conf>100</lev_conf> </pd> </pos> </slia> </omniloc>
Julie.
Partager