package cinfine;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
/**
*
Conduct
reads an XML conduct file and
* builds a JDOM Document
using a SAX 2.0
* parser.
*
*
* @author Srinivas Nagulapalli
* @version 1.0
*/
public class Conduct {
/**
*
* This provides a static entry point for creating a JDOM
* {@link Document}
object using a SAX 2.0
* parser (an XMLReader
implementation).
*
*
* @param args String[]
*
* - First argument: filename of XML document to parse
* - Second argument: optional name of SAX Driver class
*
*/
public static void main(String[] args) {
if ((args.length != 1) && (args.length != 2)) {
System.out.println(
"Usage: java cinfine.Conduct " +
"[XML document filename] ([SAX Driver Class])");
return;
}
// Load filename and SAX driver class
String filename = args[0];
String saxDriverClass = null;
if (args.length == 2) {
saxDriverClass = args[1];
}
// Request document building with validation
try {
SAXBuilder builder = null;
if (saxDriverClass == null) {
builder = new SAXBuilder(true); //with validation- this line does NOT work!
//builder = new SAXBuilder(); //without validation - this line works fine!
} else {
builder = new SAXBuilder(saxDriverClass);
}
Document doc = builder.build(filename);
// Create an outputter
XMLOutputter outputter = new XMLOutputter();
//outputter.setTrimText(true);
//outputter.setExpandEmptyElements(true);
outputter.output(doc, System.out);
} catch (JDOMException e) {
if (e.getCause() != null) {
e.getCause().printStackTrace();
} else {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}