blob: 2efbcb7e13d030c14d4ec250734fca5e6b41baa1 [file] [log] [blame]
Daniel Veillard01791d51998-07-24 19:24:09 +00001/*
2 * tester.c : a small tester program for XML input.
3 *
4 * See Copyright for the status of this software.
5 *
6 * $Id$
7 */
8
Daniel Veillard260a68f1998-08-13 03:39:55 +00009#ifdef WIN32
10#define HAVE_FCNTL_H
11#include <io.h>
12#else
13#include <config.h>
14#endif
Daniel Veillard01791d51998-07-24 19:24:09 +000015#include <sys/types.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000016#ifdef HAVE_SYS_STAT_H
Daniel Veillard01791d51998-07-24 19:24:09 +000017#include <sys/stat.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000018#endif
19#ifdef HAVE_FCNTL_H
Daniel Veillard01791d51998-07-24 19:24:09 +000020#include <fcntl.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000021#endif
22#ifdef HAVE_UNISTD_H
Daniel Veillard01791d51998-07-24 19:24:09 +000023#include <unistd.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000024#endif
Daniel Veillard01791d51998-07-24 19:24:09 +000025#include <stdio.h>
26#include <string.h>
Seth Alvese7f12e61998-10-01 20:51:15 +000027#include <stdlib.h>
Daniel Veillard01791d51998-07-24 19:24:09 +000028
Daniel Veillard260a68f1998-08-13 03:39:55 +000029#include "parser.h"
30#include "tree.h"
Daniel Veillard01791d51998-07-24 19:24:09 +000031
Daniel Veillard260a68f1998-08-13 03:39:55 +000032/*
33 * Note: there is a couple of errors introduced on purpose.
34 */
35static CHAR buffer[] =
Daniel Veillard01791d51998-07-24 19:24:09 +000036"\n\
37<?xml version=\"1.0\">\n\
38<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
39<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
40<D:propertyupdate>\n\
41<D:set a=\"'toto'\" b>\n\
42 <D:prop>\n\
43 <Z:authors>\n\
44 <Z:Author>Jim Whitehead</Z:Author>\n\
45 <Z:Author>Roy Fielding</Z:Author>\n\
46 </Z:authors>\n\
47 </D:prop>\n\
48 </D:set>\n\
49 <D:remove>\n\
50 <D:prop><Z:Copyright-Owner/></D:prop>\n\
51 </D:remove>\n\
52</D:propertyupdate>\n\
53\n\
54";
55
Daniel Veillard01791d51998-07-24 19:24:09 +000056
Daniel Veillard260a68f1998-08-13 03:39:55 +000057void parseAndPrintFile(char *filename) {
Daniel Veillard01791d51998-07-24 19:24:09 +000058 xmlDocPtr doc;
59
60 /*
Daniel Veillard260a68f1998-08-13 03:39:55 +000061 * build an XML tree from a string;
62 */
63 doc = xmlParseFile(filename);
64
65 /*
66 * print it.
67 */
68 xmlDocDump(stdout, doc);
69
70 /*
71 * free it.
72 */
73 xmlFreeDoc(doc);
74}
75
76void parseAndPrintBuffer(CHAR *buf) {
77 xmlDocPtr doc;
78
79 /*
80 * build an XML tree from a string;
Daniel Veillard01791d51998-07-24 19:24:09 +000081 */
82 doc = xmlParseDoc(buf);
83
84 /*
85 * print it.
86 */
87 xmlDocDump(stdout, doc);
88
89 /*
90 * free it.
91 */
92 xmlFreeDoc(doc);
93}
94
95int main(int argc, char **argv) {
96 int i;
97
98 if (argc > 1) {
99 for (i = 1; i < argc ; i++) {
Daniel Veillard260a68f1998-08-13 03:39:55 +0000100 parseAndPrintFile(argv[i]);
Daniel Veillard01791d51998-07-24 19:24:09 +0000101 }
102 } else
Daniel Veillard260a68f1998-08-13 03:39:55 +0000103 parseAndPrintBuffer(buffer);
Daniel Veillard01791d51998-07-24 19:24:09 +0000104
105 return(0);
106}