Return a pretty-printed XML string for the Element.
420265
def prettify_xml(elem):
    
    from xml.dom import minidom
    import xml.etree.cElementTree as et

    rough_string = et.tostring(elem, 'utf-8')
    reparsed = minidom.parseString(rough_string)
    return reparsed.toprettyxml(indent="  ")
415708
def prettyXml(elem):
    
    roughString = ET.tostring(elem, "utf-8")
    reparsed = minidom.parseString(roughString)
    return reparsed.toprettyxml(indent="  ")
706013
def _get_xml_version(element):
    """"""
    if "versions" in element.attrib:
        result = [ int(v) for v in re.split(",\s*", element.attrib["versions"]) ]
    else:
        result = [ 1 ]

    return result
200320
def _hl_as_string(self, highlight):
        
        # dummy tags to make it valid xml
        dummy_xml = "<p>" + highlight + "</p>"
        try:
            element_tree = ET.fromstring(dummy_xml)
        except ET.ParseError:
            raise ET.ParseError
        return "".join(list(element_tree.itertext()))
625184
def getXML(self):
        
        s = ''
        for element in self._svgElements:
            s += element.getXML()
        return s
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')
444180
def output_xml(data, code, headers=None):
    """"""
    resp = make_response(dumps({'response' :data}), code)
    resp.headers.extend(headers or {})
    return resp
500315
def xml(self, indent=4, **kwargs):
        
        writer = StringIO()
        self.write(writer, indent=indent, **kwargs)
        return writer.getvalue()
795998
def tostr(self):
        """"""
        element = _transform.SVGFigure(self.width, self.height)
        element.append(self)
        svgstr = element.to_str()
        return svgstr
641875
public static String prettyPrint(String xml) {
        LSParser parser = configurer.createLSParser();
        configurer.setParserConfigParameter(parser, VALIDATE_IF_SCHEMA, false);

        LSInput input = configurer.createLSInput();

        try {
            Charset charset = getTargetCharset(xml);

            input.setByteStream(new ByteArrayInputStream(xml.trim().getBytes(charset)));
            input.setEncoding(charset.displayName());
        } catch(UnsupportedEncodingException e) {
            throw new CitrusRuntimeException(e);
        }

        Document doc;
        try {
            doc = parser.parse(input);
        } catch (Exception e) {
            return xml;
        }

        return serialize(doc);
    }
1223743
def pretty_xml(data):
    
    parsed_string = minidom.parseString(data.decode('utf-8'))
    return parsed_string.toprettyxml(indent='\t', encoding='utf-8')
324562
def to_string(self):
        """"""
        root = etree.Element('urlset', nsmap={None: SITEMAP_NS})
        for url in self.urls:
            url.generate(root)
        return etree.tostring(root, pretty_print=True, xml_declaration=True,
                              encoding='utf-8')
691841
public static String prettyPrintElementLocally(Element e) {
    final ImmutableMap.Builder<String, String> ret = ImmutableMap.builder();
    final NamedNodeMap attributes = e.getAttributes();
    for (int i = 0; i < attributes.getLength(); ++i) {
      final Node attr = attributes.item(i);
      ret.put(attr.getNodeName(), "\"" + attr.getNodeValue() + "\"");
    }
    return "<" + e.getNodeName() + " " + Joiner.on(" ").withKeyValueSeparator("=").join(ret.build())
        + "/>";
  }
199291
def pformat_xml(xml):
    """"""
    try:
        from lxml import etree  # delayed import
        if not isinstance(xml, bytes):
            xml = xml.encode('utf-8')
        xml = etree.parse(io.BytesIO(xml))
        xml = etree.tostring(xml, pretty_print=True, xml_declaration=True,
                             encoding=xml.docinfo.encoding)
        xml = bytes2str(xml)
    except Exception:
        if isinstance(xml, bytes):
            xml = bytes2str(xml)
        xml = xml.replace('><', '>\n<')
    return xml.replace('  ', ' ').replace('\t', ' ')
1019891
protected function pretty()
    {
        $xml = $this->getParameter('value');
        $level = $this->getParameter('level') != null ? intval($this->getParameter('level')) : 6;

        // get an array containing each XML element
        $xml = explode("\n", preg_replace('/>\s*</', ">\n<", $xml));

        // hold current indentation level
        $indent = 0;

        // hold the XML segments
        $pretty = array();

        // shift off opening XML tag if present
        if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
            $pretty[] = array_shift($xml);
        }

        foreach ($xml as $el) {
            if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
                if($indent < 0) $indent = 0;
                // opening tag, increase indent
                $pretty[] = str_repeat('&nbsp;', $indent) . htmlentities($el,ENT_QUOTES);
                $indent += $level;
            } else {
                if (preg_match('/^<\/.+>$/', $el)) {
                    // closing tag, decrease indent
                    $indent -= $level;
                }
                $pretty[] = str_repeat('&nbsp;', abs($indent)) . htmlentities($el,ENT_QUOTES);
            }
        }

        return implode("<br/>", $pretty);
    }
500167
def format_xml(xml_str: str, exceptions: bool=False):
    
    try:
        import xml.dom.minidom
        return xml.dom.minidom.parseString(xml_str).toprettyxml()
    except Exception:
        if exceptions:
            raise
        return xml_str
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')