My code is too slow, but I'm not sure how to improve it. Reading from disk into DOM for a 1k-file takes about 20 ms, that might be okay depending on ...
Removing the whitespace is the wrong approach. Instead you should realize that the creators of that XML can put in whitespace wherever they feel like it, and more importantly, that the whitespace is also part of the document. In particular it forms text nodes which are children of the element in which they are located, just as element nodes are children. ...