[XML-SIG] [pyxml][doc][5.1] Clarification request

Lukasz Szybalski szybalski at gmail.com
Thu Jun 1 22:23:18 CEST 2006

pyxml basics

I am following pyxml doc in hope to quickly grasp functions and
classes available in pyxml.
starting out:

>>> from xml.sax import saxutils
>>> class FindIssue(saxutils.DefaultHandler):
...     def __init__(self,title,number):
...             self.search_title, self.search_number = title, number
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'DefaultHandler'

1. What exactly above class will do? How do i fix it to not give me an error?
Doc states.
"The DefaultHandler class inherits from all four interfaces:
ContentHandler, DTDHandler, EntityResolver, and ErrorHandler. This
(this = ContentHandler or ?)  is what you should use if you want to
just write a single class that wraps up all the logic for your
2. Do you mean that Default Handler should be substituted with
ContentHandler? What exactly should i do?

Doc next states...
"You could also subclass each interface individually and implement
separate classes for each purpose."
3. Do you mean : you can create a class or a subclass for your
specific element or node?
I don't know what we are trying to do here. I though we want to
extract one or all of the elements from
  <comic title="Sandman" number='62'>
    <writer>Neil Gaiman</writer>
    <penciller pages='1-9,18-24'>Glyn Dillon</penciller>
    <penciller pages="10-17">Charles Vess</penciller>

4. How do we use startElement?

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: startElement() takes exactly 3 arguments (2 given)

Then running the code ......
from xml.sax import make_parser
from xml.sax.handler import feature_namespaces

if __name__ == '__main__':
    # Create a parser
    parser = make_parser()..........

Doc states: "Once you've created a parser instance, calling the
setContentHandler() method tells the parser what to use as the content
5. How do you do create parser instance by calling setContentHandler()??

At the end doc says.
If you run the above code with the sample XML document, it'll print
Sandman #62 found.
6. Which above code do you run, and how?

Thank you

More information about the XML-SIG mailing list