I'm using ElementTree
to modify the following xml:
<li>
<p>Some stuff goes in <b>bold</b> here </p>
</li>
I would like to remove all <p>
from my <li>
elements but keep the contents.
Like this:
<li>Some stuff goes in <b>bold</b> here</li>
I am currently using the following code, which works in simple cases (no text/tail, etc....):
# strip <p> from <li> elements
liElements = rootNode.findall('.//li')
for elem in liElements:
para = elem.find(".//p")
for child in para:
elem.append(child)
elem.text = para.text
elem.remove(para)
There must an easier way to just strip a formatting tag.... I hope?