Bonjour,
J'ai un XML sous ce format la, et je n'arrive pas à récupérer les informations pour les transformer en objet.
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <TEST> <NOM test1="a" test2="b" test3="c" test4="d"> <NOM2 test10="aa" test20="bb" test30="cc"/> <NOM3 test100="aaa" test200="bbb" test300="ccc"> <NOM4 test1000="aaaa" test2000="bbbb" test3000="cccc"/> </NOM3> </NOM> </TEST>
J'aimerais crée un objet pour chaque NOM1 ( car sur mon XML d'origine j'en ai bcp plus) et récupérer les informations tq que test10 test200 par exemple.
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 public static void main(String[] args) { String fileName = "test.xml"; jaxbXmlFileToObject(fileName); } private static void jaxbXmlFileToObject(String fileName) { File xmlFile = new File(fileName); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(Student.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Student employee = (Student) jaxbUnmarshaller.unmarshal(xmlFile); System.out.println(employee); } catch (JAXBException e) { e.printStackTrace(); } }
Merci d'avance
Partager