Convert and return the XML for an *ele* (:class:`~xml.etree.ElementTree.Element`) with specified *encoding*.
160345
def to_xml(ele, encoding="UTF-8", pretty_print=False):
    ""
    xml = etree.tostring(ele, encoding=encoding, pretty_print=pretty_print)
    if sys.version < '3':
        return xml if xml.startswith('<?xml') else '<?xml version="1.0" encoding="%s"?>%s' % (encoding, xml)
    else:
        return xml.decode('UTF-8') if xml.startswith(b'<?xml') \
            else '<?xml version="1.0" encoding="%s"?>%s' % (encoding, xml.decode('UTF-8'))
962082
def xml(self, attribs = None,elements = None, skipchildren = False):
        """"""
        E = ElementMaker(namespace=NSFOLIA,nsmap={None: NSFOLIA, 'xml' : "http://www.w3.org/XML/1998/namespace"})

        if not attribs: attribs = {}
        if not elements: elements = []

        if self.id:
            attribs['id'] = self.id
            try:
                w = self.doc[self.id]
                attribs['t'] = w.text()
            except KeyError:
                pass

        e  = makeelement(E, '{' + NSFOLIA + '}' + self.XMLTAG, **attribs)
        return e
79473
def to_element(self):
        
        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
348399
def Element(cls, s, *args):
        """"""
        sargs = []
        for arg in args:
            if type(arg) == etree._Element:
                sargs.append(etree.tounicode(arg))
            else:
                sargs.append(arg)
        if type(s) == etree._Element:
            t = etree.tounicode(s)
        else:
            t = s
        if len(args) == 0:
            return XML.fromstring(t)
        else:
            return XML.fromstring(t % tuple(sargs))
556463
def raw_html(self) -> _RawHTML:
        
        if self._html:
            return self._html
        else:
            return etree.tostring(self.element, encoding='unicode').strip().encode(self.encoding)
7357
def encode(self):
        
        root_element = ElementTree.Element(self.TAG_NAME)
        for value in [value for value in self.__dict__.values() if isinstance(value, fields.Field)]:
            if value.required or value.value:
                root_element.append(value.encode())
        return root_element
647637
def copy_of_xml_element(elem):
    

    copyElem = ElementTree.Element(elem.tag, elem.attrib)
    for child in elem:
        copyElem.append(child)
    return copyElem
454661
def writeXML(self, e):
        
        self.writeType(TYPE_XML)

        data = xml.tostring(e)

        if isinstance(data, unicode):
            data = data.encode('utf-8')

        self.stream.write_ulong(len(data))
        self.stream.write(data)
313343
def to_xml_string(self):
        

        self.update_xml_element()
        xml = self.xml_element

        return etree.tostring(xml, pretty_print=True).decode('utf-8')
244058
def get_xml(self):
        
        with io.StringIO() as string:
            string.write(ET.tostring(self.root, encoding="unicode"))
            return string.getvalue()
580026
def to_xml(self, xmllint=False):
        
        root = self._tree.getroot()
        ret = ET.tostring(ET.ElementTree(root), pretty_print=True)
        if xmllint:
            ret = xmllint_format(ret)
        return ret
492171
def get_element(text_or_tree_or_element):
    
    if isinstance(text_or_tree_or_element, ET.Element):
        return text_or_tree_or_element
    elif isinstance(text_or_tree_or_element, ET.ElementTree):
        return text_or_tree_or_element.getroot()
    elif isinstance(text_or_tree_or_element, (unicode, bytes)):
        return ET.fromstring(text_or_tree_or_element)
    else:
        return ET.parse(text_or_tree_or_element).getroot()
329369
def raw_xml(self) -> _RawXML:
        
        if self._xml:
            return self._xml
        else:
            return etree.tostring(self.element, encoding='unicode').strip().encode(self.encoding)
1247354
def encode_gen(line, encoding="utf-8"):
    

    for ele in line:
        if isinstance(ele, types.UnicodeType):
            yield ele.encode(encoding)
        else:
            yield ele
893423
def decodeXML( text )
      encodingStrings( true ) { |key,value| text.gsub!( value, key ) if text }
      text.gsub!( /&#([0-9]{2,3});/ ) { |c| $1.chr } if text
      text
   end
764463
def from_string(cls, jss, xml_string):
        
        root = ElementTree.fromstring(xml_string.encode('utf-8'))
        return cls(jss, root)
647181
def xmlparser(xml, objectify=True):
    
    doclose = None
    if isinstance(xml, (etree._Element, ObjectifiedElement, etree._ElementTree)):
        return xml
    elif isinstance(xml, text_type):
        xml = StringIO(xml)
        doclose = True
    elif not isinstance(xml, IOBase):
        raise TypeError("Unsupported type of resource {}".format(type(xml)))

    if objectify is False:
        parsed = etree.parse(xml).getroot()
    else:
        parsed = parse(xml).getroot()
    if doclose:
        xml.close()
    return parsed