I need to create a checksum for an XML file in Java. The basic requirements are:
Anyone can provide any hint or sample code?
Thanks, Mark
You can make use of the Java Digital XML Signature APIs:
Introduction to the Java Digital XML Signature APIs
Essentially you would use XSLT to normalize XML documents so that equivalent documents distill down into the same document. The transformation would:
You would then checksum the normalized version of the document.
Some useful references:
normalize-space() - how to get the normalize-space() xpath function to work? If you don't like the intermediate step of producing a normalized document or DOM tree, you could use SAX or StAX to parse the XML to maintain/order/strip like above on the fly and feed each element/content/attribute/value/etc to a checksum calculator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With