Fix Python – Validating with an XML schema in Python

Question

Asked By – Eli Courtwright

I have an XML file and an XML schema in another file and I’d like to validate that my XML file adheres to the schema. How do I do this in Python?

I’d prefer something using the standard library, but I can install a third-party package if necessary.

Now we will see solution for issue: Validating with an XML schema in Python


Answer

I am assuming you mean using XSD files. Surprisingly there aren’t many python XML libraries that support this. lxml does however. Check Validation with lxml. The page also lists how to use lxml to validate with other schema types.

This question is answered By – Keegan Carruthers-Smith

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0