#!/usr/bin/env python

from xml.sax import handler

class XMLElement(object):
    """
    Represents XML elements from a document. These will assist
    us in representing an XML document as a Python object.
    """

    def __init__(self, name, attributes):
        self._name = name
        self._attributes = attributes
        self.children = []
        self.is_root = False

    def __iter__(self):
        yield self

    #TODO: make sure all XMLElements behave as lists during iteration
    def __len__(self):
        return 1


@@ -528,8 +528,691 @@
 turn 1%0A%0A
+    def __getitem__(self, key):%0A        return self.get_attribute(key)%0A%0A    def __getattr__(self, key):%0A        candidates = filter(lambda x: x._name == key, self.children)%0A        if candidates:%0A            self.__dict__%5Bkey%5D = candidates%0A            return candidates%0A        else:%0A            raise KeyError(%22No such child: %7B0%7D%22.format(key))%0A%0A    def add_child(self, child):%0A        self.children.append(child)%0A%0A    def get_attribute(self, key):%0A        return self._attributes.get(key, None)%0A%0A    def get_xmlelements(self, name):%0A        return filter(lambda x: x._name == name, self.children) %5C%0A               if name else %5C%0A               self.children%0A    %0A        %0A        %0A%0A

add element accessors