xml 받아서 다 파싱은 하는데...
데이터 내용이 뜨질 않네요...
하루종일 찾았는데도 못 찾겠네요....뭔가 잘못 된게 있으니까 안되는거 같은데 답답하네요....
<----------------------------------------------------------------------------------Xml2.java 파일------------------------------------------------------>
package com.test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import javax.xml.parsers.ParserConfigurationException;
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.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Xml2 extends ListActivity {
/** Called when the activity is first created. */
private String memoxml;//memo xml
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
makememo();
}
public void makememo(){
//XML을 UTF-8로 받아온다
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("");
HttpResponse response;
try {
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
int l;
byte[] tmp = new byte[2048];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((l = instream.read(tmp)) != -1) {
baos.write(tmp);
}//while
memoxml = new String(baos.toByteArray(), "UTF-8");
}//if
}//try
catch (Exception e) {
}//catch
XmlData xmlData = null;
ArrayList<XmlData> m_xmlData = new ArrayList<XmlData>();
String sTag;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(memoxml));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {} //if
else if(eventType == XmlPullParser.END_DOCUMENT) {}//else if
else if(eventType == XmlPullParser.START_TAG) {
sTag = xpp.getName();
if( sTag.equals("wid") ){
xmlData = new XmlData();
xmlData.wid = xpp.nextText() ;
}//if
if( sTag.equals("wcontent") ){
xmlData.wcontent = xpp.nextText();
}//if
if( sTag.equals("wregdate") ){
xmlData.wregdate = xpp.nextText() ;
}//if
} //else if
else if(eventType == XmlPullParser.END_TAG) {
sTag = xpp.getName();
if( sTag.equals("memo")){
m_xmlData.add(xmlData);
xmlData = null;
}//if
}//else if
else if(eventType == XmlPullParser.TEXT) {
} //else if
eventType = xpp.next();
}//while
}//try
catch (Exception e) {
}//catch
XmlListAdapter adapter = new XmlListAdapter(this,R.layout.row, m_xmlData);
setListAdapter(adapter);
}//makememo
//List의 row를 변형하기 위해 Adapter 오버라이딩
private class XmlListAdapter extends ArrayAdapter {
private ArrayList items;
public XmlListAdapter(Context context, int textViewResourceId, ArrayList items) {
super(context, textViewResourceId, items);
this.items = items;
}//XmlListAdapter
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null){
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(android.R.layout.simple_list_item_1,parent,false);
}
XmlData xmlData = (XmlData) items.get(position);
if(xmlData != null){
TextView wid = (TextView)v.findViewById(R.id.wid);
TextView wcontent = (TextView)v.findViewById(R.id.wcontent);
TextView wregdate = (TextView)v.findViewById(R.id.wregdate);
if(wid != null){
wid.setText(xmlData.wid);
}
if(wcontent != null){
wcontent.setText(xmlData.wcontent);
}
if(wregdate != null){
wregdate.setText(xmlData.wregdate);
}
}
return v;
}
}//XmlListAdapter
public class XmlData {
String wid = "";
String wcontent = "";
String wregdate = "";
}
}
<-------------------------------------------------------------------------row.xml------------------------------------------------------------------------------------>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/wid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="@+id/wcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="@+id/wregdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
<-------------------------------------------------------------------------main.xml------------------------------------------------------------------------------------>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</LinearLayout>
<ListView
android:id = "@+id/android:list"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent">
</ListView>
</LinearLayout>



