Hi everyone I'm quite new in Android developement,
I want to know if there's any difference between passing the stream to the parser in this way
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL("http://www.xmlfiles.com/examples/cd_catalog.xml"); // URL
XMLHandler myXMLHandler = new XMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
Or in this way
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.xmlfiles.com/examples/cd_catalog.xml");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
XMLHandler myXMLHandler = new XMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(entity.getContent()));
There's any advantage in the second? Which of the two use less memory?
According to this link (http://android-developers.blogspot.com/2011/09/androids-http-clients.html) the Android development team prefers that you use the Java SE http/https options while performing http/https operations instead of using the Apache HttpClient library. The reason for this is that the Apache HttpClient library is feature rich and hence more heavyweight than the java.net packages. But the later releases of Java SE contain http/https features that are still lightweight and efficient.
Apart from this, personally, I believe that the Android developers would prefer to move away from the Apache library because Apache keeps coming out with incremental additions and keeps deprecating features which might prove to be additional overhead to the development team.
To answer your question, the first option would be the way the Android team would prefer you use.