1
10import org.w3c.dom.Document;
11
12import com.verisign.c14n.*;
13import com.verisign.domutil.*;
14import com.verisign.xpath.*;
15
16public class Canonicalize {
17 private static String NORMAL_C14N = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
18 private static String NORMAL_C14NWC = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
19 private static String EXC_C14N = "http://www.w3.org/2001/10/xml-exc-c14n#";
20 private static String EXC_C14NWC = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
21 public static void main(String[] args) throws Exception {
22 String datafile = "../../../../data/book.xml";
24
25 Document doc = XmlUtility.readXML(datafile);
27 Canonicalizer c = CanonicalizerFactory.getInstance(NORMAL_C14N);
28 byte[] ba = c.canonicalize(doc);
29 System.out.println("Output of Normal Canonicalization:");
30 System.out.write(ba);
31 System.out.println();
32
33
34 Canonicalizer c1 = CanonicalizerFactory.getInstance(NORMAL_C14N);
35 DOMCursor dc1 = new DOMCursor(doc);
36 dc1.moveToXPath(new XPath("id('book_title')"));
37 byte[] ba1 = c1.canonicalize(dc1.getElement());
38 System.out.println("Output of Normal Canonicalization:");
39 System.out.write(ba1);
40 System.out.println();
41
42 Canonicalizer c2 = CanonicalizerFactory.getInstance(EXC_C14N);
43 DOMCursor dc2 = new DOMCursor(doc);
44 dc2.moveToXPath(new XPath("id('book_title')"));
45 byte[] ba2 = c2.canonicalize(dc2.getElement());
46 System.out.println("Output of Exclusive Canonicalization:");
47 System.out.write(ba2);
48 System.out.println();
49 }
50}