// String... arg0 is the same as String[] args protected String doInBackground(String... args) { try { // Get the XML URL that was passed in URL url = new URL(args[0]); // connection is the communications link between the // application and a URL that we will read from. URLConnection connection; connection = url.openConnection(); // Used to take advantage of HTTP specific features. // Provides tools that tell us if a connection was // made, lost and other HTTP Status Codes HttpURLConnection httpConnection = (HttpURLConnection) connection; // Did we connect properly the the URL? int responseCode = httpConnection.getResponseCode(); // Tests if responseCode == 200 Good Connection if (responseCode == HttpURLConnection.HTTP_OK) { // Reads data from the connection InputStream in = httpConnection.getInputStream(); // Provides a way to parse DOM object trees from XML documents DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Provides a DOM Document from an xml page DocumentBuilder db = dbf.newDocumentBuilder(); // Parse the Yahoo Financial YQL Stock XML File Document dom = db.parse(in); // The root element is query Element docEle = dom.getDocumentElement(); // Get a list of quote nodes NodeList nl = docEle.getElementsByTagName("quote"); // Checks to make sure we found a quote tag if (nl != null && nl.getLength() > 0) { // Cycles through if we find multiple quote tags // Mainly used for demonstration purposes for (int i = 0; i < nl.getLength(); i++) { // Passes the root element of the XML page, so // that the function below can search for the // information needed StockInfo theStock = getStockInformation(docEle); // Gets the values stored in the StockInfo object daysLow = theStock.getDaysLow(); daysHigh = theStock.getDaysHigh(); yearLow = theStock.getYearLow(); yearHigh = theStock.getYearHigh(); name = theStock.getName(); lastTradePriceOnly = theStock.getLastTradePriceOnly(); change = theStock.getChange(); daysRange = theStock.getDaysRange(); // Outputs information for tracking reasons only Log.d(TAG, "Stock Name " + name); Log.d(TAG, "Stock Year High " + yearHigh); Log.d(TAG, "Stock Year Low " + yearLow); Log.d(TAG, "Stock Days High " + daysHigh); Log.d(TAG, "Stock Days Low " + daysLow); } } } } catch (MalformedURLException e) { Log.d(TAG, "MalformedURLException", e); } catch (IOException e) { Log.d(TAG, "IOException", e); } catch (ParserConfigurationException e) { Log.d(TAG, "Parser Configuration Exception", e); } catch (SAXException e) { Log.d(TAG, "SAX Exception", e); } finally { } return null; }