Android 클 라 이언 트 가 서버 에서 되 돌아 오 는 xml 파일 내용 을 분석 합 니 다.

1. 서버 쪽 xml 파일 을 먼저 받 습 니 다.
String path = "http://10.0.2.2:9999/XMLServer/video.xml";
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setReadTimeout(8 * 1000);
conn.setRequestMethod("GET");
InputStream is = conn.getInputStream();
byte[] data = StreamTools.readInput(is);

   StreamTools 코드:
public class StreamTools {

	public static byte[] readInput(InputStream is) throws Exception {
		byte[] buffer = new byte[is.available()];
		int len = 0;
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		while((len = is.read(buffer)) != -1) {
			bos.write(buffer,0,len);
		}
		bos.close();
		return bos.toByteArray();
	}
}

 
2. 얻 은 xml 파일 을 분석 합 니 다.
/**
	 *          xml  
	 * @param content
	 * @return
	 * @throws Exception
	 */
	private static List

 MyContentHandler 코드:
public class MyContentHandler extends DefaultHandler {

	private List

 3. 최종 적 으로 분 석 된 VO 의 List 목록 은 activity 에서 ListView 로 표 시 됩 니 다.
ListView Activity 코드:
public class ListViewActivity extends Activity {

	private ListView list;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listtext);
		list = (ListView)this.findViewById(R.id.list);
		try {
			List

좋은 웹페이지 즐겨찾기