1 2 4 package eventlist; 5 6 import java.io.*; 7 8 import org.xmlpull.v1.*; 9 10 public class EventList { 11 12 public static void main (String [] args) throws IOException, XmlPullParserException{ 13 XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); 14 factory.setNamespaceAware(true); 15 Reader reader = (args.length > 0) ? 16 new FileReader (args [0]) : 17 (Reader) new StringReader("<sample>Hello World!</sample>"); 18 XmlPullParser xpp = factory.newPullParser(); 19 xpp.setInput (reader); 20 int eventType; 21 while ((eventType = xpp.next()) != xpp.END_DOCUMENT) { 22 if(eventType == xpp.START_TAG) { 23 System.out.println("START_TAG "+xpp.getName()); 24 } else if(eventType == xpp.END_TAG) { 25 System.out.println("END_TAG "+xpp.getName()); 26 } else if(eventType == xpp.TEXT) { 27 System.out.println("TEXT "+xpp.getText()); 28 } 29 } 30 31 } 32 33 } 34 35 | Popular Tags |