You have to encode the error messages in your error log using utf-8
. Try the following:
Code:
from lxml import etree
schema = etree.parse("2.xsd")
xmlschema = etree.XMLSchema(schema)
try:
document = etree.parse("1.xml")
print "Parse complete!"
except etree.XMLSyntaxError, e:
print e
print xmlschema.validate(document)
for error in xmlschema.error_log:
print "ERROR ON LINE %s: %s" % (error.line, error.message.encode("utf-8"))
Result:
Parse complete!
False
ERROR ON LINE 4: Element 'b': 'Привет мир!' is not a valid value of the atomic type 'xs:decimal'.
[Finished in 1.3s]
Relevant documentation can be found here.
Let us know if this helps.