1import java.io.File;
2
3import javax.xml.parsers.DocumentBuilder;
4import javax.xml.parsers.DocumentBuilderFactory;
5
6import org.w3c.dom.Document;
7import org.w3c.dom.NodeList;
8
9public class Demo {
10
11 public static void main(String[] args) throws Exception {
12 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
13 DocumentBuilder db = dbf.newDocumentBuilder();
14 Document document = db.parse(new File("input.xml"));
15 NodeList nodeList = document.getElementsByTagName("Item");
16 for(int x=0,size= nodeList.getLength(); x<size; x++) {
17 System.out.println(nodeList.item(x).getAttributes().getNamedItem("name").getNodeValue());
18 }
19 }
20}