Android w3c DOM Parsing very slow

unknowndreamer

New Member
I'm having some real issues with the parsing within my android app. I'm pulling down a few XML files with a DOM style parser and it's taking almost 20 seconds to do it and run some code on them, the files are no larger than 30KB.This is some code taken from the method:Code is below:\[code\]HttpURLConnection vehicles_conn = (HttpURLConnection) new URL("XXXXXXX").openConnection(); vehicles_conn.setRequestMethod("POST"); vehicles_conn.setDoInput(true); vehicles_conn.setDoOutput(true); vehicles_conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); vehicles_conn.setChunkedStreamingMode(0); String vehicles = URLEncoder.encode("LogonToken", "UTF-8") + "=" + URLEncoder.encode(gettoken, "UTF-8"); OutputStream vehicles_os = vehicles_conn.getOutputStream(); Writer vehicles_wr = new OutputStreamWriter(vehicles_os); vehicles_wr.write(vehicles); vehicles_wr.flush(); InputStream vehicles_is = vehicles_conn.getInputStream(); vehicles_wr.close(); DocumentBuilderFactory vehicles_dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder vehicles_dBuilder = vehicles_dbFactory.newDocumentBuilder(); Document vehicles_doc = vehicles_dBuilder.parse(vehicles_is); NodeList vehicles_nList = vehicles_doc.getElementsByTagName("UNIT");for (int temp = 0; temp < vehicles_nList.getLength(); temp++) { //Create a new vehicle object Vehicle v = new Vehicle(); Node vehicles_nNode = vehicles_nList.item(vehicles_temp); if (vehicles_nNode.getNodeType() == Node.ELEMENT_NODE) { Element vehicles_eElement = (Element) vehicles_nNode; String something = (getTagValue("ID", vehicles_eElement));.........\[/code\]Now, I have 3 of these (the http connections are only called ONCE however, within the method), it runs through 26 'Units' in the first XML file - let's call it XML1, then iterates through a second, XML2 with 25 'Places', until the ID field matches with XML1, then grabs a few other fields of XML2 and stores them away into an arraylist, then does the same for XML3 with 'Peopel'. Once finished, it goes back to the top and starts again with the next ID in the list.Now, my problem is that this process needs to be taking less than a few seconds ideally, it's taking 20! For the record this is over Wifi through a 20Mbit on an LG Nexus 4. Can be replicated through a Motoral Defy and Galaxy Ace 2. Does anyone know why it is so slow?I'm new to Java/Android so I don't know if perhaps I've coded something wrong, or that the XML parsing is just slow?
 
Back
Top