Parsing XML with SAX and Python - Homework (Page 7 of 7 )
Even if your knowledge of XML and Python is not advanced, I hope that by now you have an idea of how to implement a simple XML parser in Python. Of course this was just a very simple example to illustrate the possibilities of the xml.sax module of Python.
Here follow some ideas, based on our example, for further exploration:
Try to load the <select> list on our Web form dynamically from the XML document; that is to parse the document and to present the player names found as elements of the list.
In our example we mentioned nothing about proper XML syntax and similar matters. In production applications things do not always turn out as we would hope. This is why exception handling should always be part of your application. You can try to use one or more exception classes to handle the behavior of your script as soon as an error occurs, by (for example) showing the appropriate error message.
This tutorial covered the basics of the xml.sax package and its sub packages. This is not the only way to parse XML using Python. Hopefully in future articles we can take a look at other ways to do so and also take into account matters like XML validation and namespaces.
For the moment I would like to mention here PyXML, a toolkit with more than 200 XML-related modules and advanced implementations, including the xml.sax packages and sub packages. You can download it from here.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.