Skip to content

Instantly share code, notes, and snippets.

@klb3713
Created August 24, 2013 07:21
Show Gist options
  • Save klb3713/6326630 to your computer and use it in GitHub Desktop.
Save klb3713/6326630 to your computer and use it in GitHub Desktop.
lxml: 使用xsd验证xml文件
# -*- coding: utf-8 -*-
__author__ = 'klb3713'
from lxml import etree
xsdfile = etree.parse("./test.xsd")
xmlschema = etree.XMLSchema(xsdfile)
xmldoc = etree.parse("./test.xml")
print xmlschema.validate(xmldoc)
xmlschema.assert_(xmldoc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment