Friday, November 9, 2007

Still Working on Lab3

Well, I'm getting there. I pretty much have the index and domain pages displaying properly now. The trick was finding out how to use XML in python. I tried Amara, but the installation failed. So, I decided to try ElementTree. I didn't have to install anything to use it. It was a bit tricky to understand how to use it at first, but it really isn't that bad.

Here's an example:

from elementtree import ElementTree
tree = ElementTree.XML('some xml string')

# find all nodes with tag
for node in tree.getiterator('domain'):
# get attribute ideacount's value
ideacount = node.get('ideacount')

# get text between the tags
domain = node.text

# find child node of foo where tag =
foo = node.find('submit')
tech = foo.get('technology') #get technology attribute

Now I just have to work on the submit process.

No comments: