xml.sax module documentation

Paul Prescod paulp at ActiveState.com
Fri Nov 10 00:24:50 CET 2000

"S. Hendry" wrote:
> ...
> Actually I should be more specific.  I may be confused what a parser is.
> Maybe if I understand this, it will help me read the docs and available
> articles better.

Unless you have performance constraints, you may find the DOM easier to
use and (for now) more fully documented. It's easier to use because you
have the entire tree available at one time and you can navigate around
however you want. Also, it uses a more traditional Python coding
structure instead of a callback structure.

Here's how you dould do it with the DOM:

> ...
> if PO.Approver = "John Smith":
>    special_discount = 10
> ...

import xml.dom.minidom as minidom

data = """
  <Approver>John Smith</Approver>

document = minidom.parseString( data )

po = document.getElementsByTagName("PO")[0]
approver = po.getElementsByTagName("Approver")[0]
text = approver.childNodes[0].nodeValue
print text


More information about the Python-list mailing list