I need to update several nodes in an XML file (just substitute one text element for the other) in such way that resulting XML file will keep all its formatting (where possible).
For example, the following is the source document:
<project>
<!-- Some long comment -->
<!-- On several lines -->
<name>Name</name> <!-- And here too -->
<version>1.2.3</version>
</project>
and this is the required result document (note that the version has changed):
<project>
<!-- Some long comment -->
<!-- On several lines -->
<name>Name</name> <!-- And here too -->
<version>3.2.1</version>
</project>
So the result keeps all the formatting from source, and only version tag content has changed.
Unfortunately, I couldn't find a way to do this with standard Clojure (or Java) libraries. Sure, they do support basic indentation of string representation of XML, but it is not sufficient for me.
Is there a way to do this with some XML manipulation library (preferably in Clojure, but I guess Java is fine too), or I have to fall back to plain text/regexp substitutions? (really, I don't want XML tags leaking from my eyes, this should the last resort...)