<span class="gmail_quote"></span>hi, i've tested the matthew way, and it work perfectly. <br>Is possible to have the XML in a string (for example <span style="font-family: courier new,monospace;">xmlstring</span>) and for printing do a 
<br><span style="font-family: courier new,monospace;">
print xmlstring</span> ?<br><br>The Matthew way is<span class="q"><br><br><span style="font-family: courier new,monospace;">import sys</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

import elementtree.ElementTree as ET</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">root = ET.Element(&quot;manager&quot;)
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">req=ET.SubElement(root,&quot;request&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

app=ET.SubElement(req,&quot;append&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">app.set(&quot;mode&quot;,&quot;INPUT&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">met=ET.SubElement(app,&quot;method&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">met.set(&quot;type&quot;,&quot;GOOD&quot;)
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">src=ET.SubElement(app,&quot;source&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

src.set(&quot;address&quot;,&quot;</span><a style="font-family: courier new,monospace;" href="http://127.0.0.1/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">127.0.0.1</a><span style="font-family: courier new,monospace;">

&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">act=ET.SubElement(app,&quot;action&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

act.set(&quot;option&quot;,&quot;OK&quot;)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">tree = ET.ElementTree(root)
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">tree.write(sys.stdout)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

print</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$ python et.py</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&lt;manager&gt;&lt;request&gt;&lt;append mode=&quot;INPUT&quot;&gt;&lt;method type=&quot;GOOD&quot; /&gt;&lt;source<br>address=&quot;<a href="http://127.0.0.1/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

127.0.0.1</a>&quot; /&gt;&lt;action option=&quot;OK&quot;<br>/&gt;&lt;/append&gt;&lt;/request&gt;&lt;/manager&gt;<br></span><br><br></span><div><span class="gmail_quote">2006/1/19, Matthew Dixon Cowles &lt;<a href="mailto:matt@mondoinfo.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

matt@mondoinfo.com</a>&gt;:</span><div><span class="e" id="q_108e75d0fc6c1e20_3"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Dear Sbaush,
<br><br>&gt; Hi all.<br>&gt; I've this XML:<br>
&gt;<br>&gt; &lt;manager&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;request&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;append mode=&quot;INPUT&quot;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;method type=&quot;GOOD&quot;/&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source address=&quot; <a href="http://127.0.0.1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

127.0.0.1</a>&quot;/&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;action option=&quot;OK&quot;/&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/append&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/request&gt;<br>&gt; &lt;/manager&gt;<br>&gt;<br>&gt; How can i write this in a Python String? I would like use a
<br>&gt; xml.domimplementation and not a banal print...print...<br><br>Using Fredrik Lundh's ElementTree from:<br><br><a href="http://effbot.org/zone/element-index.htm" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://effbot.org/zone/element-index.htm</a><br><br>
you could do something like:<br><br>import sys<br>import elementtree.ElementTree as ET<br><br>root = ET.Element(&quot;manager&quot;)<br>req=ET.SubElement(root,&quot;request&quot;)<br>app=ET.SubElement(req,&quot;append&quot;)
<br>app.set(&quot;mode&quot;,&quot;INPUT&quot;)<br>met=ET.SubElement(app,&quot;method&quot;)<br>met.set(&quot;type&quot;,&quot;GOOD&quot;)<br>src=ET.SubElement(app,&quot;source&quot;)<br>src.set(&quot;address&quot;,&quot;
<a href="http://127.0.0.1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">127.0.0.1</a>&quot;)<br>act=ET.SubElement(app,&quot;action&quot;)<br>act.set(&quot;option&quot;,&quot;OK&quot;)<br><br>tree = 
ET.ElementTree(root)<br>tree.write(sys.stdout)<br>print<br><br>$ python 
et.py<br>&lt;manager&gt;&lt;request&gt;&lt;append mode=&quot;INPUT&quot;&gt;&lt;method type=&quot;GOOD&quot; /&gt;&lt;source<br>address=&quot;<a href="http://127.0.0.1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
127.0.0.1</a>&quot; /&gt;&lt;action option=&quot;OK&quot;
<br>/&gt;&lt;/append&gt;&lt;/request&gt;&lt;/manager&gt;<br><br>Regards,<br>Matt<br><br></blockquote></span></div></div><br><br clear="all"><br>-- <br><span class="sg">Sbaush

</span><br clear="all"><br>-- <br>Sbaush