Parsing a Document with JDOM
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import java.io.IOException;
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 no exception is thrown, then there are
// no well-formedness errors.
System.out.println(args[i] + " is well-formed.");
}
// indicates a well-formedness error
catch (JDOMException e) {
System.out.println(args[i] + " is not well-formed.");
System.out.println(e.getMessage());
}
catch (IOException e) {
System.out.println("Could not check " + args[i]);
System.out.println("because " + e.getMessage());
}
}
}
}