Xml
hakim
-
hakim -
hakim -
Bonjour,
Document document = builder.build(new File("patronsyntax.xml"));
Element racine = document.getRootElement();
java.util.List ls=racine.getChildren();
Element p1=(Element) ls.get(0);
java.util.List ls1= p1.getChildren() ;
Element pp=(Element) ls1.get(0);
java.util.List ls3= pp.getChildren() ;
Element pn=(Element) ls3.get(0);
Element p2=(Element) ls.get(1);
java.util.List hb= p2.getChildren() ;
Element pp1=(Element) hb.get(0);
java.util.List hb2= pp1.getChildren() ;
Element pn2=(Element) hb2.get(0);
Element p3=(Element) ls.get(2);
java.util.List hk= p3.getChildren() ;
Element pp2=(Element) hk.get(0);
java.util.List hk2= pp2.getChildren() ;
Element pn3=(Element) hk2.get(0);
Element p4=(Element) ls.get(3);
java.util.List bm= p4.getChildren() ;
Element pp3=(Element) bm.get(0);
java.util.List bm2= pp3.getChildren() ;
Element pn4=(Element)bm2.get(0);
salut je cherche de transformer ce parcour de fichier XML"patronsyntax.xml" par une boucle et non pas chaque element tout seul pour me permettre d'ajouter d'autres element a partir du fichier XML automatiquement sans retour au code
Document document = builder.build(new File("patronsyntax.xml"));
Element racine = document.getRootElement();
java.util.List ls=racine.getChildren();
Element p1=(Element) ls.get(0);
java.util.List ls1= p1.getChildren() ;
Element pp=(Element) ls1.get(0);
java.util.List ls3= pp.getChildren() ;
Element pn=(Element) ls3.get(0);
Element p2=(Element) ls.get(1);
java.util.List hb= p2.getChildren() ;
Element pp1=(Element) hb.get(0);
java.util.List hb2= pp1.getChildren() ;
Element pn2=(Element) hb2.get(0);
Element p3=(Element) ls.get(2);
java.util.List hk= p3.getChildren() ;
Element pp2=(Element) hk.get(0);
java.util.List hk2= pp2.getChildren() ;
Element pn3=(Element) hk2.get(0);
Element p4=(Element) ls.get(3);
java.util.List bm= p4.getChildren() ;
Element pp3=(Element) bm.get(0);
java.util.List bm2= pp3.getChildren() ;
Element pn4=(Element)bm2.get(0);
salut je cherche de transformer ce parcour de fichier XML"patronsyntax.xml" par une boucle et non pas chaque element tout seul pour me permettre d'ajouter d'autres element a partir du fichier XML automatiquement sans retour au code
A voir également:
- Xml
- Xml viewer - Télécharger - Édition & Programmation
- Office xml handler - Télécharger - Traitement de texte
- Driveimage xml - Télécharger - Sauvegarde
- Txt en xml - Forum Programmation
- Impossible d'ouvrir le fichier office open xml - Forum Bureautique
2 réponses
C'est pas tres clair je pense ta question, mais pour faire une boucle sur tes elements, tu fais:
Document document = builder.build(new File("patronsyntax.xml"));
Element racine = document.getRootElement();
Document document = builder.build(new File("patronsyntax.xml"));
Element racine = document.getRootElement();
for (Element elt : racine.getChildren())
{
for (Element elt2 : elt.getChildren())
{
// etc...
}
}
je travail avec java sur netbeens