Created
August 26, 2023 15:47
-
-
Save bryaneaton/a2754e418477e6ffd83ab7fdb9a60b00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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