Vous pouvez écrire une classe qui transformera automatiquement et indentera votre XML. Ensuite, spécifiez simplement dans Ant sur quels fichiers XML il doit être exécuté.
Quelque chose pour vous lancer:
String filePath = "test.xml";
String outputFilePath = "testOut.xml";
File xmlFile = new File(filePath);
File outputXmlFile = new File(outputFilePath);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
StreamSource ss = new StreamSource(xmlFile);
StreamResult sr = new StreamResult(outputXmlFile);
transformer.transform(ss, sr);
Merci +1 - cependant, je veux vérifier le formatage, plutôt que de reformater. Certes, je pourrais utiliser la même approche (écrire quelque chose pour vérifier diff formaté == original), mais je cherchais quelque chose qui existe déjà - comme une méthode d'utilisation de checkstyle pour xml ou quelque chose. – Synesso