public XdmNode build(Source source) throws SaxonApiException {
if (source instanceof AugmentedSource) {
throw new IllegalArgumentException("AugmentedSource not accepted");
}
ParseOptions options = new ParseOptions();
options.setDTDValidationMode(dtdValidation ? Validation.STRICT : Validation.STRIP);
if (schemaValidator != null) {
options.setSchemaValidationMode(schemaValidator.isLax() ? Validation.LAX : Validation.STRICT);
if (schemaValidator.getDocumentElementName() != null) {
options.setTopLevelElement(schemaValidator.getDocumentElementName().getStructuredQName());
}
if (schemaValidator.getDocumentElementType() != null) {
options.setTopLevelType(schemaValidator.getDocumentElementType());
}
}
if (treeModel != null) {
options.setModel(treeModel);
}
if (whitespacePolicy != null) {
options.setStripSpace(whitespacePolicy.ordinal());
}
options.setLineNumbering(lineNumbering);
if (source.getSystemId() == null && baseURI != null) {
source.setSystemId(baseURI.toString());
}
try {
NodeInfo doc = config.buildDocument(source, options);