Skip to content

Commit a520e8e

Browse files
committed
Explore the xmlpull API, BUT javac -cp still cannot work.
1 parent 2e0d8e1 commit a520e8e

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Chapter15/XMLPPDemo.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.FileReader;
2+
import java.io.IOException;
3+
4+
public class XMLPPDemo{
5+
6+
public static void main(String[] args) throws IOException, XmlPullParserException{
7+
if(args.length!=1){
8+
System.err.println("usage: java XMLPPDemo xmlfile");
9+
return;
10+
}
11+
XmlPullParserFactory xmppFactory = XmlPullParserFactory.newInstance();
12+
xmppFactory.setNamespaceAware(true);
13+
xmlPullParser xmlpp = xmppFactory.newPullParser();
14+
15+
xmlpp.setInput(new FileReader(args[0]));
16+
int eventType = xmlpp.getEventType();
17+
while(eventType!=XmlPullParser.END_DOCUMENT){
18+
switch(eventType){
19+
case XmlPullParser.START_DOCUMENT:
20+
System.out.println("Start document");
21+
break;
22+
case XmlPullParser.START_TAG:
23+
System.out.println("Start tag: " + xmlpp.getName());
24+
break;
25+
case XmlPullParser.TEXT:
26+
System.out.println("Text: " + xmlpp.getText());
27+
break;
28+
case XmlPullParser.ENT_TAG:
29+
System.out.println("End tag: " + xmlpp.getName());
30+
}
31+
eventType = xmlpp.next();
32+
}
33+
}
34+
}

Chapter15/xmlpull-1.1.3.1.jar

7.02 KB
Binary file not shown.

0 commit comments

Comments
 (0)