Skip to content

Instantly share code, notes, and snippets.

@bryaneaton
Created August 26, 2023 15:47
Show Gist options
  • Save bryaneaton/a2754e418477e6ffd83ab7fdb9a60b00 to your computer and use it in GitHub Desktop.
Save bryaneaton/a2754e418477e6ffd83ab7fdb9a60b00 to your computer and use it in GitHub Desktop.
import com.helger.schematron.ISchematronResource;
import com.helger.schematron.svrl.SVRLFailedAssertAndReport;
import com.helger.schematron.xslt.SchematronResourceSCH;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.util.List;
public class SchematronValidator {
public static void validate(File xmlFile, File schematronFile) throws Exception {
ISchematronResource aResSCH = SchematronResourceSCH.fromFile(schematronFile);
if (!aResSCH.isValidSchematron())
throw new IllegalArgumentException("Invalid Schematron!");
List<SVRLFailedAssertAndReport> aList = aResSCH.applySchematronValidationToSVRL(new StreamSource(xmlFile));
for (SVRLFailedAssertAndReport aFailedAssert : aList) {
System.out.println("Failed assert: " + aFailedAssert.getAsResourceError().getErrorText());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment