<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("manager")
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">req=ET.SubElement(root,"request")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
app=ET.SubElement(req,"append")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">app.set("mode","INPUT")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">met=ET.SubElement(app,"method")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">met.set("type","GOOD")
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">src=ET.SubElement(app,"source")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
src.set("address","</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;">
")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">act=ET.SubElement(app,"action")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
act.set("option","OK")</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;"><manager><request><append mode="INPUT"><method type="GOOD" /><source<br>address="<a href="http://127.0.0.1/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
127.0.0.1</a>" /><action option="OK"<br>/></append></request></manager><br></span><br><br></span><div><span class="gmail_quote">2006/1/19, Matthew Dixon Cowles <<a href="mailto:matt@mondoinfo.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
matt@mondoinfo.com</a>>:</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>> Hi all.<br>> I've this XML:<br>
><br>> <manager><br>> <request><br>> <append mode="INPUT"><br>> <method type="GOOD"/><br>> <source address=" <a href="http://127.0.0.1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
127.0.0.1</a>"/><br>> <action option="OK"/><br>> </append><br>> </request><br>> </manager><br>><br>> How can i write this in a Python String? I would like use a
<br>> 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("manager")<br>req=ET.SubElement(root,"request")<br>app=ET.SubElement(req,"append")
<br>app.set("mode","INPUT")<br>met=ET.SubElement(app,"method")<br>met.set("type","GOOD")<br>src=ET.SubElement(app,"source")<br>src.set("address","
<a href="http://127.0.0.1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">127.0.0.1</a>")<br>act=ET.SubElement(app,"action")<br>act.set("option","OK")<br><br>tree =
ET.ElementTree(root)<br>tree.write(sys.stdout)<br>print<br><br>$ python
et.py<br><manager><request><append mode="INPUT"><method type="GOOD" /><source<br>address="<a href="http://127.0.0.1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
127.0.0.1</a>" /><action option="OK"
<br>/></append></request></manager><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