XParsepublic class XParse extends Object Parse an XML file using DOM, via JAXP. |
Methods Summary |
---|
public static void | main(java.lang.String[] av)
if (av.length == 0) {
System.err.println("Usage: XParse file");
return;
}
boolean validate = false;
for (int i=0; i<av.length; i++) {
if (av[i].equals("-validate"))
validate = true;
else
parse(av[i], validate);
}
| public static void | parse(java.lang.String fileName, boolean validate)Convert the file
try {
System.err.println("Parsing " + fileName + "...");
// Make the document a URL so relative DTD works.
String uri = "file:" + new File(fileName).getAbsolutePath();
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
if (validate)
f.setValidating(true);
DocumentBuilder p = f.newDocumentBuilder();
Document doc = p.parse(uri);
System.out.println("Parsed OK");
} catch (SAXException ex) {
System.err.println("+================================+");
System.err.println("| *Parse Error* |");
System.err.println("+================================+");
System.err.println(ex.getClass());
System.err.println(ex.getMessage());
System.err.println("+================================+");
} catch (Exception ex) {
System.err.println("+================================+");
System.err.println("| *XML Error* |");
System.err.println("+================================+");
System.err.println(ex.toString());
}
|
|