http解析XML

URL httpUrl=new URL("**");
HttpURLConnection coon=(HttpURLConnection)httpUrl.openConnection();
coon.setReadTimeout(5000);
coon.setRequestMethod("GET");
InputStream in=coon.getInputStream();
XmlPullParserFactory factory=XmlPullParserFactory.newInstance();
XmlPullParser parser=factory.newPullParser();
parser.setInput(in,"UTF-8");
int eventType=parser.getEventType();
//E是自己根据需求定义的entity帮助解析
List<E> list=new ArrayList<E>();
E e=null;

while(eventType!=XmlPullParser.END_DOCUMENT){
    String data=parser.getName();
    switch(eventType){
    case XmlPullParser.START.TAG:{
    //此处是标签名
    if("".equals(data)){
        e=new E();
    }
    if("子标签".equals(data)){
        //TODO   e.set (parser.nextText());
        // e.set(Integer.parserInt(parser.nextText())) ;
    }
    break;
    }
    case XmlPullParser.END.TAG:{
        if("实体类".equals(data)&实体类!=null){
        list.add("实体类")
        }
        break;
    }
    }
        //每调用一个继续向下
        eventType=parser.next();
    }

你可能感兴趣的:(android,基础,xml,http)