diff --git a/app/validate_mathml_against_schema.py b/app/validate_mathml_against_schema.py new file mode 100644 index 0000000000000000000000000000000000000000..80f97b76f42d49062e551bb8874790f21950ae0c --- /dev/null +++ b/app/validate_mathml_against_schema.py @@ -0,0 +1,26 @@ +import os + +import lxml.etree as et + + +#mathml_object_path = os.path.abspath("mathml_test.xml") +mathml_object_path = os.path.abspath("iir_filter.xml") +mathml_schema_path = os.path.abspath("app/report/mathml3/mathml3.rng") + +print(f"Expression: {mathml_object_path}") +print(f"Schema : {mathml_schema_path}") + + +try: + schema = et.RelaxNG(et.parse(mathml_schema_path)) + expression = et.parse(mathml_object_path) +except et.XMLSyntaxError as e: + print("Provided schema or expression not valid XML. Please check.") + print(f"Error log: {e}") +else: + validation_result = schema.validate(expression) + + print(f"Expression {'' if validation_result else '_not_ '}valid according to RelaxNG schema.") + if not validation_result: + print("Error log:") + print(schema.error_log)