-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse.java
More file actions
34 lines (25 loc) · 781 Bytes
/
parse.java
File metadata and controls
34 lines (25 loc) · 781 Bytes
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
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
public class parse{
public static void main(String[] args){
try{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbFactory.newDocumentBuilder();
File inputFile = new File(args[0]);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputFile);
NodeList nl = doc.getElementsByTagName("name");
for (int i=0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
System.out.println(node.getTextContent());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}