Tag
Hash :
14fff064
Author :
Date :
1999-06-22T21:49:07
Big changes, seems that 1.2.0 wasn't commited, here is 1.3.0, Daniel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
/*
* tester.c : a small tester program for XML input.
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@w3.org
*/
#ifdef WIN32
#define HAVE_FCNTL_H
#include <io.h>
#else
#include <config.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "parser.h"
#include "tree.h"
#include "debugXML.h"
static int debug = 0;
static int copy = 0;
static int recovery = 0;
static int noent = 0;
/*
* Note: there is a couple of errors introduced on purpose.
*/
static CHAR buffer[] =
"<?xml version=\"1.0\"?>\n\
<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
<D:propertyupdate>\n\
<D:set a=\"'toto'\" b>\n\
<D:prop>\n\
<Z:authors>\n\
<Z:Author>Jim Whitehead</Z:Author>\n\
<Z:Author>Roy Fielding</Z:Author>\n\
</Z:authors>\n\
</D:prop>\n\
</D:set>\n\
<D:remove>\n\
<D:prop><Z:Copyright-Owner/></D:prop>\n\
</D:remove>\n\
</D:propertyupdate>\n\
\n\
";
/************************************************************************
* *
* Debug *
* *
************************************************************************/
int treeTest(void) {
xmlDocPtr doc, tmp;
xmlNodePtr tree, subtree;
/*
* build a fake XML document
*/
doc = xmlNewDoc("1.0");
doc->root = xmlNewDocNode(doc, NULL, "EXAMPLE", NULL);
xmlSetProp(doc->root, "prop1", "gnome is great");
xmlSetProp(doc->root, "prop2", "&linux; too");
xmlSetProp(doc->root, "emptyprop", "");
tree = xmlNewChild(doc->root, NULL, "head", NULL);
subtree = xmlNewChild(tree, NULL, "title", "Welcome to Gnome");
tree = xmlNewChild(doc->root, NULL, "chapter", NULL);
subtree = xmlNewChild(tree, NULL, "title", "The Linux adventure");
subtree = xmlNewChild(tree, NULL, "p", "bla bla bla ...");
subtree = xmlNewChild(tree, NULL, "image", NULL);
xmlSetProp(subtree, "href", "linus.gif");
/*
* test intermediate copy if needed.
*/
if (copy) {
tmp = doc;
doc = xmlCopyDoc(doc, 1);
xmlFreeDoc(tmp);
}
/*
* print it.
*/
xmlDocDump(stdout, doc);
/*
* free it.
*/
xmlFreeDoc(doc);
return(0);
}
void parseAndPrintFile(char *filename) {
xmlDocPtr doc, tmp;
/*
* build an XML tree from a string;
*/
if (recovery)
doc = xmlRecoverFile(filename);
else
doc = xmlParseFile(filename);
/*
* test intermediate copy if needed.
*/
if (copy) {
tmp = doc;
doc = xmlCopyDoc(doc, 1);
xmlFreeDoc(tmp);
}
/*
* print it.
*/
if (!debug)
xmlDocDump(stdout, doc);
else
xmlDebugDumpDocument(stdout, doc);
/*
* free it.
*/
xmlFreeDoc(doc);
}
void parseAndPrintBuffer(CHAR *buf) {
xmlDocPtr doc, tmp;
/*
* build an XML tree from a string;
*/
if (recovery)
doc = xmlRecoverDoc(buf);
else
doc = xmlParseDoc(buf);
/*
* test intermediate copy if needed.
*/
if (copy) {
tmp = doc;
doc = xmlCopyDoc(doc, 1);
xmlFreeDoc(tmp);
}
/*
* print it.
*/
if (!debug)
xmlDocDump(stdout, doc);
else
xmlDebugDumpDocument(stdout, doc);
/*
* free it.
*/
xmlFreeDoc(doc);
}
int main(int argc, char **argv) {
int i;
int files = 0;
for (i = 1; i < argc ; i++) {
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
debug++;
else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
copy++;
else if ((!strcmp(argv[i], "-recover")) ||
(!strcmp(argv[i], "--recover")))
recovery++;
else if ((!strcmp(argv[i], "-noent")) ||
(!strcmp(argv[i], "--noent")))
noent++;
}
if (noent != 0) xmlSubstituteEntitiesDefault(1);
for (i = 1; i < argc ; i++) {
if (argv[i][0] != '-') {
parseAndPrintFile(argv[i]);
files ++;
}
}
if (files == 0) {
printf("Usage : %s [--debug] [--copy] [--recover] [--noent] XMLfiles ...\n",
argv[0]);
printf("\tParse the XML files and output the result of the parsing\n");
printf("\t--debug : dump a debug tree of the in-memory document\n");
printf("\t--copy : used to test the internal copy implementation\n");
printf("\t--recover : output what is parsable on broken XmL documents\n");
printf("\t--noent : substitute entity references by their value\n");
}
return(0);
}