To remove a particular element from the xml-string using lxml Python 3.5
<p>I have the below xml as an input to a function of python. I want to find a particular element which has Null value((firstChild.nodeValue)) and totally delete that from the xml and return the string. I have a contingency of using only the lxml module. Can I get help with this.  </p>

<pre><code>&lt;country name="Liechtenstein"&gt;
    &lt;rank&gt;&lt;/rank&gt;
    &lt;a&gt;&lt;/a&gt;
    &lt;b&gt;&lt;/b&gt;
    &lt;year&gt;2008&lt;/year&gt;
    &lt;gdppc&gt;141100&lt;/gdppc&gt;
    &lt;neighbor name="Austria" direction="E"&gt;345&lt;/neighbor&gt;
&lt;/country&gt;
</code></pre>

<p>I want the output to be:-</p>

<pre><code>&lt;country name="Liechtenstein"&gt;
    &lt;year&gt;2008&lt;/year&gt;
    &lt;gdppc&gt;141100&lt;/gdppc&gt;
    &lt;neighbor name="Austria" direction="E"&gt;345&lt;/neighbor&gt;
&lt;/country&gt;
</code></pre>

<p>I basically have the flexibility with a constant list containing tag names where I can iterate and find the text.Below is the list.
a= ('rank','year','a','b','gdppc','neighbor')</p>

<p>Please help !</p>

<p>The below code worked :)</p>

<pre><code>def remove_empty_elements(self,xml_input):
    tree = etree.fromstring(xml_input)
    for found in tree.xpath("//*[text()=' ']"):
        print("deleted " + str(found))
        found.getparent().remove(found)
    print(etree.tostring(tree).decode("utf-8"))
</code></pre>

python xml lxml python-3.5