xml.sax module documentation

Hendry, Slamet shendry at usa.capgemini.com
Fri Nov 10 15:45:19 CET 2000


Thank you.  That clears things up.

Slamet Hendry,  shendry at usa.capgemini.com


-----Original Message-----
From: Paul Prescod [mailto:paulp at ActiveState.com]
Sent: Thursday, November 09, 2000 5:25 PM
To: S. Hendry
Cc: python-list at python.org
Subject: Re: xml.sax module documentation


"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 = """
<PO>
  <POnum>123</POnum>
  <Approver>John Smith</Approver>
  <Items>
    <Num>1</Num>
      <SKU>34A</SKU>
      <Qty>10</Qty>
    <Num>2</Num>
  </Items>
</PO>
"""

document = minidom.parseString( data )

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

 Paul




More information about the Python-list mailing list