PYTHON 2.7 Close and open up an xml element

I have an xml file and I want to open and also close an element in the file.

<my_element>
    <blablabla href="docs/MyBlank.htm" />
</my_element>

this one I would like to close like this:

<!--
<my_element>
    <blablabla href="docs/MyBlank.htm" />
</my_element>
-->

Furter down in the file I have an element with the same name which is “closed” like this:

<!--
<my_element>
    <blablabla href="secretwebhacking/MySecrectBankLogin.htm" />
</my_element>
-->

and I want to “open” it up like:

<my_element>
     <blablabla href="secretwebhacking/MySecrectBankLogin.htm" />
</my_element>

I use ElementTree for this, I know how to edit the value and the attribute in the element, but I am not at all sure how to remove and add the < !-- --> around one specific element.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s