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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Vector;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class XMLData {
public static class Membre {
public String prenom;
public String nom;
public String exp;
public String elo;
public String elomax;
public String tel;
public String mail;
public String actif;
public Membre(String p, String n, String ex, String el,
String elm, String t, String em, String a) {
this.prenom = p;
this.nom = n;
this.exp = ex;
this.elo = el;
this.elomax = elm;
this.tel = t;
this.mail = em;
this.actif = a;
}
}
static Vector<Membre> listeDesMembres = new Vector<Membre>();
public static void ajoutMembre(Membre m) {
listeDesMembres.add(m);
}
public static Vector<Membre> ListeMembres() {
SAXBuilder builder = new SAXBuilder();
File xmlfile = new File("membres.xml");
try {
Document document = (Document) builder.build(xmlfile);
Element rootNode = document.getRootElement();
@SuppressWarnings("rawtypes")
List list = rootNode.getChildren("membre");
for (int i = 0; i < list.size(); i++) {
Element node = (Element)list.get(i);
ajoutMembre(new Membre(node.getChildText("prenom"),
node.getChildText("nom"),
node.getChildText("exp"),
node.getChildText("elo"),
node.getChildText("elomax"),
node.getChildText("tel"),
node.getChildText("mail"),
node.getChildText("actif")));
System.out.println("Prenom " + node.getChildText("prenom"));
System.out.println("Nom " + node.getChildText("nom"));
System.out.println("Exp " + node.getChildText("exp"));
System.out.println("Elo " + node.getChildText("elo"));
System.out.println("EloMax " + node.getChildText("elomax"));
System.out.println("Tel " + node.getChildText("tel"));
System.out.println("Email " + node.getChildText("mail"));
System.out.println("Actif " + node.getChildText("actif"));
System.out.println();
}
System.out.println ("Nombre de membres : " + listeDesMembres.size());
} catch (IOException io) {
System.out.println(io.getMessage());
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
}
return listeDesMembres;}
} |
Partager