def tostring(element, encoding="UTF-8", pretty_print=False):
    if HAS_LXML:
        return xml_to_string(element,
                             encoding="unicode",
                             pretty_print=pretty_print)
    else:
        return to_text(
            xml_to_string(element, encoding),
            encoding=encoding,
        )
Esempio n. 2
0
def include_additional_menu_items():
    parser = XMLParser(remove_blank_text=True)
    doc = xml_from_string(gen_menu_items(), parser=parser)
    html_fragments_str = ''
    for elem in doc.xpath('/child::node()/*'):
        # because Jinja2 produces HTML5 instead of XHTML, we need to re-parse the fragments:
        html_fragments_str += html_to_string(
            html_fragment_from_string(xml_to_string(elem))).decode('utf-8')
    return Markup(html_fragments_str)
Esempio n. 3
0
def include_xml_template(template_name):
    parser = XMLParser(remove_blank_text=True)
    # resource path is relative to the modules path, therefor '../../static/templates/'
    doc = parse(resource_stream(__name__,
                                '../../static/templates/' + template_name),
                parser=parser)
    html_fragments_str = ''
    for elem in doc.xpath('/child::node()/*'):
        # because Jinja2 produces HTML5 instead of XHTML, we need to re-parse the fragments:
        html_fragments_str += html_to_string(
            html_fragment_from_string(xml_to_string(elem))).decode('utf-8')
    return Markup(html_fragments_str)
Esempio n. 4
0
def tostring(element, encoding="UTF-8"):
    if HAS_LXML:
        return xml_to_string(element, encoding="unicode")
    else:
        return to_text(xml_to_string(element, encoding), encoding=encoding)
Esempio n. 5
0
File: ods.py Progetto: turicas/rows
def xpath(element, xpath, namespaces):
    return xml_from_string(xml_to_string(element)).xpath(xpath, namespaces=namespaces)
Esempio n. 6
0
def tostring(element, encoding='UTF-8'):
    if HAS_LXML:
        return xml_to_string(element, encoding='unicode')
    else:
        return to_text(xml_to_string(element, encoding), encoding=encoding)
Esempio n. 7
0
def xpath(element, xpath, namespaces):
    return xml_from_string(xml_to_string(element)).xpath(xpath,
                                                         namespaces=namespaces)