on May 19th, 2008pySX: Simple XML processing in Python
pySX is my latest hobby project. It’s a very simple XML library that aims to simplify the process of handling XML as much as possible. The code can be found here: http://svn.loveandtheft.org/fredrik/pysx. Here are a couple of quick usage examples:
“Manual”
When accessing an element, two things can happen:
- You get a list back, which means that there are more then one element with that name
- You get an object of type pysx.node.Element back, which means there’s only one element with that name
Examples
Loading an xml hierarchy
import pysx
tree = pysx.handler.parse('users.xml')
Iterating over a collection of elements
for user in tree.root.users:
print user.name
print user.age
print user.get_child('pysx:age') # Also under it's namespace
Accessing the n:th element
print tree.root.user[0].name
Accessing attributes
print tree.root.user['id'] print tree.root.user['pysx:id'] # namespaced
Replacing an element with another one
# replaces the first <user> with a <admin> print tree.root.user[0].replace_self(pysx.node.Element(qname = 'admin')) print tree.root.admin.name
Removing an element
tree.root.admin.remove_self()
there is something wrong with your svn-repo:
svn: PROPFIND of ‘/fredrik/pysx’: could not connect to server (http://svn.loveandtheft.org)
I’ll really like to try it :)
Yes, my server is currently down - it’ll be up by the end of the week again, trying to relocate it to a place where it doesn’t disturbt my nights sleep :)