Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In Android, the XmlPullParser is recommended when doing XML. Here's a very simple example on how to use it.</p> <pre><code> import java.io.IOException; import java.io.StringReader; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException.html; import org.xmlpull.v1.XmlPullParserFactory; 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 ("&lt;foo&gt;Hello World!&lt;/foo&gt;")); 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(); } } } </code></pre> <p>Here are some links that might help:</p> <ul> <li>Several approaches - <a href="http://www.ibm.com/developerworks/opensource/library/x-android/" rel="nofollow">http://www.ibm.com/developerworks/opensource/library/x-android/</a></li> <li>I got this example from here - <a href="http://www.vogella.com/articles/AndroidXML/article.html" rel="nofollow">http://www.vogella.com/articles/AndroidXML/article.html</a></li> <li>Very good, more complete example - <a href="http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/" rel="nofollow">http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload