WEB开发网
开发学院手机开发Android 开发 Android的HTTP通信 XML解析和异步消息处理 阅读

Android的HTTP通信 XML解析和异步消息处理

 2010-02-03 19:10:00 来源:WEB开发网   
核心提示:mResult += "name:" + attributes.getValue("name");}// 一发现元素结束标记就回调此函数@Overridepublic void endElement(String uri, String localName, String qNa

mResult += " name:" + attributes.getValue("name");

}

// 一发现元素结束标记就回调此函数

@Override

public void endElement(String uri, String localName, String qName)

throws SAXException {

if (localName == "title")

mIsTitleTag = false;

else if (localName == "salary")

mIsSalaryTag = false;

else if (localName == "dateOfBirth")

mIsBirthTag = false;

}

// 一发现元素值或属性值就回调此函数

@Override

public void characters(char[] ch, int start, int length)

throws SAXException {

if (mIsTitleTag)

mResult += new String(ch, start, length);

else if (mIsSalaryTag)

mResult += " salary:" + new String(ch, start, length);

else if (mIsBirthTag)

mResult += " dateOfBirth:" + new String(ch, start, length);

}

public String getResult(){

return mResult;

}

}

Main.java

代码

package com.webabcd.communication;

import java.io.BufferedInputStream;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.net.URLConnection;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Map;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;

import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;

import org.apache.http.client.entity.UrlEncodedFormEntity;

上一页  1 2 3 4 5 6 7  下一页

Tags:Android HTTP 通信

编辑录入:coldstar [复制链接] [打 印]
赞助商链接