Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - XML Parsing (Multiple Documents) From Web Service Very Slow

XML Parsing (Multiple Documents) From Web Service Very Slow

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

XML Parsing (Multiple Documents) From Web Service Very Slow

Postby SebF » Wed Mar 20, 2013 3:15 pm

I will attempt to supply this in context.

Below is code from my method getVehicles();

3 Web Service calls similar to this one:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. HttpURLConnection v_conn = (HttpURLConnection) new URL("XXXXXX").openConnection();
  2. v_conn.setRequestMethod("POST");                                       
  3. v_conn.setDoInput(true);
  4. v_conn.setDoOutput(true);
  5. v_conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
  6. v_conn.setChunkedStreamingMode(0);
  7. String v = URLEncoder.encode("Token", "UTF-8") + "=" + URLEncoder.encode(gettoken, "UTF-8");
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


This then does the following - writes to an output stream, retrieves an input stream:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. OutputStream v_os = v_conn.getOutputStream();
  2. Writer v_wr = new OutputStreamWriter(v_os);
  3. v_wr.write(v);
  4. v_wr.flush();
  5. v_wr.close();
  6. InputStream v_is = v_conn.getInputStream();
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


It then builds a document from it and gets a node list:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. DocumentBuilderFactory v_dbFactory = DocumentBuilderFactory.newInstance();
  2. DocumentBuilder v_dBuilder = v_dbFactory.newDocumentBuilder();
  3. Document v_doc = v_dBuilder.parse(v_is);
  4. NodeList v_nList = v_doc.getElementsByTagName("UNIT");
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


This happens three times for, let's call them, XML1 (UNIT), XML2 (LOCATION) and XML3 (PERSON).

What then happens is I create a for loop as such (Vehicle is a custom class with simple get/set methods for things like vid, registration etc):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. for (int v_temp = 0; v_temp < v_nList.getLength(); v_temp++) {
  2. Vehicle v = new Vehicle();
  3. Node v_nNode = v_nList.item(v_temp);
  4. Element v_eElement = (Element) v_nNode;
  5. String XML1_vid = (getTagValue("Vid", v_eElement));
  6. ......
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


Within this for loop I also have TWO other for loops, in the same style but there are if statements within the loops stating that:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if (XML2_vid.equals(XML1_vid)){
  2. assign some values to Vehicle v....
  3. BREAK XML2 FOR LOOP
  4. }
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if (XML3_vid.equals(XML1_vid)){
  2. assign some more values to Vehicle v....
  3. BREAK XML3 FOR LOOP
  4. }
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


When these two for & if loops break, it cycles to the bottom of the first for loop that iterates through XML1 and adds a new case of Vehicle into an array.

This process starts over again from the start of the for loop until all cases of Vehicle v within XML1 have been found along with their associating values within XML2 and XML3.

The problem I have is that, even for a list of only 20 in XML1, it takes almost 25 seconds to run through this entire method.

The XML layout is as follows:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ArrayOfUNIT xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="XXXXX">
  2. <UNIT>
  3. <Vid>1</Vid>
  4. <Reg>vehicle registration</Reg>
  5. <Make>VW</Make>
  6. <Model>Golf</Model>
  7. </UNIT>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Can anyone shed any light on this? I've tried using the setFeature() on the document/builder but it didn't help.

Realistically all of this needs to be happening in around 2 seconds, no more, otherwise the exercise is fruitless.

Am I using a slow method of parsing XML? Is this DOM not efficent?

I am new to java/android and coding in general so I'm not really sure what to do. I read the SAX parsing tutorial on here but I can't get my head around it, I don't know how to adapt it to fit what I need it to do.

Thanks in advance.
SebF
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Mar 20, 2013 10:37 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 6 guests