0
경로에서 xml 파일을 구문 분석하고 객체화하기 위해 lxml을 사용하고 있습니다. 모델과 xsd가 많으며 각 객체 모델은 특정 정의 된 클래스에 매핑됩니다 xml이 model 태그로 시작하면 dataModel이고 page 태그로 시작하면 viewModel입니다.xml의 시작 태그를 감지하고 구문 분석하고 객 체화하는 방법
내 질문은 XML 파일이있는 태그로 시작하는 것이 효율적인 방법으로 감지하고 적절한 XSD 파일을 구문 분석 한 후이
files = glob(os.path.join('resources/xml', '*.xml'))
for f in files:
xmlinput = open(f)
xmlContent = xmlinput.read()
if xsdPath:
xsdFile = open(xsdPath)
# xsdFile should retrieve according to xml content
schema = etree.XMLSchema(file=xsdFile)
xmlinput.seek(0)
myxml = etree.parse(xmlinput)
try:
schema.assertValid(myxml)
except etree.DocumentInvalid as x:
print "In file %s error %s has occurred." % (xmlPath, x.message)
finally:
xsdFile.close()
xmlinput.close()