hi, i've tested the matthew way, and it work perfectly.
Is possible to have the XML in a string (for example xmlstring) and for printing do a
print xmlstring ?

The Matthew way is

import sys
import elementtree.ElementTree as ET

root = ET.Element("manager")
req=ET.SubElement(root,"request")
app=ET.SubElement(req,"append")
app.set("mode","INPUT")
met=ET.SubElement(app,"method")
met.set("type","GOOD")
src="">
src.set("address","127.0.0.1 ")
act=ET.SubElement(app,"action")
act.set("option","OK")

tree = ET.ElementTree(root)
tree.write(sys.stdout)
print

$ python et.py
<manager><request><append mode="INPUT"><method type="GOOD" /><source
address=" 127.0.0.1" /><action option="OK"
/></append></request></manager>


2006/1/19, Matthew Dixon Cowles < [EMAIL PROTECTED]>:
Dear Sbaush,

> Hi all.
> I've this XML:
>
> <manager>
>     <request>
>         <append mode="INPUT">
>             <method type="GOOD"/>
>             <source address=" 127.0.0.1"/>
>             <action option="OK"/>
>         </append>
>     </request>
> </manager>
>
> How can i write this in a Python String? I would like use a
> xml.domimplementation and not a banal print...print...

Using Fredrik Lundh's ElementTree from:

http://effbot.org/zone/element-index.htm

you could do something like:

import sys
import elementtree.ElementTree as ET

root = ET.Element("manager")
req=ET.SubElement(root,"request")
app=ET.SubElement(req,"append")
app.set("mode","INPUT")
met=ET.SubElement(app,"method")
met.set("type","GOOD")
src="">src.set("address"," 127.0.0.1")
act=ET.SubElement(app,"action")
act.set("option","OK")

tree = ET.ElementTree(root)
tree.write(sys.stdout)
print

$ python et.py
<manager><request><append mode="INPUT"><method type="GOOD" /><source
address=" 127.0.0.1" /><action option="OK"
/></append></request></manager>

Regards,
Matt




--
Sbaush

--
Sbaush
_______________________________________________
XML-SIG maillist  -  XML-SIG@python.org
http://mail.python.org/mailman/listinfo/xml-sig

Reply via email to