Re,
voici un fichier xml
Je voudrais récuperer tous les noeuds compris dans "Logiciels installés"
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 <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="..\..\treeview.xslt"?> <treeview title="System Treeview"> <folder title="Logiciels installés" img="softwares.gif"> <folder title="7-Zip 4.09 beta" img="app_unknown.gif"> <leaf title="Date d'installation : 2005/1/31 16:18:30:0" img="arrow.gif"/> </folder> <folder title="A2iA FieldReader V2.4 R2" img="app_unknown.gif"> <leaf title="Date d'installation : 2006/2/9 10:36:26:0" img="arrow.gif"/> </folder> <folder title="A2iA FieldReader V2.5 R3" img="app_unknown.gif"> <leaf title="Date d'installation : 2006/2/9 10:39:8:0" img="arrow.gif"/> </folder> </folder> </treeview>
Voici mon code
Merci de l'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 public static void afficherInfos(Node noeud, int niv) { ArrayList liste2 = new ArrayList(); short type = noeud.getNodeType(); String nom = noeud.getNodeName(); String valeur = noeud.getNodeValue(); indenter(niv, type == Node.TEXT_NODE); System.out.print(nom + " (" + type + ") = '"); if(valeur != null && !valeur.matches("^\\s+$")) System.out.print(valeur); System.out.println("'"); if ((type == Node.DOCUMENT_NODE || type == Node.ELEMENT_NODE) && noeud.hasChildNodes()) { if(noeud.hasAttributes()) { String nom2 = noeud.getNodeName(); NamedNodeMap attributs = noeud.getAttributes(); for(int i = 0; i < attributs.getLength(); i++) { Node attribut = attributs.item(i); Node h = attributs.getNamedItem("title"); String s = h.getNodeValue(); liste2.add(i, s); afficherInfos(attribut, niv + 2); } } NodeList liste = noeud.getChildNodes(); for (int i = 0; i < liste.getLength(); i++) afficherInfos(liste.item(i), niv + 1); } }
Partager