from lxml import etree xsd = b""" """ schema = etree.XMLSchema(etree.fromstring(xsd)) for count in (5, 0, -2): document = etree.fromstring(f"{count}") print(count, schema.validate(document))