import java.io.File; import java.io.IOException; import java.util.List; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; public class ReadXML { public static void main(String[] args) { String filePath ="staff.xml"; System.out.println(" hellooooo TP 01"); //Read(filePath); } public static void Read(String filePath) { SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(filePath); try { Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List list = rootNode.getChildren("staff"); for (int i = 0; i < list.size(); i++) { Element node = list.get(i); System.out.println("Staff id = " + node.getAttributeValue("id")); System.out.println("First Name : " + node.getChildText("firstname")); System.out.println("Last Name : " + node.getChildText("lastname")); System.out.println("Nick Name : " + node.getChildText("nickname")); System.out.println("Salary : " + node.getChildText("salary")); System.out.println("\n--------------------------------------------"); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } } }