XML Pull Parsing (Demo)
by , 11-22-2011 at 05:58 PM (1211 Views)
XML Pull Parsing makes parsing XML documents easier and efficient. This post introduces this API.
You may get the required API from http://www.xmlpull.org/.
Java docs are available at: http://www.xmlpull.org/v1/doc/api/or...ullParser.html
Let me present an example of parsing XML using XML Pull Parsing.
Output:Java Code:public class SimpleXmlPullApp { public static void main (String args[]) throws XmlPullParserException, IOException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); xpp.setInput( new StringReader ( "Hello World!" ) ); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_DOCUMENT) { System.out.println("Start document"); } else if(eventType == XmlPullParser.END_DOCUMENT) { System.out.println("End document"); } else if(eventType == XmlPullParser.START_TAG) { System.out.println("Start tag "+xpp.getName()); } else if(eventType == XmlPullParser.END_TAG) { System.out.println("End tag "+xpp.getName()); } else if(eventType == XmlPullParser.TEXT) { System.out.println("Text "+xpp.getText()); } eventType = xpp.next(); } } }
Start document
Start tag foo
Text Hello World!
End tag foo









Email Blog Entry
Size Reduced for Images in PDF &...
05-15-2013, 05:53 PM in Java Software