I need to modify an xml file in python; specifically I need to add a new entry under the video tag. For instance, having something like this
<sources>
<programs>
<default pathversion="1"></default>
</programs>
<video>
<default pathversion="1"></default>
<source>
<name>Dir 1</name>
<path pathversion="1">/path/to/dir1/</path>
<allowsharing>true</allowsharing>
</source>
<source>
<name>Dir 2</name>
<path pathversion="1">/path/to/dir2/</path>
<allowsharing>true</allowsharing>
</source>
</video>
<music>
<default pathversion="1"></default>
</music>
<pictures>
<default pathversion="1"></default>
</pictures>
</sources>
I need to create a new entry under <video>...</video> as follows:
<source>
<name>Dir 3</name>
<path pathversion="1">/path/to/dir3/</path>
<allowsharing>true</allowsharing>
</source>
and update the original xml file. What would be the best practice to do so?
</video>with your new markup plus</video>xml.etree.ElementTreeas well though. Thanks for your comment!