XML
  Home arrow XML arrow Page 7 - Parsing XML with SAX and Python
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Parsing XML with SAX and Python
By: Nadia Poulou
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 36
    2004-11-09

    Table of Contents:
  • Parsing XML with SAX and Python
  • The xml.sax Package
  • Our SAX Parser
  • The Heart of the Code
  • Element Content
  • The Main Code
  • Homework

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    Conclusion 

    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.

    A very good reference site for Python and XML is "Uche Ogbuji's Akara site for XML processing in Python".

    Also, you may want to check out the Python library reference (search for the xml.sax package and sub-packages)


    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.

       · Nice article. The correct URL for Uche Ogbuji's site...
       · I'm new to all of this and found this article to be a tremendous help. Thanks so...
       · Thanks for this great article. I have a question. I am using your code to learn xml...
       · Thank you for this article. Very easy, ideas very well exposed. The code have...
       · Thanks. This was exactly what I was looking for and explained things very nicely...
     

    XML ARTICLES

    - Using Regions with XSL Formatting Objects
    - Using XSL Formatting Objects
    - More Schematron Features
    - Schematron Patterns and Validation
    - Using Schematron
    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek