Return an ElementTree Element based on this resource.

        Returns:
            ~xml.etree.ElementTree.Element: an Element.

def to_element(self):
        """Return an ElementTree Element based on this resource.

        Returns:
            ~xml.etree.ElementTree.Element: an Element.
        """
        if not self.protocol_info:
            raise DIDLMetadataError('Could not create Element for this'
                                    'resource:'
                                    'protocolInfo not set (required).')
        root = XML.Element('res')

        # Required
        root.attrib['protocolInfo'] = self.protocol_info
        # Optional
        if self.import_uri is not None:
            root.attrib['importUri'] = self.import_uri
        if self.size is not None:
            root.attrib['size'] = str(self.size)
        if self.duration is not None:
            root.attrib['duration'] = self.duration
        if self.bitrate is not None:
            root.attrib['bitrate'] = str(self.bitrate)
        if self.sample_frequency is not None:
            root.attrib['sampleFrequency'] = str(self.sample_frequency)
        if self.bits_per_sample is not None:
            root.attrib['bitsPerSample'] = str(self.bits_per_sample)
        if self.nr_audio_channels is not None:
            root.attrib['nrAudioChannels'] = str(self.nr_audio_channels)
        if self.resolution is not None:
            root.attrib['resolution'] = self.resolution
        if self.color_depth is not None:
            root.attrib['colorDepth'] = str(self.color_depth)
        if self.protection is not None:
            root.attrib['protection'] = self.protection

        root.text = self.uri
        return root