2
* Copyright 2002-2005 The Apache Software Foundation.
2
* Copyright 2002-2009 The Apache Software Foundation.
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
57
57
void printUsage(void) {
59
cerr << "\nUsage: c14n [-n] <input file name>\n";
60
cerr << " -n = No comments\n\n";
59
cerr << "\nUsage: c14n [-n] [-x] [-1.1] [-id ID] <input file name>\n";
60
cerr << " -n = No comments\n";
61
cerr << " -1.1 = Use c14n 1.1\n";
62
cerr << " -x = Use exclusive c14n\n";
63
cerr << " -id ID = References node to canonicalize by ID\n\n";
64
67
int main(int argc, char **argv) {
66
bool printComments = true; // By default print comments
69
const char* id = NULL;
70
bool printComments = true;
71
bool exclusive = false;
72
bool inclusive11 = false;
78
82
for (int i = 1; i < argc - 1; ++i) {
80
84
if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "-N"))
81
85
printComments = false;
86
else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "-X"))
88
else if (!strcmp(argv[i], "-1.1"))
90
else if (!strcmp(argv[i], "-id") && argc > i + 1)
83
93
cerr << "Unknown option %s\n\n";
110
120
XercesDOMParser * parser = new XercesDOMParser;
111
121
parser->setDoNamespaces(true);
112
parser->setValidationScheme(XercesDOMParser::Val_Never);
122
parser->setValidationScheme(XercesDOMParser::Val_Never);
113
123
parser->setDoSchema(false);
114
124
parser->setCreateEntityReferenceNodes(false);
116
126
// Now parse out file
118
128
bool errorsOccured = false;
129
xsecsize_t errorCount = 0;
122
132
parser->parse(argv[argc-1]);
156
DOMNode *doc; // The document that we parsed
158
doc = parser->getDocument();
166
DOMNode *subtree = NULL;
159
167
DOMDocument *theDOM = parser->getDocument();
161
// Creat the canonicalizer
163
XSECC14n20010315 canon(theDOM);
164
canon.setCommentsProcessing(printComments);
165
canon.setUseNamespaceStack(true);
167
// canon.XPathSelectNodes("(/descendant-or-self::node() | /descendant-or-self::node()/attribute::* | /descendant-or-self::node()/namespace::*)[ self::ietf:e1 or (parent::ietf:e1 and not(self::text() or self::e2)) or count (id(\"E3\") | ancestor-or-self::node()) = count (ancestor-or-self::node())]");
169
XMLCh* temp = XMLString::transcode(id);
170
subtree = theDOM->getElementById(temp);
171
XMLString::release(&temp);
173
cerr << "ID reference did not resolve" << endl;
178
// Create the canonicalizer
179
XSECC14n20010315* canon=NULL;
181
canon = new XSECC14n20010315(theDOM, subtree);
183
canon = new XSECC14n20010315(theDOM);
184
canon->setCommentsProcessing(printComments);
185
canon->setUseNamespaceStack(true);
187
canon->setInclusive11();
189
canon->setExclusive();
191
// canon->XPathSelectNodes("(/descendant-or-self::node() | /descendant-or-self::node()/attribute::* | /descendant-or-self::node()/namespace::*)[ self::ietf:e1 or (parent::ietf:e1 and not(self::text() or self::e2)) or count (id(\"E3\") | ancestor-or-self::node()) = count (ancestor-or-self::node())]");
169
193
char buffer[512];
170
int res = canon.outputBuffer((unsigned char *) buffer, 128);
194
xsecsize_t res = canon->outputBuffer((unsigned char *) buffer, 128);
173
197
while (res != 0) {
174
198
buffer[res] = '\0';
176
res = canon.outputBuffer((unsigned char *) buffer, 128);
200
res = canon->outputBuffer((unsigned char *) buffer, 128);
208
XSECPlatformUtils::Terminate();
209
XMLPlatformUtils::Terminate();