Howto create this XML string?

Sbaush <[email protected]>
Newsgroups gmane.comp.python.xml
Message-ID <[email protected]>
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=ET.SubElement(app,"source")
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=ET.SubElement(app,"source")
> 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  -  [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.