def startElement(self, elem, attrs): # Remember the name of the previous element previousElem = None if self.env.currentElem: previousElem = self.env.currentElem.name e = XmlParser.startElement(self, elem, attrs) # Determine the type of the element. elemType = 'unicode' # Default value if attrs.has_key('type'): elemType = attrs['type'] elif self.tagTypes.has_key(elem): elemType = self.tagTypes[elem] if elemType in self.containerTags: # I must create a new container object. if elemType == 'object': newObject = Object(**self.convertAttrs(attrs)) elif elemType == 'tuple': newObject = [] # Tuples become lists elif elemType == 'list': newObject = [] elif elemType == 'dict': newObject = {} elif elemType == 'file': newObject = UnmarshalledFile() if attrs.has_key('name'): newObject.name = attrs['name'] if attrs.has_key('mimeType'): newObject.mimeType = attrs['mimeType'] else: newObject = Object(**self.convertAttrs(attrs)) # Store the value on the last container, or on the root object. self.storeValue(elem, newObject) # Push the new object on the container stack e.containerStack.append(newObject) else: # If we are already parsing a basic type, it means that we were # wrong for our diagnotsic of the containing element: it was not # basic. We will make the assumption that the containing element is # then an object. if e.currentBasicType: # Previous elem was an object: create it on the stack. newObject = Object() self.storeValue(previousElem, newObject) e.containerStack.append(newObject) e.currentBasicType = elemType