Дмитрий, спасибо за ссылку. Разобрался и допилил функционал, как хотел. Привожу код, возможно кому-нибудь пригодится
import os
import sys
import datetime
from lxml import etree
rootDir = os.path.dirname(sys.argv[0])
scheme = '{}\\{}'.format(rootDir, 'ListForRating_v03\ListForRating_v03.xsd')
pathToXML = '{}\\{}'.format(rootDir, 'xml')
class Validator:
def __init__(self, xsd_path: str):
xmlschema_doc = etree.parse(xsd_path)
self.xmlschema = etree.XMLSchema(xmlschema_doc)
def validate(self, xml_path: str) -> str:
xml_doc = etree.parse(xml_path)
try:
self.xmlschema.assertValid(xml_doc)
return 'Valid! :)'
except etree.DocumentInvalid as e:
msg = 'Not valid! :( Errors save in errors.log:'
with open('errors.log', 'a') as f:
for error in self.xmlschema.error_log:
f.write('File name: {} Error: {} Line: {}.\n'.format(os.path.basename(xml_path), error.message, error.line))
return msg
validator = Validator(scheme)
Files = os.listdir(pathToXML)
t = 'files' if len(Files) > 1 else 'file'
print('Scanning %s %s' % (len(Files), t))
timeBegin = datetime.datetime.now()
for file_name in Files:
print('{}: '.format(file_name), end='')
file_path = '{}\\{}'.format(pathToXML, file_name)
print(validator.validate(file_path))
timeEnd = datetime.datetime.now()
delta = timeEnd - timeBegin