forked from elifesciences/schematron-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.py
39 lines (31 loc) · 1.01 KB
/
validate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import lxml
from lxml import isoschematron
from lxml import etree
def runschematron(rulesFile, xmlFile):
try:
schematron = isoschematron.Schematron(file=rulesFile, store_report = True)
nodes = open(xmlFile, 'r') # XML to be checked
doc = etree.parse(nodes)
validationResult = schematron.validate(doc)
report = schematron.validation_report
if validationResult:
print("test: passed")
else:
print("test: failed")
print(report)
except lxml.etree.XSLTParseError as err:
# problem parsing the schema
print err
except lxml.etree.XSLTApplyError as err:
# no problems parsing the schema, we do have a problem compiling it
print err
#
#
#
def main():
schema = 'schema/reference/eLife-elem-citation-driver-final.sch'
schema = 'min.sch' # pared down to almost nothing
xml = 'elife-09560-v1.xml'
runschematron(schema, xml)
if __name__ == '__main__':
main()