<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def endElement(self, name):
 """ End current xml element, parse and add to to parent node. """

        if self.current:
            # we have nested elements
            obj = self.current
        else:
            # text only node
            text = ''.join(self.chardata).strip()
            obj = self._parse_node_data(text)
        newcurrent, self.chardata = self.stack.pop()
        self.current = self._element_to_node(newcurrent, name, obj)