I need to remove cases like this:
<text> </text>
I have codes that works when there is no whitespace, but what about if there is whitespace?
Code:
doc = etree.XML("""<root><a>1</a><b><c></c></b><d></d></root>""")
def remove_empty_elements(doc):
for element in doc.xpath('//*[not(node())]'):
element.getparent().remove(element)
I also need to do it with lxml and not BeautifulSoup.