blob: 030ee1cc4675e036cd5431be5a8e6a02e4357eff [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
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13#include <stdio.h>
14#include <string.h>
15#include <malloc.h>
16
17#include "xml_parser.h"
18#include "xml_tree.h"
19
20#define MAX_BUF 500000
21
22static CHAR buffer[MAX_BUF] =
23"\n\
24<?xml version=\"1.0\">\n\
25<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
26<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
27<D:propertyupdate>\n\
28<D:set a=\"'toto'\" b>\n\
29 <D:prop>\n\
30 <Z:authors>\n\
31 <Z:Author>Jim Whitehead</Z:Author>\n\
32 <Z:Author>Roy Fielding</Z:Author>\n\
33 </Z:authors>\n\
34 </D:prop>\n\
35 </D:set>\n\
36 <D:remove>\n\
37 <D:prop><Z:Copyright-Owner/></D:prop>\n\
38 </D:remove>\n\
39</D:propertyupdate>\n\
40\n\
41";
42
43int readFile(char *filename) {
44 int input;
45 int res;
46
47 memset(buffer, 0, sizeof(buffer));
48 input = open (filename, O_RDONLY);
49 if (input < 0) {
50 fprintf (stderr, "Cannot read file %s :\n", filename);
51 perror ("open failed");
52 return(-1);
53 }
54 res = read(input, buffer, sizeof(buffer));
55 if (res < 0) {
56 fprintf (stderr, "Cannot read file %s :\n", filename);
57 perror ("read failed");
58 return(-1);
59 }
60 if (res >= MAX_BUF) {
61 fprintf (stderr, "Read only %d byte of %s, increase MAX_BUF\n",
62 res, filename);
63 return(-1);
64 }
65 close(input);
66 return(res);
67}
68
69void parseAndPrint(CHAR *buf) {
70 xmlDocPtr doc;
71
72 /*
73 * build a fake XML document from a string;
74 */
75 doc = xmlParseDoc(buf);
76
77 /*
78 * print it.
79 */
80 xmlDocDump(stdout, doc);
81
82 /*
83 * free it.
84 */
85 xmlFreeDoc(doc);
86}
87
88int main(int argc, char **argv) {
89 int i;
90
91 if (argc > 1) {
92 for (i = 1; i < argc ; i++) {
93 if (readFile(argv[i]) >= 0) {
94 printf("\n\n------- %s -----------\n", argv[i]);
95 parseAndPrint(buffer);
96 }
97 }
98 } else
99 parseAndPrint(buffer);
100
101 return(0);
102}