title: How to parse xml for HTTPS url using SAXParser in Android
body: <pre><code>URL url = new URL("https://www.setindia.com"); 
  URLConnection urlConnectionObject = url.openConnection();
  xmlHandlerObject = new XMLHandler(); 
  xmlReaderObject.setContentHandler(xmlHandlerObject); 
  xmlReaderObject.parse(new InputSource(urlConnectionObject.getInputStream())); 
  </code></pre>
  
  <p>// error on the last line please get me an explanation (new to android) and is this right </p>
  
  <p><strong>MAIN ACTIVITY:</strong></p>
  
  <pre><code>    package com.example.testparser;
  
      import java.net.URL;
      import java.net.URLConnection;
      import java.security.KeyStore;
  
      import javax.net.ssl.HttpsURLConnection;
      import javax.net.ssl.KeyManagerFactory;
      import javax.xml.parsers.SAXParser;
      import javax.xml.parsers.SAXParserFactory;
  
      import org.xml.sax.InputSource;
      import org.xml.sax.XMLReader;
  
      import android.app.Activity;
      import android.os.Bundle;
      import android.util.Log;
      import android.view.Menu;
  
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
      public static String TAG = "MYParser";
  
      GettersSetters getData;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          Log.d(TAG, "OnCreate");
  
          View layout = findViewById(R.id.layout);
  
          TextView tittle[];
          TextView country[];
          XMLHandler xmlHandlerObject = null;
  
          try{
              Log.d(TAG, "try");
              SAXParserFactory saxParserFactoryObject = SAXParserFactory.newInstance();   //obtain and configure a SAX based parser
              SAXParser saxParserObject = saxParserFactoryObject.newSAXParser(); //obtaining object for SAX parser
              XMLReader xmlReaderObject = saxParserObject.getXMLReader();
  
  
              URL url = new URL("https://www.setindia.com/setindia_api/episode/1?date=22-10-2013&amp;hd=1");
              URLConnection urlConnectionObject = url.openConnection();
  
  
              xmlHandlerObject = new XMLHandler();
              xmlReaderObject.setContentHandler(xmlHandlerObject);
  
              Log.d(TAG, "about to get an error");
  
              xmlReaderObject.parse(new InputSource(urlConnectionObject.getInputStream()));
              Log.d(TAG, "try end");  
      }
           catch (Exception e) {
                 Log.e(TAG, e.getMessage());
          }
          Log.d(TAG, "OnCreate fetching the data from the xml");
          getData = xmlHandlerObject.getXMLData();
  
          tittle = new TextView[getData.getTittle().size()];
          country = new TextView[getData.getCountry().size()];
  
          for (int i = 0; i &lt; getData.getTittle().size(); i++) {
  
              tittle[i] = new TextView(this);
              tittle[i].setText("ITEM is : " + getData.getTittle().get(i));
  
              country[i] = new TextView(this);
              country[i].setText("Country is :" + getData.getTittle().get(i));
  
              ((ViewGroup) layout).addView(tittle[i]);
              ((ViewGroup) layout).addView(country[i]);
               setContentView(R.layout.main);
          }
  
      }
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p><strong>GettersSetters :</strong></p>
  
  <pre><code>package com.example.testparser;
  
  import java.lang.reflect.Array;
  import java.util.ArrayList;
  
  import android.util.Log;
  
  public class GettersSetters {
      private ArrayList&lt;String&gt; tittle = new ArrayList&lt;String&gt;();
      private ArrayList&lt;String&gt; country = new ArrayList&lt;String&gt;();
  
      public ArrayList&lt;String&gt; getCountry(){
          return country;
      }
      public ArrayList&lt;String&gt; getTittle(){
  
          return tittle;
      }
      public void setCountry(String country){
          this.country.add(country);
          Log.i("This is the country : ",country);
  
      }
       public void setTittle(String tittle){
  
           this.tittle.add(tittle);
           Log.i("This is the tittle : ",tittle);
       }
  
  }
  </code></pre>
  
  <p><strong>XMLHandler:</strong></p>
  
  <pre><code>package com.example.testparser;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.DefaultHandler;
  
  import android.util.Log;
  
  
  public class XMLHandler extends DefaultHandler {
  
      public static String TAG = "MYParser";
      public static GettersSetters data = null;
      String elementValue = null ;
      Boolean elementOn = false;
  
      public GettersSetters getXMLData(){
          Log.e(TAG, "getXMLdata -&gt; "+data.toString());
          return data;
      }
      public void setXMLData(GettersSetters data){
  
          XMLHandler.data = data;
          Log.e(TAG, "setXmldata");
      }
  
      @Override
      public void startElement(String uri, String localName, String qName,
              Attributes attributes) throws SAXException {
  
          super.startElement(uri, localName, qName, attributes);
          elementOn = true;
          Log.d(TAG, "Checking the first element"+localName.equalsIgnoreCase("item"));
          if(localName.equalsIgnoreCase("item"))
          {
              Log.d(TAG, "Creating a new getter setter instance");
              data = new GettersSetters();            
          }
      }
      @Override
      public void characters(char[] ch, int start, int length)
              throws SAXException {
          super.characters(ch, start, length);
          if(elementOn)
          {
              elementValue = new String(ch,start,length);
              elementOn =false;
          }
      }
      @Override
      public void endElement(String uri, String localName, String qName)
              throws SAXException {
          elementOn = false;
          super.endElement(uri, localName, qName);
          if(localName.equalsIgnoreCase("country"))
              data.setCountry(elementValue);
          if(localName.equalsIgnoreCase("tittle"))
              data.setTittle(elementValue);
      }
  }
  </code></pre>
  
  <p><strong>MAIN.Xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
      &lt;TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="SAGAR HERE"
          android:textSize="20dp"
          android:gravity="center_horizontal"
          android:id="@+id/layout"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>