Is there any way to print empty elements like <tag></tag> rather than <tag /> using org.w3c.dom? I’m modifying XML files that need to be diff’ed against old versions of themselves for review.
If it helps, the code that writes the XML to the file:
TransformerFactory t = TransformerFactory.newInstance();
Transformer transformer = t.newTransformer();
DOMSource source = new DOMSource(doc);
StringWriter xml = new StringWriter();
StreamResult result = new StreamResult(xml);
transformer.transform(source, result);
File f = new File("output.xml");
FileWriter writer = new FileWriter(f);
BufferedWriter out = new BufferedWriter(writer);
out.write(xml.toString());
out.close();
Thanks.
You may want to consider converting both the old and the new XML file to Canonical XML – http://en.wikipedia.org/wiki/Canonical_XML – before comparing them with e.g. diff.
James Clark has a small Java program to do so on http://www.jclark.com/xml/