Note that there are some explanatory texts on larger screens.

plurals
  1. POpython lxml with py2exe
    primarykey
    data
    text
    <p>I have Generated an XML with dom and i want to use lxml to pretty print the xml. </p> <p>this is my code for pretty print the xml </p> <pre><code>def prettify_xml(xml_str): import lxml.etree as etree root = etree.fromstring(xml_str) xml_str = etree.tostring(root, pretty_print=True) return xml_str </code></pre> <p>my output should be an xml formatted string.</p> <p>I got this code from some post in stactoverflow. This works flawlessly when i am compiling wit python itself. But when i convert my project to a binary created from py2exe (my binary is windows service with a namedpipe).I had two problems:</p> <ol> <li><p>My service was not starting , i solved this by adding <code>lxml.etree</code> in <code>includes</code> option in py2exe function. then on my service started properly. </p></li> <li><p>when xml generation in called here, is the error which I am seeing in my log <code>'module' object has no attribute 'fromstring'</code></p></li> </ol> <p>where do i rectify this error ? And Is my first problem's solution correct ?</p> <p>my xml generation Code : </p> <pre><code>from xml.etree import ElementTree from xml.dom import minidom from xml.etree.ElementTree import Element, SubElement, tostring, XML import lxml.etree def prettify_xml(xml_str): root = lxml.etree.fromstring(xml_str) xml_str = lxml.etree.tostring(root, pretty_print=True) return xml_str def dll_xml(status): try: xml_declaration = '&lt;?xml version="1.0" standalone="no" ?&gt;' rootTagName='response' root = Element(rootTagName) root.set('id' , 'rp001') parent = SubElement(root, 'command', opcode ='-ac') # Create children chdtag1Name = 'mode' chdtag1Value = 'repreport' chdtag2Name='status' chdtag2Value = status fullchildtag1 = ''+chdtag1Name+' value = "'+chdtag1Value+'"' fullchildtag2=''+chdtag2Name+' value="'+chdtag2Value+'"' children = XML('''&lt;root&gt;&lt;'''+fullchildtag1+''' /&gt;&lt;'''+fullchildtag2+'''/&gt;&lt;/root&gt; ''') # Add parent parent.extend(children) dll_xml_doc = xml_declaration + tostring(root) dll_xml_doc = prettify_xml(dll_xml_doc) return dll_xml_doc except Exception , error: log.error("xml_generation_failed : %s" % error) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload