Alex Rivera | Logout

XML Parsing too slow!

Asked 2011-06-01T16:51:43.513
9

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?

Edit
Report

1 Answer

33

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
answered 2012-07-24T20:17:11.643

Your Answer