Code snippets, code sharing, PHP code sharing, Java code sharing, Ruby code sharing, Python code sharing, HTML code sharing, CSS code sharing, SQL code sharing, and JavaScript code sharing
/*** Get version information and application id from config. xml *** @ param urlPath * @ return * @ throws Exception */public List
GetUpdateInfo () {Resources r = context. getResources (); // use Resources to obtain the XmlResourceParser instance XmlResourceParser xrp = r. getXml (R. xml. config); List
List = new ArrayList
(); // If it is the start tag try {// if it is not at the end of the file, continue executing while (xrp. getEventType ()! = XmlResourceParser. END_DOCUMENT) {// if it is the start tag if (xrp. getEventType () = XmlResourceParser. START_TAG) {// Obtain the tag name String name = xrp. getName (); // Determine whether the tag name is friendif (name. equals ("update") {// Obtain the tag attribute and append it to the list in StringBuilder. add (xrp. getAttributeValue (0); list. add (xrp. getAttributeValue (1); list. add (xrp. getAttributeValue (2);} else if (xrp. getEventType () = XmlPullParser. END_TAG) {} else if (xrp. getEventType () = XmlPullParser. TEXT) {}// the next tag xrp. next () ;}} catch (XmlPullParserException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} return list ;}
The above is the detailed content of the code instance for android to read xml. For more information, see other related articles in the first PHP community!