Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Parsing too slow!

I wrote a java app to communicate with a web application using XML. After deployment, I found out it takes too long to parse the XML generated by the web application.

For example, it takes about 2 minutes to login; the login information is included in the url. The web application does its processing and responds to the Java app whether the login was successful using XML returned.

I used the standard java DOM parsing.

Is there a way I can optimize this process so that activities can be faster?

like image 522
yomexzo Avatar asked Jun 01 '11 16:06

yomexzo


2 Answers

I've runned into the same issue and managed to speed up parser by switching off all validation that DocumentBuilder will do by default:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setNamespaceAware(false);
factory.setValidating(false);
factory.setFeature("http://xml.org/sax/features/namespaces", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

// then take a builder via `factory.newDocumentBuilder()` and parse doc with that builder
like image 71
om-nom-nom Avatar answered Oct 16 '22 01:10

om-nom-nom


Using a standard XML parser a short message should be parsed in about one milli-second. Using a custom parser you can cut this to about 20 micro-seconds. Any time longer than this is not in the XML parsing

like image 42
Peter Lawrey Avatar answered Oct 16 '22 01:10

Peter Lawrey