Am working with xml file (making its validation). I need to edit some attributes before calculating CRC32 function of entire file. I using DOM parser and xPath. After I have edited my file, am converting it to byte array for crc- function:
Node file_crc = (Node) xPath.compile("/IODevice/Stamp/@crc").evaluate(doc, XPathConstants.NODE);
file_crc.setTextContent("");
bos = new ByteArrayOutputStream();
result = new StreamResult(bos);
try {
transformer.transform(new DOMSource(doc), result);
crc.reset();
crc.update(bos.toByteArray());
} catch (TransformerException ex) {
return false;
}
The trouble is that DOM parser changes attributes order in xml file (sorts them alphabeticaly) - this cause invalid checksum of file. How to avoid attributes order mutation?