Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating documents with etree.XMLSchema #42

Open
lmar76 opened this issue Jan 3, 2022 · 0 comments
Open

Validating documents with etree.XMLSchema #42

lmar76 opened this issue Jan 3, 2022 · 0 comments

Comments

@lmar76
Copy link

lmar76 commented Jan 3, 2022

According to the documentation it is possible to validate an ElementTree object against an XML schema using etree.XMLSchema.validate() method or using it as a callable. In both cases, mypy traces an error. E.g.:

import sys

from lxml import etree


def main() -> None:
    try:
        schema_file = sys.argv[1]
        file = sys.argv[2]
    except IndexError:
        sys.exit("Missing argument(s)")

    schema = etree.XMLSchema(etree.parse(schema_file))
    doc = etree.parse(file)

    if schema(doc):
        print(f"{file} is valid")
    else:
        print(f"{file} is not valid")

    if schema.validate(doc):
        print(f"{file} is valid")
    else:
        print(f"{file} is not valid")


if __name__ == '__main__':
    main()
% mypy main.py     
main.py:16: error: "XMLSchema" not callable
main.py:21: error: "XMLSchema" has no attribute "validate"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant