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
|
Element racine;
Document doc;
String toto = "<?xml version=\"1.0\"?>" +
"<racine>" +
"<couple><nom>tutu</nom><prenom>bebere</prenom></couple>" +
"<couple><nom>toto</nom><prenom>roger</prenom></couple>" +
"<couple><nom>tata</nom><prenom>jul</prenom></couple>" +
"</racine>";
SAXBuilder sx = new SAXBuilder();
InputStream inputStream = new ByteArrayInputStream(toto.getBytes());
try {
doc = sx.build(inputStream);
racine = doc.getRootElement();
List listEtudiants = racine.getChildren();
Iterator i = listEtudiants.iterator();
while(i.hasNext())
{
Element courant = (Element)i.next();
System.out.println(courant.getChild("nom").getText() + " " + courant.getChild("prenom").getText());
System.out.println();
}
}
catch (Exception e) {e.printStackTrace();} |