-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathXMLPPDemo.java
More file actions
38 lines (34 loc) · 1.11 KB
/
Copy pathXMLPPDemo.java
File metadata and controls
38 lines (34 loc) · 1.11 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
import java.io.FileReader;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
public class XMLPPDemo{
public static void main(String[] args) throws IOException, XmlPullParserException{
if(args.length!=1){
System.err.println("usage: java XMLPPDemo xmlfile");
return;
}
XmlPullParserFactory xmppFactory = XmlPullParserFactory.newInstance();
xmppFactory.setNamespaceAware(true);
XmlPullParser xmlpp = xmppFactory.newPullParser();
xmlpp.setInput(new FileReader(args[0]));
int eventType = xmlpp.getEventType();
while(eventType!=XmlPullParser.END_DOCUMENT){
switch(eventType){
case XmlPullParser.START_DOCUMENT:
System.out.println("Start document");
break;
case XmlPullParser.START_TAG:
System.out.println("Start tag: " + xmlpp.getName());
break;
case XmlPullParser.TEXT:
System.out.println("Text: " + xmlpp.getText());
break;
case XmlPullParser.END_TAG:
System.out.println("End tag: " + xmlpp.getName());
}
eventType = xmlpp.next();
}
}
}