def xmlstring(elt, stripXmlns=False, prettyPrint=False, contentsOnly=False): if contentsOnly: return ('\n' if prettyPrint else '').join( xmlstring(child, stripXmlns, prettyPrint) for child in elt.iterchildren()) xml = etree.tostring(elt, encoding=_STR_UNICODE, pretty_print=prettyPrint) if not prettyPrint: xml = xml.strip() if stripXmlns: return xmlnsStripPattern.sub('', xml) else: return xml
def xmlstring(elt, stripXmlns=False, prettyPrint=False, contentsOnly=False, includeText=False): if contentsOnly: if includeText: _text = elt.text _tail = elt.tail else: _text = _tail = "" return _text + ('\n' if prettyPrint else '').join( xmlstring(child, stripXmlns, prettyPrint) for child in elt.iterchildren()) + _tail xml = etree.tostring(elt, encoding=_STR_UNICODE, pretty_print=prettyPrint) if not prettyPrint: xml = xml.strip() if stripXmlns: return xmlnsStripPattern.sub('', xml) else: return xml
def xmlstring(elt, stripXmlns=False, prettyPrint=False, contentsOnly=False, includeText=False): if elt is None: return "" if contentsOnly: if includeText: _text = elt.text or "" _tail = elt.tail or "" else: _text = _tail = "" return _text + ('\n' if prettyPrint else '').join( xmlstring(child, stripXmlns, prettyPrint) for child in elt.iterchildren()) + _tail xml = etree.tostring(elt, encoding=_STR_UNICODE, pretty_print=prettyPrint) if not prettyPrint: xml = xml.strip() if stripXmlns: return xmlnsStripPattern.sub('', xml) else: return xml