I have a Problem that when I'm removing a child-node from an xml there will be an empty line in the xml. The node is removed correctly but i don't want an empty line, and I have no idea where that empty line comes from as I'm not writing the xml, but Javas Transformer is doing it for me:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t;
DocumentBuilder db;
db = dbf.newDocumentBuilder();
Document doc = db.parse(myXml);
//get the node I want to remove
Node n = getMyNodeToRemove(doc);
n.getParentNode().removeChild(n);
//write the xml
t = tf.newTransformer();
DOMSource src = new DOMSource(doc);
StreamResult result = new StreamResult(xml);
t.transform(src, result);
The xml i want to edit is in fact very simple and looks like this:
<parent>
<childnode 1>
<childnode i want to remove>
<childnode 2>
<childnode 3>
</parent>
after removing the child it looks like this:
<parent>
<childnode 1>
<childnode 2>
<childnode 3>
</parent>
But what I want is this:
<parent>
<childnode 1>
<childnode 2>
<childnode 3>
</parent>
Is there some function to call on the parent-node i'm missing ? or is there a explicit pretty-print function for xmls ?