Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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