xml processing

Steven Bethard steven.bethard at gmail.com
Wed Jun 1 11:01:48 EDT 2005


Jeff Elkins wrote:
> I've like to use python to maintain a small addressbook which lives on a Sharp 
> Zaurus. This list will never grow beyond 200 or so entries. I've installed 
> pyxml.

If you're not committed to pyxml, you might consider using ElementTree:

http://effbot.org/zone/element-index.htm

I find it *way* easier to work with.

> 
> Speaking generally, given a wxpython app to do data entry, 
> I'm planning to:
> 
> 1. parse the addressbook file, loading its data into an array.
> 2. Perform any edit operations within the array.
> 3. Write out a finished xml file from the array when I'm done.
> 
> Is this reasonable? Better, smarter ways to accomplish this?

Seems pretty reasonable.  Another option might be to parse the 
addressbook file into an XML object and then modify the XML object 
itself.  E.g.:

tree = ElementTree(file="...")
elem = tree.getroot()
for node in elem.findall("..."):
     node.text = "..."

STeVe



More information about the Python-list mailing list