简体   繁体   中英

Python or XSD for validating XML documents

Getting XML documents from external sources, not all of them following a schema makes it hard to have all identical structured XML files.

1st option: Use an XML Scheme language or XSD

2nd option: Use Python(ElementTree, Panda) to create a XML validation checker

Which option would be better considering the number of files is quite a lot and I don't want to change the rules every time I get XMLS from a new external source?

The goal would be to have a self-sustainable XML validation/checker

I would go with lxml and XSD validation . XSD is the way to go by design and does not creates a dependency in any language (python,java,etc..)

XML Schema was invented specifically to solve this type of problem, and it does it very well. I cannot think of any good reason to write your own validator. You may like ElementTree a lot and be very productive with it, but it's never going to do the job as easily and thoroughly as an XSD.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM