6.1. JAVA programming
In Java, you must first compile the source files with Xdefinitions. The first parameter of the method
is the Properties for compilation (this parameter can be null or an empty Properties object - then
the compilation defaults are used). The result of the compilation is an XDPool object:
File xdef1, xdef2; // files with Xdefinition source code
Properties props = new Properties();
props.setProperty(XDConstants.XDPROPERTY_WARNINGS, "true"); // set compiler to report both warnings and errors
XDPool xpool = XDFactory.compileXD(props, xdef1, xdef2); // compile Xdefinitions and create XDPool object
From the XDPool object it is possible to create the XDDocument object,
in which the Xdefinition name is entered, which contains the data model to be worked with:
XDDocument xdoc = xpool.createXDDocument("d1"); //create XDDocument from the Xdefinition with the name "d1"
Before work, it is advisable to prepare a reporter in which information
about the process will be recorded. Then it is possible to start the
validation or construction mode of processing:
ArrayReporter reporter = new ArrayReporter(); // create empty reporter
xdoc.xparse(data, reporter); // run validate mode with data source (or you can run xcreate - construction mode)
)
// errors in reporter?
if (reporter.errors()) {
reporter.printReports(System.err); // print reported messages
} else { // no error has been reported
...
}