I'm working with javax.xml
& After removing some node:
docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilder = docBuilderFactory.newDocumentBuilder();
document = docBuilder.parse(new File("file_name"));
NodeList tagList = document.getElementsByTagName("tag_name");
tagList.item(0).getParentNode().removeChild(waysList.item(0));
Instead of the removed tag, I have an empty line.
How can avoid this or remove the empty line?
XML file is:
<root>
<tag_name>text</tag_name>
<tag_name>text</tag_name>
<tag_name>text</tag_name>
</root>
EDIT:
If I add tagList.item(0).getParentNode().setTextContent("");
before or after the removeChild
I get a NullPointerException.
Thanks,
Indent before the element and the Carriage return after it are text nodes. If you remove an element and there's a text node before or after it, you will see it as whitespace lines.