Generating xml in python and lxml

前端 未结 4 972
逝去的感伤
逝去的感伤 2020-12-25 08:21

I have this xml from sql, and I want to do the same by python 2.7 and lxml



  

        
4条回答
  •  旧时难觅i
    2020-12-25 09:16

    Note this also prints the BOM

    >>> from lxml.etree import tostring
    >>> from lxml.builder import E
    >>> print tostring(
                 E.results(
                     E.Country(name='Germany',
                               Code='DE',
                               Storage='Basic',
                               Status='Fresh',
                               Type='Photo')
                 ), pretty_print=True, xml_declaration=True, encoding='UTF-16')
    
    ��
    
      
    
    

提交回复
热议问题