u"""Assigns a new XML structure to the node.

        A literal value, dict or list can be passed in. Works for all nested levels.

        Dictionary:
        >>> m = Mappet('<root/>')
        >>> m.head = {'a': 'A', 'b': {'#text': 'B', '@attr': 'val'}}
        >>> m.head.to_str()
        '<head><a>A</a><b attr="val">B</b></head>'

        List:
        >>> m.head = [{'a': i} for i in 'ABC']
        >>> m.head.to_str()
        '<head><a>A</a><a>B</a><a>C</a></head>'

        Literals:
        >>> m.head.leaf = 'A'
        >>> m.head.leaf.get()
        'A'

def set(self, name, value):
        u"""Assigns a new XML structure to the node.

        A literal value, dict or list can be passed in. Works for all nested levels.

        Dictionary:
        >>> m = Mappet('<root/>')
        >>> m.head = {'a': 'A', 'b': {'#text': 'B', '@attr': 'val'}}
        >>> m.head.to_str()
        '<head><a>A</a><b attr="val">B</b></head>'

        List:
        >>> m.head = [{'a': i} for i in 'ABC']
        >>> m.head.to_str()
        '<head><a>A</a><a>B</a><a>C</a></head>'

        Literals:
        >>> m.head.leaf = 'A'
        >>> m.head.leaf.get()
        'A'
        """
        try:
            # Searches for a node to assign to.
            element = next(self._xml.iterchildren(tag=name))
        except StopIteration:
            # There is no such node in the XML tree. We create a new one
            # with current root as parent (self._xml).
            element = etree.SubElement(self._xml, name)

        if isinstance(value, dict):
            self.assign_dict(element, value)
        elif isinstance(value, (list, tuple, set)):
            self.assign_sequence_or_set(element, value)
        else:
            # Literal value.
            self.assign_literal(element, value)

        # Clear the aliases.
        self._aliases = None