python对xml进行schema检查

#-*- coding:utf-8 -*-
"""
usage:
    python xml_schema_check.py schema_file data_file
"""
from lxml import etree
import sys
schema_file = sys.argv[1]
data_file = sys.argv[2]

schema_doc = etree.parse(schema_file)
schema = etree.XMLSchema(schema_doc)

data = etree.parse(data_file)
print schema.validate(data)
print schema.error_log 

你可能感兴趣的:(python对xml进行schema检查)