Get the XML as an UTF-8 string

        :returns: bytes encoded as UTF-8
4379
def get_xml(self, pretty=True):
        
        return etree.tostring(self.root, encoding="utf-8", pretty_print=pretty)
1337601
public static String documentToString(Document xmlDocument) throws IOException {
        String encoding = (xmlDocument.getXmlEncoding() == null) ? "UTF-8" : xmlDocument.getXmlEncoding();
        OutputFormat format = new OutputFormat(xmlDocument);
        format.setLineWidth(65);
        format.setIndenting(true);
        format.setIndent(2);
        format.setEncoding(encoding);
        try (Writer out = new StringWriter()) {
            XMLSerializer serializer = new XMLSerializer(out, format);
            serializer.serialize(xmlDocument);
            return out.toString();
        }
    }
890634
def etree_to_string(root, pretty_print=True, xml_declaration=True,
                    encoding='utf-8'):
    """"""
    return etree.tostring(
        root,
        pretty_print=pretty_print,
        xml_declaration=xml_declaration,
        encoding=encoding,
    ).decode('utf-8')
463467
def _handle_utf8_payload(body, properties):
        
        if 'content_encoding' not in properties:
            properties['content_encoding'] = 'utf-8'
        encoding = properties['content_encoding']
        if compatibility.is_unicode(body):
            body = body.encode(encoding)
        elif compatibility.PYTHON3 and isinstance(body, str):
            body = bytes(body, encoding=encoding)
        return body
1117772
def to_xml_string(str = '')
      str << '<?xml version="1.0" encoding="UTF-8"?>'
      str << ('<Types xmlns="' << XML_NS_T << '">')
      each { |type| type.to_xml_string(str) }
      str << '</Types>'
    end
475533
def getXML(self):
        
        xml='<'+self._elementName+' '
        for key,value in list(self._attributes.items()):
            if value != None:
                xml+=key+'="'+self.quote_attrib(str(value))+'" '
        if  len(self._subElements)==0: #self._textContent==None and
            xml+=' />\n'
        else:
            xml+=' >\n'
            #if self._textContent==None:
            for subelement in self._subElements:
                s = subelement.getXML()
                if type(s) != str:
                    s = str(s)
                xml+=s
               # xml+=str(subelement.getXML())
            #else:
            #if self._textContent!=None:
            #    xml+=self._textContent
            xml+='</'+self._elementName+'>\n'
        #print xml
        return xml
1156153
def convert_xml_to_text(filename: str = None,
                        blob: bytes = None,
                        config: TextProcessingConfig = _DEFAULT_CONFIG) -> str:
    
    with get_filelikeobject(filename, blob) as fp:
        soup = bs4.BeautifulStoneSoup(fp)
        return soup.get_text()
1337792
def xmllint_format(xml):
    
    parser = ET.XMLParser(resolve_entities=False, strip_cdata=False, remove_blank_text=True)
    document = ET.fromstring(xml, parser)
    return ('%s\n%s' % ('<?xml version="1.0" encoding="UTF-8"?>', ET.tostring(document, pretty_print=True).decode('utf-8'))).encode('utf-8')
693881
def read_string(self):
        
        length = self.read_int()
        return str(self.read(length).decode("UTF-8"))
1280491
def toxml(self, encoding="UTF-8"):
        
        domtree = self.todom()
        # WARNING: The XML declaration has to follow the order 
        # version-encoding-standalone (standalone being optional), otherwise 
        # if it is embedded in an exe the exe will fail to launch! 
        # ('application configuration incorrect')
        xmlstr = domtree.toxml(encoding).replace(
            '<?xml version="1.0" encoding="%s"?>' % encoding, 
            '<?xml version="1.0" encoding="%s" standalone="yes"?>' % encoding)
        domtree.unlink()
        return xmlstr
604908
def toString(self):
        
        xprofile = self.toXml()
        projex.text.xmlindent(xprofile)
        return ElementTree.tostring(xprofile)
849140
def serialize_for_reading(element):
    
    xml = etree.tostring(element, encoding='unicode', pretty_print=True)
    return XmlString(xml)
1239635
def toxml(self):
        

        return '<Property name="{0}"'.format(self.name) +\
          (' dimension="{0}"'.format(self.dimension) if self.dimension else 'none') +\
          (' defaultValue = "{0}"'.format(self.default_value) if self.default_value else '') +\
          '/>'
110687
def request_xml(url, auth=None):
    '''
    
    '''
    try:
        r = requests.get(url, auth=auth, verify=False)
        return r.text.encode('utf-8')
    except BaseException:
        logger.error("Skipping %s (error parsing the XML)" % url)
    return
1121820
def is_xml(text):
    
    # BOM_UTF8 is an UTF-8 byte order mark which may precede the XML from an Exchange server
    bom_len = len(BOM_UTF8)
    if text[:bom_len] == BOM_UTF8:
        return text[bom_len:bom_len + 5] == b'<?xml'
    return text[:5] == b'<?xml'
909597
def prettify(root, encoding='utf-8'):
    
    if isinstance(root, ElementTree.Element):
        node = ElementTree.tostring(root, 'utf-8')
    else:
        node = root

    # Hacky solution as it seems PyXML doesn't exist anymore... 
    return etree.tostring(etree.fromstring(node),
                          pretty_print=True,
                          xml_declaration=True,
                          encoding='utf-8')
1233392
def utf8(s):
    
    if isinstance(s, mitogen.core.UnicodeType):
        s = s.encode('utf-8')
    return s