Hello,

I am trying to get xml data from the web and already added the
internet user permission but I cannot get my sax parser to work:

package com.kaddoz.android.igift;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.List;

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 com.kaddoz.android.igift.tos.ItemTO;
import com.kaddoz.android.igift.util.KaddozAndroidUtil;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class giftFinder extends Activity {
    /** Called when the activity is first created.
     * @throws IOException */
    @Override
    public void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        KaddozAndroidUtil util = new KaddozAndroidUtil();
        List<ItemTO> items=util.getItemIdsFromUrl("http://
www.kaddoz.com/ws/rest/items/xml/recommendationQ?num=1");

        StringBuffer sb = new StringBuffer();

        for(Iterator<ItemTO> it = items.iterator() ; it.hasNext();){
                sb.append("Name: "+it.next().getName());
        }


                TextView tv = new TextView(this);
            tv.setText(sb.toString());
            setContentView(tv);

    }
}


public class KaddozAndroidUtil {



        public List<ItemTO> getItemIdsFromUrl(String strURL){
                ItemsTOHandler itemsTOHandler = new ItemsTOHandler();
                try {
                        URL url = new URL(strURL);
                /* Get a SAXParser from the SAXPArserFactory. */
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp;
                        sp = spf.newSAXParser();

                /* Get the XMLReader of the SAXParser we created. */
                XMLReader xr = sp.getXMLReader();
                /* Create a new ContentHandler and apply it to the XML-
Reader*/

                xr.setContentHandler(itemsTOHandler);
                /* Parse the xml-data from our URL. */
                        xr.parse(new InputSource(url.openStream()));

                } catch (IOException e) {
                        Log.e(KaddozAndroidUtil.class.getName(),e.toString());
                } catch (SAXException e) {
                        Log.e(KaddozAndroidUtil.class.getName(),e.toString());
                }catch (ParserConfigurationException e) {
                        Log.e(KaddozAndroidUtil.class.getName(),e.toString());
                }
        /* Parsing has finished. */

        return itemsTOHandler.getItemsTO();

        }


}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to