Unformatted XML is a problem in our build. I would like to include style checking for XML documents, primarily looking for poor indentation.
What is the best tool to use? (The build uses Ant).
Unformatted XML is a problem in our build. I would like to include style checking for XML documents, primarily looking for poor indentation.
What is the best tool to use? (The build uses Ant).
You can write a class that will automatically transform and therefore indent your XML. Then just specify in Ant on which XML files it should be ran.
Something to get you started:
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);
Check XCOP: http://www.yegor256.com/2017/08/29/xcop.html
This is how you integrate it with ant: