-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReaderXml.java
More file actions
41 lines (31 loc) · 1.45 KB
/
ReaderXml.java
File metadata and controls
41 lines (31 loc) · 1.45 KB
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
import java.io.*;
import java.util.*;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
public class ReaderXml{
public static void main(String[] args){
try{
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new File("agenda.xml"));
Element root = document.getRootElement();
List<Element> children = root.getChildren();
Iterator<Element> iterator = children.iterator();
while(iterator.hasNext()){
Element item = (Element)iterator.next();
Element start = item.getChild("Start");
System.out.println("Id: " +item.getAttributeValue("id"));
System.out.println("Name: "+item.getChild("Name").getText());
System.out.println("Place: "+item.getChild("Place").getText());
System.out.println("Start: "+start.getChild("Day").getText()+"/"+start.getChild("Month").getText()+"/"+start.getChild("Year").getText()+" "+start.getChild("Hour").getText()+":"+start.getChild("Minute").getText());
System.out.println("Notify: "+item.getChild("Notify").getText());
System.out.println("Alerted: "+item.getChild("Alerted").getText());
System.out.println("Important: "+item.getChild("Important").getText());
System.out.println();
}
}catch(Exception e){
System.err.println("Errore durante la lettura dal file");
e.printStackTrace();
}
}
}