Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you generate xml from non string data types using minidom?
    primarykey
    data
    text
    <p>How do you generate xml from non string data types using minidom? I have a feeling someone is going to tell me to generate strings before hand, but this is not what I'm after.</p> <pre><code>from datetime import datetime from xml.dom.minidom import Document num = "1109" bool = "false" time = "2010-06-24T14:44:46.000" doc = Document() Submission = doc.createElement("Submission") Submission.setAttribute("bool",bool) doc.appendChild(Submission) Schedule = doc.createElement("Schedule") Schedule.setAttribute("id",num) Schedule.setAttribute("time",time) Submission.appendChild(Schedule) print doc.toprettyxml(indent=" ",encoding="UTF-8") </code></pre> <p>This is the result:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Submission bool="false"&gt; &lt;Schedule id="1109" time="2010-06-24T14:44:46.000"/&gt; &lt;/Submission&gt; </code></pre> <p>How do I get valid xml representations of non-string datatypes?</p> <pre><code>from datetime import datetime from xml.dom.minidom import Document num = 1109 bool = False time = datetime.now() doc = Document() Submission = doc.createElement("Submission") Submission.setAttribute("bool",bool) doc.appendChild(Submission) Schedule = doc.createElement("Schedule") Schedule.setAttribute("id",num) Schedule.setAttribute("time",time) Submission.appendChild(Schedule) print doc.toprettyxml(indent=" ",encoding="UTF-8") </code></pre> <p>File "C:\Python25\lib\xml\dom\minidom.py", line 299, in _write_data data = data.replace("&amp;", "&amp;").replace("&lt;", "&lt;") AttributeError: 'bool' object has no attribute 'replace'</p>
    singulars
    1. This table or related slice is empty.
    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.
    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