Parsing a Document with JDOM
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class JDOMChecker {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage: java JDOMChecker URL1 URL2...");
}
SAXBuilder builder = new SAXBuilder();
// start parsing...
for (int i = 0; i < args.length; i++) {
// command line should offer URIs or file names
try {
builder.build(args[i]);
// If there are no well-formedness errors,
// then no exception is thrown
System.out.println(args[i] + " is well-formed.");
}
// indicates a well-formedness or other error
catch (JDOMException e) {
System.out.println(args[i] + " is not well-formed.");
System.out.println(e.getMessage());
}
}
}
}