Forum Discussion

sunrays123's avatar
sunrays123
Occasional Contributor
6 years ago

How to add a node under the child element in XML

 

-<test-results total="13" time="0:16:30:27" date="5/22/2018">


-<test-suite total="13" not-run="0" name="TestCase">


-<results>


-<test-suite total="13" not-run="0" name="">

<results/>

</test-suite>

</results>

</test-suite>


-<statistic>

<stat name="tests" value="0"/>

<stat name="failures" value="0"/>

<stat name="errors" value="0"/>

</statistic>

</test-results>

 Hi, I want to add a node under the second <results/> element. I tried with following line of code but it is adding the new node under each "result" element.

 for result in root.iter("result"):

    ET.SubElement(result, 'Name').text = 'Hello'

 

Can anyone suggest the solution in Python?

 

No RepliesBe the first to reply