-1

I am developing android application and I got a error When I parse XML data like Json.I confused how many array has this data? I share code at below. can anyone help me or sharing example code like this xml data? I added photo of parsing data

public class MainActivity extends Activity implements OnRefreshListener,
        OnClickListener {
    // Declare Variables
    JSONObject jsonobject;
    JSONArray jsonarray;
    JSONArray jsonarray2;
    ListView listview;
    ListViewAdapter adapter;
    ProgressDialog mProgressDialog;
    ArrayList<HashMap<String, String>> arraylist;
    static String RANK = "rank";
    static String COUNTRY = "country";
    static String POPULATION = "population";
    static String FLAG = "flag";

    Button btngeri;

    static Integer[] imageId = { R.drawable.enveloppe, R.drawable.enveloppe,
            R.drawable.enveloppe, R.drawable.enveloppe, R.drawable.enveloppe,
            R.drawable.enveloppe, R.drawable.enveloppe };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from listview_main.xml
        setContentView(R.layout.listview_main);

        btngeri = (Button) findViewById(R.id.btn_geri);
        btngeri.setOnClickListener(this);


        // Execute DownloadJSON AsyncTask
        new DownloadJSON().execute();
    }

    // DownloadJSON AsyncTask
    private class DownloadJSON extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a progressdialog
            mProgressDialog = new ProgressDialog(MainActivity.this);
            // Set progressdialog title
            mProgressDialog.setTitle("Mail Kutusu");
            // Set progressdialog message
            mProgressDialog.setMessage("Güncelleme Yapılıyor...");
            mProgressDialog.setIndeterminate(false);
            // Show progressdialog
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // Create an array
            arraylist = new ArrayList<HashMap<String, String>>();
            // Retrieve JSON Objects from the given URL address
            jsonobject = JSONfunctions
                    .getJSONfromURL("http://78.186.62.169:8210/AnketServis.asmx/Message");

            try {
                // Locate the array name in JSON

                jsonarray = jsonobject.getJSONArray("MessageVO");

                for (int i = 0; i < jsonarray.length(); i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    jsonobject = jsonarray.getJSONObject(i);
                    // Retrive JSON Objects
                    // map.put("rank", jsonobject.getString("rank"));
                    map.put("country", jsonobject.getString("Konu"));
                    // map.put("population",
                    // jsonobject.getString("population"));
                    // map.put("flag", jsonobject.getString("flag"));
                    // Set the JSON Objects into the array
                    arraylist.add(map);
                }
            } catch (JSONException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void args) {
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listview);
            // Pass the results into ListViewAdapter.java
            adapter = new ListViewAdapter(MainActivity.this, arraylist, imageId);
            // Set the adapter to the ListView
            listview.setAdapter(adapter);
            // Close the progressdialog
            mProgressDialog.dismiss();
        }
    }
Diego
  • 937
  • 8
  • 24

1 Answers1

0

Yo cannot parse xml file like json. You have to use xml parser. There are two parse method. SAX and Dom. Yo can see the versus about them. What is the difference between SAX and DOM? And You can see the an xml parser sample in android.

http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/

Community
  • 1
  • 1
Cüneyt
  • 2,565
  • 25
  • 31