DOM XML Error Checker and Locator

Posted: March 24, 2010 in XML
Tags: , ,

If an XML is not well-formed, then it will throw exception which can be caught and made to show the line number and column number of the exception

catch (SAXParseException e) {
System.out.println(“type” + “: ” + e.getMessage()+”\n”);
System.out.println(“Line ” + e.getLineNumber() + ” Column “
+ e.getColumnNumber());
}
catch (SAXException e) {
System.err.println(e);
System.exit(1);
}
catch (ParserConfigurationException e) {
System.err.println(e);
System.exit(1);
}
catch (IOException e) {
System.err.println(e);
System.exit(1);
}
}
}

Download this example.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s