Java regular expression to remove empty xml nodes and childrens completely

I am struggling to find the best solution. Below is my XML :

                    <Nm>John doe</Nm>

This is should replaced like this below :

                    <Nm>John doe</Nm>

So all the empty nodes and children without any values should be left out.
I am using following expression and it don’t work as per my wishes

docStr = docStr.replaceAll("<(w+)></1>|<w+/>", ""); 

Any help would be really appreciated.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.