The XML Validation subject area is quite complex. The reason for this is that when there is intelligence in your data, as XML often has, it can be organized in a variety of ways. One approach with XML data is to oversee its integrity with the use of DTD schemas, which is like a blueprint for your XML data, outlining how it should be structured to pass validation checks. If you know your XML data passes the validation tests implied by the DTD then you are likely to have a very successful project, if the DTD has been structured methodically and has enough flexibility to express all the complication needed to satisfy business logic requirements.
Python has functionality to help with validating XML in a variety of different scenarios, as do other languages such as PHP and Java, for example. Here for this tutorial there were two huge contributions from:
- the Eclipse IDE XML examples provided ( the same as used in yesterday to yesterday’s tutorial Java Eclipse XML and DTD Validate Primer Tutorial )
- very good tutorial here where only the input file name was changed in download code presented below
In this primer tutorial you can see some Python XML and DTD validation program in action on a Windows laptop using Python 2.4 and PyXML 0.8.4, as you will see being installed, during the tutorial.
Link to downloadable Python programming source code for XML and DTD validation xmldtdvalidate.py
Link to sample DTD data Invoice.dtd
Link to sample XML data Invoice.xml
If this was interesting you may be interested in this too.
2 Responses to Python XML and DTD Validate Primer Tutorial