Android的HTTP通信 XML解析和异步消息处理
2010-02-03 19:10:00 来源:WEB开发网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;
更多精彩
赞助商链接