Document Example
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class XMLPrinter {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage: java XMLPrinter 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 {
Document doc = builder.build(args[i]);
System.out.println("*************" + args[i] + "*************");
String serializedDocument = doc.getSerializedForm();
System.out.println(serializedDocument);
}
catch (JDOMException e) { // indicates a well-formedness or other error
System.out.println(args[i] + " is not well formed.");
System.out.println(e.getMessage());
}
}
}
}