[XML-SIG] Re: inserting nodes
Fredrik Lundh
fredrik at pythonware.com
Wed Mar 30 16:05:51 CEST 2005
Necati DEMiR wrote:
> I wanna ask a question about inserting childs.
> How can i insert a child?
what toolkit are you using?
> For example, i have a xml file as the following;
>
> <?xml version="1.0" encoding="UTF-8" >
> <results>
> <result>
> <node1>test1</node1>
> <node2>tes2</node2>
> </result>
> </results>
>
> And i want the output as the following after inserting nodes
>
> <?xml version="1.0" encoding="UTF-8" >
> <results>
> <result>
> <node1>test1</node1>
> <node2>tes2</node2>
> </result>
> <result>
> <node1>qwe</node1>
> <node2>rty</node2>
> </result>
>
> </results>
ElementTree version:
from elementtree import ElementTree as ET
doc = ET.parse("mydoc.xml")
results = doc.getroot()
result = ET.SubElement(results, "result")
ET.SubElement(result, "node1").text = "qwe"
ET.SubElement(result, "node2").text = "rty"
</F>
More information about the XML-SIG
mailing list