which xml validator will work perfectly for multithreading project
Posted
by Sunil Kumar Sahoo
on Stack Overflow
See other posts from Stack Overflow
or by Sunil Kumar Sahoo
Published on 2010-04-19T07:20:00Z
Indexed on
2010/04/19
7:23 UTC
Read the original article
Hit count: 504
Hi All, I have used jdom for xml validation against schema. The main problem there is that it gives an error
FWK005 parse may not be called while parsing
The main reason was that multiple of threads working for xerces validation at the same time. SO I got the solution that i have to lock that validation. which is not good
So I want to know which xml validator works perfectly for multithreading project
public static HashMap validate(String xmlString, Validator validator) {
HashMap<String, String> map = new HashMap<String, String>();
long t1 = System.currentTimeMillis();
DocumentBuilder builder = null;
try {
//obtain lock to proceed
// lock.lock();
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
// Source source = new DOMSource(builder.parse(new ByteArrayInputStream(xmlString.getBytes())));
validator.validate(new StreamSource(new StringReader(xmlString)));
map.put("ISVALID", "TRUE");
logger.info("We have successfuly validated the schema");
} catch (Exception ioe) {
ioe.printStackTrace();
logger.error("NOT2 VALID STRING IS :" + xmlString);
map.put("MSG", ioe.getMessage());
// logger.error("IOException while validating the input XML", ioe);
}
logger.info(map);
long t2 = System.currentTimeMillis();
logger.info("XML VALIDATION TOOK:::" + (t2 - t1));
} catch (Exception e) {
logger.error(e);
} finally {
//release lock
// lock.unlock(); builder = null; }
return map;
}
Thanks Sunil Kumar Sahoo
© Stack Overflow or respective owner