protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
package com.bill99.kuaiqian;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import android.util.Xml;
public class UpdateInfoParser implements MessageParse{
private Boolean statrtappInfo=false;
@Override
public Listparse(InputStream inStream) throws Exception {
Listupdateinfolist=null;
msgContent updateinfo=null;
XmlPullParser xmlPullParser= Xml.newPullParser();
xmlPullParser.setInput(inStream,"UTF-8");
int type=xmlPullParser.getEventType();
while(type!=XmlPullParser.END_DOCUMENT){
switch (type) {
case XmlPullParser.START_DOCUMENT:
{
updateinfolist =new ArrayList();
}
break;
case XmlPullParser.START_TAG:
String tag=xmlPullParser.getName();
if(tag.equalsIgnoreCase("appInfo")){
updateinfo=new msgContent();
type=xmlPullParser.next();
statrtappInfo=true;
}
if(tag.equalsIgnoreCase("latesAppVersion")){
updateinfo.setLatestAppVersion(xmlPullParser.getText());
type=xmlPullParser.next();
}else if(tag.equalsIgnoreCase("appVersion")){
updateinfo.setAppVersion(xmlPullParser.getText());
type=xmlPullParser.next();
}if(tag.equalsIgnoreCase("responseCode")){
updateinfo.setResponseCode(xmlPullParser.getText());
type=xmlPullParser.next();
}if(tag.equalsIgnoreCase("appFlag")){
updateinfo.setAppFlag(xmlPullParser.getText());
type=xmlPullParser.next();
}if(tag.equalsIgnoreCase("appType")){
updateinfo.setAppType(xmlPullParser.getText());
type=xmlPullParser.next();
}if(tag.equalsIgnoreCase("latestAppVersionUrl")){
updateinfo.setLatestAppVersionUrl(xmlPullParser.getText());
type=xmlPullParser.next();
}
break;
case XmlPullParser.END_TAG:
if(xmlPullParser.getName().equals("appInfo")){
updateinfolist.add(updateinfo);
updateinfo=null;
}
}
type=xmlPullParser.next();
}
return updateinfolist;
}
}
public void xml() throws XmlPullParserException, IOException{成功拿到数据
String str = "";
XmlPullParser xmlPullParser= Xml.newPullParser();
xmlPullParser.setInput(getResources().openRawResource(R.raw.file),"UTF-8");
int type=xmlPullParser.getEventType();
while(type!=XmlPullParser.END_DOCUMENT){
switch (type) {
case XmlPullParser.START_DOCUMENT:
{
// updateinfolist =new ArrayList();
}
break;
case XmlPullParser.START_TAG:
String tag=xmlPullParser.getName();
// if(tag.equalsIgnoreCase("appInfo")){
// updateinfo=new msgContent();
// statrtappInfo=true;
// }
if(tag.equalsIgnoreCase("latesAppVersion")){
// updateinfo.setLatestAppVersion(xmlPullParser.getText());
str +="=====" + xmlPullParser.nextText()+";" ;
}else if(tag.equalsIgnoreCase("appVersion")){
// updateinfo.setAppVersion(xmlPullParser.getText());
str +="=====" + xmlPullParser.nextText()+";" ;
}if(tag.equalsIgnoreCase("responseCode")){
// updateinfo.setResponseCode(xmlPullParser.getText());
str +="=====" + xmlPullParser.nextText()+";" ;
}if(tag.equalsIgnoreCase("appFlag")){
// updateinfo.setAppFlag(xmlPullParser.getText());
str +="=====" + xmlPullParser.nextText()+";" ;
}if(tag.equalsIgnoreCase("appType")){
// updateinfo.setAppType(xmlPullParser.getText());
str +="=====" + xmlPullParser.nextText()+";" ;
}if(tag.equalsIgnoreCase("latestAppVersionUrl")){
// updateinfo.setLatestAppVersionUrl(xmlPullParser.getText());
str +="=====" + xmlPullParser.nextText()+";" ;
}
break;
case XmlPullParser.END_TAG:
if(xmlPullParser.getName().equals("appInfo")){
// updateinfolist.add(updateinfo);
// updateinfo=null;
}
}
type=xmlPullParser.next();
}
System.out.print(str);
}
public Listparse(String result){}
public void xml(int id) throws XmlPullParserException, IOException{就这样吧他需要的参数传递进去就ok
String str = "";
XmlPullParser xmlPullParser= Xml.newPullParser();
xmlPullParser.setInput(getResources().openRawResource(id),"UTF-8");
public class msgContent {
private String appVersion;
private String latestAppVersion;
private String latestAppVersionUrl;
private String appType;
private String appFlag;
private String responseCode;
public msgContent() {
}
public msgContent(String appVersion,String latestAppVersion, String latestAppVersionUrl,
String appType,String appFlag,String responseCode){
this.appFlag=appFlag;
this.appType=appType;
this.appVersion=appVersion;
this.latestAppVersion=latestAppVersion;
this.latestAppVersiOnUrl=latestAppVersionUrl;
this.respOnseCode=responseCode;
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion;
}
public String getLatestAppVersion() {
return latestAppVersion;
}
public void setLatestAppVersion(String latestAppVersion) {
this.latestAppVersion = latestAppVersion;
}
public String getLatestAppVersionUrl() {
return latestAppVersionUrl;
}
public void setLatestAppVersionUrl(String latestAppVersionUrl) {
this.latestAppVersionUrl = latestAppVersionUrl;
}
public String getAppType() {
return appType;
}
public void setAppType(String appType) {
this.appType = appType;
}
public String getAppFlag() {
return appFlag;
}
public void setAppFlag(String appFlag) {
this.appFlag = appFlag;
}
}
public class UpdateInfoParser extends Activity implements MessageParse { @Override
public Listparse(InputStream inStream) throws Exception {
Listupdateinfolist=null;
msgContent updateinfo=null;
XmlPullParser xmlPullParser= Xml.newPullParser();
xmlPullParser.setInput(inStream,"UTF-8");
int type=xmlPullParser.getEventType();
while(type!=XmlPullParser.END_DOCUMENT){
switch (type) {
case XmlPullParser.START_DOCUMENT:
{
updateinfolist =new ArrayList();
}
break;
case XmlPullParser.START_TAG:
String tag=xmlPullParser.getName();
updateinfo=new msgContent();
if(tag.equalsIgnoreCase("latesAppVersion")){
updateinfo.setAppType(xmlPullParser.nextText());
}else if(tag.equalsIgnoreCase("appVersion")){
updateinfo.setAppVersion(xmlPullParser.nextText());
}if(tag.equalsIgnoreCase("responseCode")){
updateinfo.setResponseCode(xmlPullParser.nextText());
}if(tag.equalsIgnoreCase("appFlag")){
updateinfo.setAppFlag(xmlPullParser.nextText());
}if(tag.equalsIgnoreCase("appType")){
updateinfo.setAppType(xmlPullParser.nextText());
}if(tag.equalsIgnoreCase("latestAppVersionUrl")){
updateinfo.setLatestAppVersionUrl(xmlPullParser.nextText());
}
break;
case XmlPullParser.END_TAG:
if(xmlPullParser.getName().equalsIgnoreCase("appInfo")){
updateinfolist.add(updateinfo);
updateinfo=null;
}
}
type=xmlPullParser.next();
}
return updateinfolist;
}
}
UpdateInfoParser updateInfoParser=new UpdateInfoParser();
Listb=updateInfoParser.parse(input);