首页 > 代码库 > Xml 解析 PullParser

Xml 解析 PullParser

public static UpdateInfo getUpdateInfos(InputStream is)
{
	try
	{
		XmlPullParser parser = Xml.newPullParser();
		parser.setInput(is, "UTF-8");
		int type = parser.getEventType();
		UpdateInfo info = new UpdateInfo();

		while (type != XmlPullParser.END_DOCUMENT)
		{
			switch (type)
			{
			case XmlPullParser.START_TAG:
				if ("version".equals(parser.getName()))
				{
					String version = parser.nextText();
					info.setVersion(version);
				}
				else if ("description".equals(parser.getName()))
				{
					String description = parser.nextText();
					info.setDescription(description);
				}
				else if ("path".equals(parser.getName()))
				{
					String path = parser.nextText();
					info.setApkurl(path);
				}
				break;
			}
			type = parser.next();
		}
		return info;
	}
	catch (Exception e)
	{
		e.printStackTrace();
		return null;
	}
}