Bonjour,
J'ai un petit soucis avec mon parseur, il bloque au root ..
La partie en XML qui pose problème :
Le Java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?> <ns1:rule xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns1='http://www.mySiteWeb.com' xsi:schemaLocation='http://www.mySiteWeb.com mySchema.xsd'> <actions> <notifyUser> <!-- mail of the user who will be notified --> <mail>mytest@mail.com</mail> </notifyUser> </actions> </ns1:rule>
L'erreur que j'ai :
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 package exercice; import java.io.*; import org.jdom2.*; import org.jdom2.input.SAXBuilder; import java.util.List; import java.util.Iterator; public class Pars { static org.jdom2.Document document; static Element racine; static String MY_XML_FILE = "C:\\Users\\Oxgan\\Desktop\\myXml.xml"; public static void main(String[] args) throws JDOMException, IOException { SAXBuilder sxb = new SAXBuilder(); document = sxb.build(new File(MY_XML_FILE)); racine = document.getRootElement(); List notifyUser; List test = racine.getChildren("actions"); Iterator i = test.iterator(); while(i.hasNext()) { Element courant = (Element)i.next(); notifyUser = courant.getChildren("notifyUser"); Iterator j = notifyUser.iterator(); while(j.hasNext()){ Element courant2 = (Element)j.next(); System.out.println(courant2.getChild("mail").getText()); } } } }Donc je suppose qu'il trouve ns1 mais pas rule .. comment je peux passer au travers de ce problème ?Exception in thread "main" org.jdom2.input.JDOMParseException: Error on line 4 of document file:/C:/Users/Oxgan/Desktop/exampleXml.xml: Le préfixe "ns1" de l'élément "ns1:rule" n'est pas lié.
Merci d'avance !
Partager