Android code example for reading xml

Y2J
Release: 2017-04-27 13:26:29
Original
1765 people have browsed it

/**
* 从config.xml中获取版本信息以及应用id
*
* @param urlPath
* @return
* @throws Exception
*/
public List<String> getUpdateInfo() {
Resources r = context.getResources();
// 通过Resources,获得XmlResourceParser实例
XmlResourceParser xrp = r.getXml(R.xml.config);
List<String> list = new ArrayList<String>();
// 如果是开始标签
try {
// 如果没有到文件尾继续执行
while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
// 如果是开始标签
if (xrp.getEventType() == XmlResourceParser.START_TAG) {
// 获取标签名称
String name = xrp.getName();
// 判断标签名称是否等于friend
if (name.equals("update")) {
// 获得标签属性追加到StringBuilder中
list.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) {
}
// 下一个标签
xrp.next();
}
 
 
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
Copy after login

The above is the detailed content of Android code example for reading xml. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template