From cf33638637f7f9517a6ad305d32266cd5af977cc Mon Sep 17 00:00:00 2001 From: Maximilian Gruber <maximilian.gruber@ptb.de> Date: Tue, 2 Jul 2024 09:46:15 +0200 Subject: [PATCH] add mathml validation script --- app/validate_mathml_against_schema.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/validate_mathml_against_schema.py diff --git a/app/validate_mathml_against_schema.py b/app/validate_mathml_against_schema.py new file mode 100644 index 0000000..80f97b7 --- /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) -- GitLab