Java XML

From sheep
Revision as of 21:02, 14 September 2021 by Martin (talk | contribs) (Created page with "= Canonical xml = When you want to compare xml or check signatures after manipulating xml - note namespaces and prefixes... Canonical class bundled with Java 6 or available f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Canonical xml

When you want to compare xml or check signatures after manipulating xml - note namespaces and prefixes...

Canonical class bundled with Java 6 or available from xml-security http://santuario.apache.org/

Essential you use init or you get an exception: "com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException: Unknown canonicalizer. No handler installed for URI http://www.w3.org/TR/2001/REC-xml-c14n-20010315"

import com.sun.org.apache.xml.internal.security.Init;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;

Init.init();
Canonicalizer c = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
byte[] bres = c.canonicalize(xmlString.getBytes());