Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 1 | /* |
| 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 Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9 | #ifdef WIN32 |
| 10 | #define HAVE_FCNTL_H |
| 11 | #include <io.h> |
| 12 | #else |
| 13 | #include <config.h> |
| 14 | #endif |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 15 | #include <sys/types.h> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 16 | #ifdef HAVE_SYS_STAT_H |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 17 | #include <sys/stat.h> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 18 | #endif |
| 19 | #ifdef HAVE_FCNTL_H |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 20 | #include <fcntl.h> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 21 | #endif |
| 22 | #ifdef HAVE_UNISTD_H |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 23 | #include <unistd.h> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 24 | #endif |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <string.h> |
Seth Alves | e7f12e6 | 1998-10-01 20:51:15 +0000 | [diff] [blame] | 27 | #include <stdlib.h> |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 28 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 29 | #include "parser.h" |
| 30 | #include "tree.h" |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame^] | 31 | #include "debugXML.h" |
| 32 | |
| 33 | static int debug = 0; |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 34 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 35 | /* |
| 36 | * Note: there is a couple of errors introduced on purpose. |
| 37 | */ |
| 38 | static CHAR buffer[] = |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 39 | "\n\ |
| 40 | <?xml version=\"1.0\">\n\ |
| 41 | <?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\ |
| 42 | <?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\ |
| 43 | <D:propertyupdate>\n\ |
| 44 | <D:set a=\"'toto'\" b>\n\ |
| 45 | <D:prop>\n\ |
| 46 | <Z:authors>\n\ |
| 47 | <Z:Author>Jim Whitehead</Z:Author>\n\ |
| 48 | <Z:Author>Roy Fielding</Z:Author>\n\ |
| 49 | </Z:authors>\n\ |
| 50 | </D:prop>\n\ |
| 51 | </D:set>\n\ |
| 52 | <D:remove>\n\ |
| 53 | <D:prop><Z:Copyright-Owner/></D:prop>\n\ |
| 54 | </D:remove>\n\ |
| 55 | </D:propertyupdate>\n\ |
| 56 | \n\ |
| 57 | "; |
| 58 | |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 59 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 60 | void parseAndPrintFile(char *filename) { |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 61 | xmlDocPtr doc; |
| 62 | |
| 63 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 64 | * build an XML tree from a string; |
| 65 | */ |
| 66 | doc = xmlParseFile(filename); |
| 67 | |
| 68 | /* |
| 69 | * print it. |
| 70 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame^] | 71 | if (!debug) |
| 72 | xmlDocDump(stdout, doc); |
| 73 | else |
| 74 | xmlDebugDumpDocument(stdout, doc); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * free it. |
| 78 | */ |
| 79 | xmlFreeDoc(doc); |
| 80 | } |
| 81 | |
| 82 | void parseAndPrintBuffer(CHAR *buf) { |
| 83 | xmlDocPtr doc; |
| 84 | |
| 85 | /* |
| 86 | * build an XML tree from a string; |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 87 | */ |
| 88 | doc = xmlParseDoc(buf); |
| 89 | |
| 90 | /* |
| 91 | * print it. |
| 92 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame^] | 93 | if (!debug) |
| 94 | xmlDocDump(stdout, doc); |
| 95 | else |
| 96 | xmlDebugDumpDocument(stdout, doc); |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * free it. |
| 100 | */ |
| 101 | xmlFreeDoc(doc); |
| 102 | } |
| 103 | |
| 104 | int main(int argc, char **argv) { |
| 105 | int i; |
| 106 | |
| 107 | if (argc > 1) { |
| 108 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame^] | 109 | if ((strcmp(argv[i], "-debug")) && (strcmp(argv[i], "--debug"))) |
| 110 | parseAndPrintFile(argv[i]); |
| 111 | else |
| 112 | debug++; |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 113 | } |
| 114 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 115 | parseAndPrintBuffer(buffer); |
Daniel Veillard | 01791d5 | 1998-07-24 19:24:09 +0000 | [diff] [blame] | 116 | |
| 117 | return(0); |
| 118 | } |