2 * xmllint.c : a small tester program for XML input.
4 * See Copyright for the status of this software.
15 #if defined (_WIN32) && !defined(__CYGWIN__)
16 #if defined (_MSC_VER) || defined(__BORLANDC__)
18 #pragma comment(lib, "ws2_32.lib")
19 #define gettimeofday(p1,p2)
23 #ifdef HAVE_SYS_TIME_H
32 #include <wsockcompat.h>
35 #define XML_SOCKLEN_T unsigned int
38 #ifdef HAVE_SYS_TIMEB_H
39 #include <sys/timeb.h>
42 #ifdef HAVE_SYS_TYPES_H
43 #include <sys/types.h>
45 #ifdef HAVE_SYS_STAT_H
54 #ifdef HAVE_SYS_MMAN_H
56 /* seems needed for Solaris */
58 #define MAP_FAILED ((void *) -1)
64 #ifdef HAVE_LIBREADLINE
65 #include <readline/readline.h>
66 #ifdef HAVE_LIBHISTORY
67 #include <readline/history.h>
71 #include <libxml/xmlmemory.h>
72 #include <libxml/parser.h>
73 #include <libxml/parserInternals.h>
74 #include <libxml/HTMLparser.h>
75 #include <libxml/HTMLtree.h>
76 #include <libxml/tree.h>
77 #include <libxml/xpath.h>
78 #include <libxml/debugXML.h>
79 #include <libxml/xmlerror.h>
80 #ifdef LIBXML_XINCLUDE_ENABLED
81 #include <libxml/xinclude.h>
83 #ifdef LIBXML_CATALOG_ENABLED
84 #include <libxml/catalog.h>
86 #include <libxml/globals.h>
87 #include <libxml/xmlreader.h>
88 #ifdef LIBXML_SCHEMATRON_ENABLED
89 #include <libxml/schematron.h>
91 #ifdef LIBXML_SCHEMAS_ENABLED
92 #include <libxml/relaxng.h>
93 #include <libxml/xmlschemas.h>
95 #ifdef LIBXML_PATTERN_ENABLED
96 #include <libxml/pattern.h>
98 #ifdef LIBXML_C14N_ENABLED
99 #include <libxml/c14n.h>
101 #ifdef LIBXML_OUTPUT_ENABLED
102 #include <libxml/xmlsave.h>
105 #ifndef XML_XML_DEFAULT_CATALOG
106 #define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
110 XMLLINT_RETURN_OK = 0, /* No error */
111 XMLLINT_ERR_UNCLASS = 1, /* Unclassified */
112 XMLLINT_ERR_DTD = 2, /* Error in DTD */
113 XMLLINT_ERR_VALID = 3, /* Validation error */
114 XMLLINT_ERR_RDFILE = 4, /* CtxtReadFile error */
115 XMLLINT_ERR_SCHEMACOMP = 5, /* Schema compilation */
116 XMLLINT_ERR_OUT = 6, /* Error writing output */
117 XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */
118 XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */
119 XMLLINT_ERR_MEM = 9, /* Out of memory error */
120 XMLLINT_ERR_XPATH = 10 /* XPath evaluation error */
122 #ifdef LIBXML_DEBUG_ENABLED
123 static int shell = 0;
124 static int debugent = 0;
126 static int debug = 0;
127 static int maxmem = 0;
128 #ifdef LIBXML_TREE_ENABLED
130 #endif /* LIBXML_TREE_ENABLED */
131 static int recovery = 0;
132 static int noent = 0;
133 static int noblanks = 0;
134 static int noout = 0;
135 static int nowrap = 0;
136 #ifdef LIBXML_OUTPUT_ENABLED
137 static int format = 0;
138 static const char *output = NULL;
139 static int compress = 0;
140 static int oldout = 0;
141 #endif /* LIBXML_OUTPUT_ENABLED */
142 #ifdef LIBXML_VALID_ENABLED
143 static int valid = 0;
144 static int postvalid = 0;
145 static char * dtdvalid = NULL;
146 static char * dtdvalidfpi = NULL;
148 #ifdef LIBXML_SCHEMAS_ENABLED
149 static char * relaxng = NULL;
150 static xmlRelaxNGPtr relaxngschemas = NULL;
151 static char * schema = NULL;
152 static xmlSchemaPtr wxschemas = NULL;
154 #ifdef LIBXML_SCHEMATRON_ENABLED
155 static char * schematron = NULL;
156 static xmlSchematronPtr wxschematron = NULL;
158 static int repeat = 0;
159 static int insert = 0;
160 #if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
162 static int xmlout = 0;
164 static int htmlout = 0;
165 #if defined(LIBXML_HTML_ENABLED)
166 static int nodefdtd = 0;
168 #ifdef LIBXML_PUSH_ENABLED
170 #endif /* LIBXML_PUSH_ENABLED */
171 #ifdef HAVE_SYS_MMAN_H
172 static int memory = 0;
174 static int testIO = 0;
175 static char *encoding = NULL;
176 #ifdef LIBXML_XINCLUDE_ENABLED
177 static int xinclude = 0;
179 static int dtdattrs = 0;
180 static int loaddtd = 0;
181 static xmllintReturnCode progresult = XMLLINT_RETURN_OK;
182 static int timing = 0;
183 static int generate = 0;
184 static int dropdtd = 0;
185 #ifdef LIBXML_CATALOG_ENABLED
186 static int catalogs = 0;
187 static int nocatalogs = 0;
189 #ifdef LIBXML_C14N_ENABLED
190 static int canonical = 0;
191 static int canonical_11 = 0;
192 static int exc_canonical = 0;
194 #ifdef LIBXML_READER_ENABLED
195 static int stream = 0;
196 static int walker = 0;
197 #endif /* LIBXML_READER_ENABLED */
198 static int chkregister = 0;
199 static int nbregister = 0;
200 #ifdef LIBXML_SAX1_ENABLED
202 #endif /* LIBXML_SAX1_ENABLED */
203 #ifdef LIBXML_PATTERN_ENABLED
204 static const char *pattern = NULL;
205 static xmlPatternPtr patternc = NULL;
206 static xmlStreamCtxtPtr patstream = NULL;
208 #ifdef LIBXML_XPATH_ENABLED
209 static const char *xpathquery = NULL;
211 static int options = XML_PARSE_COMPACT;
213 static int oldxml10 = 0;
215 /************************************************************************
217 * Entity loading control and customization. *
219 ************************************************************************/
222 # define PATH_SEPARATOR ';'
224 # define PATH_SEPARATOR ':'
226 static xmlChar *paths[MAX_PATHS + 1];
227 static int nbpaths = 0;
228 static int load_trace = 0;
231 void parsePath(const xmlChar *path) {
237 if (nbpaths >= MAX_PATHS) {
238 fprintf(stderr, "MAX_PATHS reached: too many paths\n");
242 while ((*cur == ' ') || (*cur == PATH_SEPARATOR))
245 while ((*cur != 0) && (*cur != ' ') && (*cur != PATH_SEPARATOR))
248 paths[nbpaths] = xmlStrndup(path, cur - path);
249 if (paths[nbpaths] != NULL)
256 static xmlExternalEntityLoader defaultEntityLoader = NULL;
258 static xmlParserInputPtr
259 xmllintExternalEntityLoader(const char *URL, const char *ID,
260 xmlParserCtxtPtr ctxt) {
261 xmlParserInputPtr ret;
262 warningSAXFunc warning = NULL;
263 errorSAXFunc err = NULL;
266 const char *lastsegment = URL;
267 const char *iter = URL;
269 if ((nbpaths > 0) && (iter != NULL)) {
272 lastsegment = iter + 1;
277 if ((ctxt != NULL) && (ctxt->sax != NULL)) {
278 warning = ctxt->sax->warning;
279 err = ctxt->sax->error;
280 ctxt->sax->warning = NULL;
281 ctxt->sax->error = NULL;
284 if (defaultEntityLoader != NULL) {
285 ret = defaultEntityLoader(URL, ID, ctxt);
288 ctxt->sax->warning = warning;
290 ctxt->sax->error = err;
294 "Loaded URL=\"%s\" ID=\"%s\"\n",
295 URL ? URL : "(null)",
301 for (i = 0;i < nbpaths;i++) {
304 newURL = xmlStrdup((const xmlChar *) paths[i]);
305 newURL = xmlStrcat(newURL, (const xmlChar *) "/");
306 newURL = xmlStrcat(newURL, (const xmlChar *) lastsegment);
307 if (newURL != NULL) {
308 ret = defaultEntityLoader((const char *)newURL, ID, ctxt);
311 ctxt->sax->warning = warning;
313 ctxt->sax->error = err;
317 "Loaded URL=\"%s\" ID=\"%s\"\n",
328 ctxt->sax->error = err;
329 if (warning != NULL) {
330 ctxt->sax->warning = warning;
332 warning(ctxt, "failed to load external entity \"%s\"\n", URL);
334 warning(ctxt, "failed to load external entity \"%s\"\n", ID);
338 /************************************************************************
340 * Memory allocation consumption debugging *
342 ************************************************************************/
347 fprintf(stderr, "Ran out of memory needs > %d bytes\n", maxmem);
348 progresult = XMLLINT_ERR_MEM;
352 myFreeFunc(void *mem)
357 myMallocFunc(size_t size)
361 ret = xmlMemMalloc(size);
363 if (xmlMemUsed() > maxmem) {
372 myReallocFunc(void *mem, size_t size)
376 ret = xmlMemRealloc(mem, size);
378 if (xmlMemUsed() > maxmem) {
387 myStrdupFunc(const char *str)
391 ret = xmlMemoryStrdup(str);
393 if (xmlMemUsed() > maxmem) {
401 /************************************************************************
403 * Internal timing routines to remove the necessity to have *
404 * unix-specific function calls. *
406 ************************************************************************/
408 #ifndef HAVE_GETTIMEOFDAY
409 #ifdef HAVE_SYS_TIMEB_H
410 #ifdef HAVE_SYS_TIME_H
414 my_gettimeofday(struct timeval *tvp, void *tzp)
416 struct timeb timebuffer;
420 tvp->tv_sec = timebuffer.time;
421 tvp->tv_usec = timebuffer.millitm * 1000L;
425 #define HAVE_GETTIMEOFDAY 1
426 #define gettimeofday my_gettimeofday
428 #endif /* HAVE_FTIME */
429 #endif /* HAVE_SYS_TIME_H */
430 #endif /* HAVE_SYS_TIMEB_H */
431 #endif /* !HAVE_GETTIMEOFDAY */
433 #if defined(HAVE_GETTIMEOFDAY)
434 static struct timeval begin, end;
437 * startTimer: call where you want to start timing
442 gettimeofday(&begin, NULL);
446 * endTimer: call where you want to stop timing and to print out a
447 * message about the timing performed; format is a printf
451 endTimer(const char *fmt, ...)
456 gettimeofday(&end, NULL);
457 msec = end.tv_sec - begin.tv_sec;
459 msec += (end.tv_usec - begin.tv_usec) / 1000;
461 #ifndef HAVE_STDARG_H
462 #error "endTimer required stdarg functions"
465 vfprintf(stderr, fmt, ap);
468 fprintf(stderr, " took %ld ms\n", msec);
470 #elif defined(HAVE_TIME_H)
472 * No gettimeofday function, so we have to make do with calling clock.
473 * This is obviously less accurate, but there's little we can do about
476 #ifndef CLOCKS_PER_SEC
477 #define CLOCKS_PER_SEC 100
480 static clock_t begin, end;
487 endTimer(const char *fmt, ...)
493 msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
495 #ifndef HAVE_STDARG_H
496 #error "endTimer required stdarg functions"
499 vfprintf(stderr, fmt, ap);
501 fprintf(stderr, " took %ld ms\n", msec);
506 * We don't have a gettimeofday or time.h, so we just don't do timing
516 endTimer(char *format, ...)
519 * We cannot do anything because we don't have a timing function
522 va_start(ap, format);
523 vfprintf(stderr, format, ap);
525 fprintf(stderr, " was not timed\n", msec);
527 /* We don't have gettimeofday, time or stdarg.h, what crazy world is
533 /************************************************************************
537 ************************************************************************/
538 static char buffer[50000];
541 xmlHTMLEncodeSend(void) {
544 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
546 xmlGenericError(xmlGenericErrorContext, "%s", result);
553 * xmlHTMLPrintFileInfo:
554 * @input: an xmlParserInputPtr input
556 * Displays the associated file and line informations for the current input
560 xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
562 xmlGenericError(xmlGenericErrorContext, "<p>");
564 len = strlen(buffer);
566 if (input->filename) {
567 snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename,
570 snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line);
577 * xmlHTMLPrintFileContext:
578 * @input: an xmlParserInputPtr input
580 * Displays current context within the input content for error tracking
584 xmlHTMLPrintFileContext(xmlParserInputPtr input) {
585 const xmlChar *cur, *base;
589 if (input == NULL) return;
590 xmlGenericError(xmlGenericErrorContext, "<pre>\n");
593 while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
597 while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
599 if ((*cur == '\n') || (*cur == '\r')) cur++;
602 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
603 len = strlen(buffer);
604 snprintf(&buffer[len], sizeof(buffer) - len, "%c",
605 (unsigned char) *cur++);
608 len = strlen(buffer);
609 snprintf(&buffer[len], sizeof(buffer) - len, "\n");
611 while ((*cur == '\n') || (*cur == '\r'))
614 while ((cur != base) && (n++ < 80)) {
615 len = strlen(buffer);
616 snprintf(&buffer[len], sizeof(buffer) - len, " ");
619 len = strlen(buffer);
620 snprintf(&buffer[len], sizeof(buffer) - len, "^\n");
622 xmlGenericError(xmlGenericErrorContext, "</pre>");
627 * @ctx: an XML parser context
628 * @msg: the message to display/transmit
629 * @...: extra parameters for the message display
631 * Display and format an error messages, gives file, line, position and
635 xmlHTMLError(void *ctx, const char *msg, ...)
637 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
638 xmlParserInputPtr input;
644 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
645 input = ctxt->inputTab[ctxt->inputNr - 2];
648 xmlHTMLPrintFileInfo(input);
650 xmlGenericError(xmlGenericErrorContext, "<b>error</b>: ");
652 len = strlen(buffer);
653 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
656 xmlGenericError(xmlGenericErrorContext, "</p>\n");
658 xmlHTMLPrintFileContext(input);
664 * @ctx: an XML parser context
665 * @msg: the message to display/transmit
666 * @...: extra parameters for the message display
668 * Display and format a warning messages, gives file, line, position and
672 xmlHTMLWarning(void *ctx, const char *msg, ...)
674 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
675 xmlParserInputPtr input;
681 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
682 input = ctxt->inputTab[ctxt->inputNr - 2];
686 xmlHTMLPrintFileInfo(input);
688 xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: ");
690 len = strlen(buffer);
691 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
694 xmlGenericError(xmlGenericErrorContext, "</p>\n");
696 xmlHTMLPrintFileContext(input);
701 * xmlHTMLValidityError:
702 * @ctx: an XML parser context
703 * @msg: the message to display/transmit
704 * @...: extra parameters for the message display
706 * Display and format an validity error messages, gives file,
707 * line, position and extra parameters.
710 xmlHTMLValidityError(void *ctx, const char *msg, ...)
712 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
713 xmlParserInputPtr input;
719 if ((input->filename == NULL) && (ctxt->inputNr > 1))
720 input = ctxt->inputTab[ctxt->inputNr - 2];
722 xmlHTMLPrintFileInfo(input);
724 xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: ");
725 len = strlen(buffer);
727 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
730 xmlGenericError(xmlGenericErrorContext, "</p>\n");
732 xmlHTMLPrintFileContext(input);
734 progresult = XMLLINT_ERR_VALID;
738 * xmlHTMLValidityWarning:
739 * @ctx: an XML parser context
740 * @msg: the message to display/transmit
741 * @...: extra parameters for the message display
743 * Display and format a validity warning messages, gives file, line,
744 * position and extra parameters.
747 xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
749 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
750 xmlParserInputPtr input;
756 if ((input->filename == NULL) && (ctxt->inputNr > 1))
757 input = ctxt->inputTab[ctxt->inputNr - 2];
759 xmlHTMLPrintFileInfo(input);
761 xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: ");
763 len = strlen(buffer);
764 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
767 xmlGenericError(xmlGenericErrorContext, "</p>\n");
769 xmlHTMLPrintFileContext(input);
773 /************************************************************************
777 ************************************************************************/
778 #ifdef LIBXML_DEBUG_ENABLED
779 #ifdef LIBXML_XPATH_ENABLED
782 * @prompt: the prompt value
786 * Returns a pointer to it or NULL on EOF the caller is expected to
787 * free the returned string.
790 xmlShellReadline(char *prompt) {
791 #ifdef HAVE_LIBREADLINE
794 /* Get a line from the user. */
795 line_read = readline (prompt);
797 /* If the line has any text in it, save it on the history. */
798 if (line_read && *line_read)
799 add_history (line_read);
808 fprintf(stdout, "%s", prompt);
809 if (!fgets(line_read, 500, stdin))
812 len = strlen(line_read);
813 ret = (char *) malloc(len + 1);
815 memcpy (ret, line_read, len + 1);
820 #endif /* LIBXML_XPATH_ENABLED */
821 #endif /* LIBXML_DEBUG_ENABLED */
823 /************************************************************************
827 ************************************************************************/
829 static int myRead(FILE *f, char * buf, int len) {
830 return(fread(buf, 1, len, f));
832 static void myClose(FILE *f) {
838 /************************************************************************
842 ************************************************************************/
847 static xmlSAXHandler emptySAXHandlerStruct = {
848 NULL, /* internalSubset */
849 NULL, /* isStandalone */
850 NULL, /* hasInternalSubset */
851 NULL, /* hasExternalSubset */
852 NULL, /* resolveEntity */
853 NULL, /* getEntity */
854 NULL, /* entityDecl */
855 NULL, /* notationDecl */
856 NULL, /* attributeDecl */
857 NULL, /* elementDecl */
858 NULL, /* unparsedEntityDecl */
859 NULL, /* setDocumentLocator */
860 NULL, /* startDocument */
861 NULL, /* endDocument */
862 NULL, /* startElement */
863 NULL, /* endElement */
864 NULL, /* reference */
865 NULL, /* characters */
866 NULL, /* ignorableWhitespace */
867 NULL, /* processingInstruction */
869 NULL, /* xmlParserWarning */
870 NULL, /* xmlParserError */
871 NULL, /* xmlParserError */
872 NULL, /* getParameterEntity */
873 NULL, /* cdataBlock; */
874 NULL, /* externalSubset; */
877 NULL, /* startElementNs */
878 NULL, /* endElementNs */
879 NULL /* xmlStructuredErrorFunc */
882 static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
883 extern xmlSAXHandlerPtr debugSAXHandler;
884 static int callbacks;
888 * @ctxt: An XML parser context
890 * Is this document tagged standalone ?
895 isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
900 fprintf(stdout, "SAX.isStandalone()\n");
905 * hasInternalSubsetDebug:
906 * @ctxt: An XML parser context
908 * Does this document has an internal subset
913 hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
918 fprintf(stdout, "SAX.hasInternalSubset()\n");
923 * hasExternalSubsetDebug:
924 * @ctxt: An XML parser context
926 * Does this document has an external subset
931 hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
936 fprintf(stdout, "SAX.hasExternalSubset()\n");
941 * internalSubsetDebug:
942 * @ctxt: An XML parser context
944 * Does this document has an internal subset
947 internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
948 const xmlChar *ExternalID, const xmlChar *SystemID)
953 fprintf(stdout, "SAX.internalSubset(%s,", name);
954 if (ExternalID == NULL)
955 fprintf(stdout, " ,");
957 fprintf(stdout, " %s,", ExternalID);
958 if (SystemID == NULL)
959 fprintf(stdout, " )\n");
961 fprintf(stdout, " %s)\n", SystemID);
965 * externalSubsetDebug:
966 * @ctxt: An XML parser context
968 * Does this document has an external subset
971 externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
972 const xmlChar *ExternalID, const xmlChar *SystemID)
977 fprintf(stdout, "SAX.externalSubset(%s,", name);
978 if (ExternalID == NULL)
979 fprintf(stdout, " ,");
981 fprintf(stdout, " %s,", ExternalID);
982 if (SystemID == NULL)
983 fprintf(stdout, " )\n");
985 fprintf(stdout, " %s)\n", SystemID);
989 * resolveEntityDebug:
990 * @ctxt: An XML parser context
991 * @publicId: The public ID of the entity
992 * @systemId: The system ID of the entity
994 * Special entity resolver, better left to the parser, it has
995 * more context than the application layer.
996 * The default behaviour is to NOT resolve the entities, in that case
997 * the ENTITY_REF nodes are built in the structure (and the parameter
1000 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
1002 static xmlParserInputPtr
1003 resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
1008 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
1011 fprintf(stdout, "SAX.resolveEntity(");
1012 if (publicId != NULL)
1013 fprintf(stdout, "%s", (char *)publicId);
1015 fprintf(stdout, " ");
1016 if (systemId != NULL)
1017 fprintf(stdout, ", %s)\n", (char *)systemId);
1019 fprintf(stdout, ", )\n");
1025 * @ctxt: An XML parser context
1026 * @name: The entity name
1028 * Get an entity by name
1030 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
1033 getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
1038 fprintf(stdout, "SAX.getEntity(%s)\n", name);
1043 * getParameterEntityDebug:
1044 * @ctxt: An XML parser context
1045 * @name: The entity name
1047 * Get a parameter entity by name
1049 * Returns the xmlParserInputPtr
1052 getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
1057 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
1064 * @ctxt: An XML parser context
1065 * @name: the entity name
1066 * @type: the entity type
1067 * @publicId: The public ID of the entity
1068 * @systemId: The system ID of the entity
1069 * @content: the entity value (without processing).
1071 * An entity definition has been parsed
1074 entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
1075 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
1077 const xmlChar *nullstr = BAD_CAST "(null)";
1078 /* not all libraries handle printing null pointers nicely */
1079 if (publicId == NULL)
1081 if (systemId == NULL)
1083 if (content == NULL)
1084 content = (xmlChar *)nullstr;
1088 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
1089 name, type, publicId, systemId, content);
1093 * attributeDeclDebug:
1094 * @ctxt: An XML parser context
1095 * @name: the attribute name
1096 * @type: the attribute type
1098 * An attribute definition has been parsed
1101 attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem,
1102 const xmlChar * name, int type, int def,
1103 const xmlChar * defaultValue, xmlEnumerationPtr tree)
1108 if (defaultValue == NULL)
1109 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n",
1110 elem, name, type, def);
1112 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
1113 elem, name, type, def, defaultValue);
1114 xmlFreeEnumeration(tree);
1119 * @ctxt: An XML parser context
1120 * @name: the element name
1121 * @type: the element type
1122 * @content: the element value (without processing).
1124 * An element definition has been parsed
1127 elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
1128 xmlElementContentPtr content ATTRIBUTE_UNUSED)
1133 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
1138 * notationDeclDebug:
1139 * @ctxt: An XML parser context
1140 * @name: The name of the notation
1141 * @publicId: The public ID of the entity
1142 * @systemId: The system ID of the entity
1144 * What to do when a notation declaration has been parsed.
1147 notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
1148 const xmlChar *publicId, const xmlChar *systemId)
1153 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
1154 (char *) name, (char *) publicId, (char *) systemId);
1158 * unparsedEntityDeclDebug:
1159 * @ctxt: An XML parser context
1160 * @name: The name of the entity
1161 * @publicId: The public ID of the entity
1162 * @systemId: The system ID of the entity
1163 * @notationName: the name of the notation
1165 * What to do when an unparsed entity declaration is parsed
1168 unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
1169 const xmlChar *publicId, const xmlChar *systemId,
1170 const xmlChar *notationName)
1172 const xmlChar *nullstr = BAD_CAST "(null)";
1174 if (publicId == NULL)
1176 if (systemId == NULL)
1178 if (notationName == NULL)
1179 notationName = nullstr;
1183 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
1184 (char *) name, (char *) publicId, (char *) systemId,
1185 (char *) notationName);
1189 * setDocumentLocatorDebug:
1190 * @ctxt: An XML parser context
1191 * @loc: A SAX Locator
1193 * Receive the document locator at startup, actually xmlDefaultSAXLocator
1194 * Everything is available on the context, so this is useless in our case.
1197 setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
1202 fprintf(stdout, "SAX.setDocumentLocator()\n");
1206 * startDocumentDebug:
1207 * @ctxt: An XML parser context
1209 * called when the document start being processed.
1212 startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
1217 fprintf(stdout, "SAX.startDocument()\n");
1222 * @ctxt: An XML parser context
1224 * called when the document end has been detected.
1227 endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
1232 fprintf(stdout, "SAX.endDocument()\n");
1236 * startElementDebug:
1237 * @ctxt: An XML parser context
1238 * @name: The element name
1240 * called when an opening tag has been processed.
1243 startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
1250 fprintf(stdout, "SAX.startElement(%s", (char *) name);
1252 for (i = 0;(atts[i] != NULL);i++) {
1253 fprintf(stdout, ", %s='", atts[i++]);
1254 if (atts[i] != NULL)
1255 fprintf(stdout, "%s'", atts[i]);
1258 fprintf(stdout, ")\n");
1263 * @ctxt: An XML parser context
1264 * @name: The element name
1266 * called when the end of an element has been detected.
1269 endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
1274 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
1279 * @ctxt: An XML parser context
1280 * @ch: a xmlChar string
1281 * @len: the number of xmlChar
1283 * receiving some chars from the parser.
1284 * Question: how much at a time ???
1287 charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
1295 for (i = 0;(i<len) && (i < 30);i++)
1299 fprintf(stdout, "SAX.characters(%s, %d)\n", out, len);
1304 * @ctxt: An XML parser context
1305 * @name: The entity name
1307 * called when an entity reference is detected.
1310 referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
1315 fprintf(stdout, "SAX.reference(%s)\n", name);
1319 * ignorableWhitespaceDebug:
1320 * @ctxt: An XML parser context
1321 * @ch: a xmlChar string
1322 * @start: the first char in the string
1323 * @len: the number of xmlChar
1325 * receiving some ignorable whitespaces from the parser.
1326 * Question: how much at a time ???
1329 ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
1337 for (i = 0;(i<len) && (i < 30);i++)
1340 fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", out, len);
1344 * processingInstructionDebug:
1345 * @ctxt: An XML parser context
1346 * @target: the target name
1347 * @data: the PI data's
1348 * @len: the number of xmlChar
1350 * A processing instruction has been parsed.
1353 processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
1354 const xmlChar *data)
1360 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
1361 (char *) target, (char *) data);
1363 fprintf(stdout, "SAX.processingInstruction(%s, NULL)\n",
1369 * @ctx: the user data (XML parser context)
1370 * @value: The pcdata content
1371 * @len: the block length
1373 * called when a pcdata block has been parsed
1376 cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
1381 fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
1382 (char *) value, len);
1387 * @ctxt: An XML parser context
1388 * @value: the comment content
1390 * A comment has been parsed.
1393 commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
1398 fprintf(stdout, "SAX.comment(%s)\n", value);
1403 * @ctxt: An XML parser context
1404 * @msg: the message to display/transmit
1405 * @...: extra parameters for the message display
1407 * Display and format a warning messages, gives file, line, position and
1410 static void XMLCDECL
1411 warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
1418 va_start(args, msg);
1419 fprintf(stdout, "SAX.warning: ");
1420 vfprintf(stdout, msg, args);
1426 * @ctxt: An XML parser context
1427 * @msg: the message to display/transmit
1428 * @...: extra parameters for the message display
1430 * Display and format a error messages, gives file, line, position and
1433 static void XMLCDECL
1434 errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
1441 va_start(args, msg);
1442 fprintf(stdout, "SAX.error: ");
1443 vfprintf(stdout, msg, args);
1449 * @ctxt: An XML parser context
1450 * @msg: the message to display/transmit
1451 * @...: extra parameters for the message display
1453 * Display and format a fatalError messages, gives file, line, position and
1456 static void XMLCDECL
1457 fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
1464 va_start(args, msg);
1465 fprintf(stdout, "SAX.fatalError: ");
1466 vfprintf(stdout, msg, args);
1470 static xmlSAXHandler debugSAXHandlerStruct = {
1471 internalSubsetDebug,
1473 hasInternalSubsetDebug,
1474 hasExternalSubsetDebug,
1481 unparsedEntityDeclDebug,
1482 setDocumentLocatorDebug,
1489 ignorableWhitespaceDebug,
1490 processingInstructionDebug,
1495 getParameterEntityDebug,
1497 externalSubsetDebug,
1505 xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
1508 * SAX2 specific callbacks
1511 * startElementNsDebug:
1512 * @ctxt: An XML parser context
1513 * @name: The element name
1515 * called when an opening tag has been processed.
1518 startElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
1519 const xmlChar *localname,
1520 const xmlChar *prefix,
1523 const xmlChar **namespaces,
1526 const xmlChar **attributes)
1533 fprintf(stdout, "SAX.startElementNs(%s", (char *) localname);
1535 fprintf(stdout, ", NULL");
1537 fprintf(stdout, ", %s", (char *) prefix);
1539 fprintf(stdout, ", NULL");
1541 fprintf(stdout, ", '%s'", (char *) URI);
1542 fprintf(stdout, ", %d", nb_namespaces);
1544 if (namespaces != NULL) {
1545 for (i = 0;i < nb_namespaces * 2;i++) {
1546 fprintf(stdout, ", xmlns");
1547 if (namespaces[i] != NULL)
1548 fprintf(stdout, ":%s", namespaces[i]);
1550 fprintf(stdout, "='%s'", namespaces[i]);
1553 fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted);
1554 if (attributes != NULL) {
1555 for (i = 0;i < nb_attributes * 5;i += 5) {
1556 if (attributes[i + 1] != NULL)
1557 fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]);
1559 fprintf(stdout, ", %s='", attributes[i]);
1560 fprintf(stdout, "%.4s...', %d", attributes[i + 3],
1561 (int)(attributes[i + 4] - attributes[i + 3]));
1564 fprintf(stdout, ")\n");
1569 * @ctxt: An XML parser context
1570 * @name: The element name
1572 * called when the end of an element has been detected.
1575 endElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
1576 const xmlChar *localname,
1577 const xmlChar *prefix,
1583 fprintf(stdout, "SAX.endElementNs(%s", (char *) localname);
1585 fprintf(stdout, ", NULL");
1587 fprintf(stdout, ", %s", (char *) prefix);
1589 fprintf(stdout, ", NULL)\n");
1591 fprintf(stdout, ", '%s')\n", (char *) URI);
1594 static xmlSAXHandler debugSAX2HandlerStruct = {
1595 internalSubsetDebug,
1597 hasInternalSubsetDebug,
1598 hasExternalSubsetDebug,
1605 unparsedEntityDeclDebug,
1606 setDocumentLocatorDebug,
1613 ignorableWhitespaceDebug,
1614 processingInstructionDebug,
1619 getParameterEntityDebug,
1621 externalSubsetDebug,
1624 startElementNsDebug,
1629 static xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
1632 testSAX(const char *filename) {
1633 xmlSAXHandlerPtr handler;
1634 const char *user_data = "user_data"; /* mostly for debugging */
1635 xmlParserInputBufferPtr buf = NULL;
1636 xmlParserInputPtr inputStream;
1637 xmlParserCtxtPtr ctxt = NULL;
1638 xmlSAXHandlerPtr old_sax = NULL;
1643 handler = emptySAXHandler;
1644 #ifdef LIBXML_SAX1_ENABLED
1646 handler = debugSAXHandler;
1649 handler = debugSAX2Handler;
1653 * it's not the simplest code but the most generic in term of I/O
1655 buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
1660 #ifdef LIBXML_SCHEMAS_ENABLED
1661 if (wxschemas != NULL) {
1663 xmlSchemaValidCtxtPtr vctxt;
1665 vctxt = xmlSchemaNewValidCtxt(wxschemas);
1666 xmlSchemaSetValidErrors(vctxt,
1667 (xmlSchemaValidityErrorFunc) fprintf,
1668 (xmlSchemaValidityWarningFunc) fprintf,
1671 ret = xmlSchemaValidateStream(vctxt, buf, 0, handler,
1675 fprintf(stderr, "%s validates\n", filename);
1676 } else if (ret > 0) {
1677 fprintf(stderr, "%s fails to validate\n", filename);
1678 progresult = XMLLINT_ERR_VALID;
1680 fprintf(stderr, "%s validation generated an internal error\n",
1682 progresult = XMLLINT_ERR_VALID;
1685 xmlSchemaFreeValidCtxt(vctxt);
1690 * Create the parser context amd hook the input
1692 ctxt = xmlNewParserCtxt();
1694 xmlFreeParserInputBuffer(buf);
1697 old_sax = ctxt->sax;
1698 ctxt->sax = handler;
1699 ctxt->userData = (void *) user_data;
1700 inputStream = xmlNewIOInputStream(ctxt, buf, XML_CHAR_ENCODING_NONE);
1701 if (inputStream == NULL) {
1702 xmlFreeParserInputBuffer(buf);
1705 inputPush(ctxt, inputStream);
1707 /* do the parsing */
1708 xmlParseDocument(ctxt);
1710 if (ctxt->myDoc != NULL) {
1711 fprintf(stderr, "SAX generated a doc !\n");
1712 xmlFreeDoc(ctxt->myDoc);
1719 ctxt->sax = old_sax;
1720 xmlFreeParserCtxt(ctxt);
1724 /************************************************************************
1726 * Stream Test processing *
1728 ************************************************************************/
1729 #ifdef LIBXML_READER_ENABLED
1730 static void processNode(xmlTextReaderPtr reader) {
1731 const xmlChar *name, *value;
1734 type = xmlTextReaderNodeType(reader);
1735 empty = xmlTextReaderIsEmptyElement(reader);
1738 name = xmlTextReaderConstName(reader);
1740 name = BAD_CAST "--";
1742 value = xmlTextReaderConstValue(reader);
1745 printf("%d %d %s %d %d",
1746 xmlTextReaderDepth(reader),
1750 xmlTextReaderHasValue(reader));
1754 printf(" %s\n", value);
1757 #ifdef LIBXML_PATTERN_ENABLED
1759 xmlChar *path = NULL;
1762 if (type == XML_READER_TYPE_ELEMENT) {
1763 /* do the check only on element start */
1764 match = xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader));
1767 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED)
1768 path = xmlGetNodePath(xmlTextReaderCurrentNode(reader));
1769 printf("Node %s matches pattern %s\n", path, pattern);
1771 printf("Node %s matches pattern %s\n",
1772 xmlTextReaderConstName(reader), pattern);
1776 if (patstream != NULL) {
1779 if (type == XML_READER_TYPE_ELEMENT) {
1780 ret = xmlStreamPush(patstream,
1781 xmlTextReaderConstLocalName(reader),
1782 xmlTextReaderConstNamespaceUri(reader));
1784 fprintf(stderr, "xmlStreamPush() failure\n");
1785 xmlFreeStreamCtxt(patstream);
1787 } else if (ret != match) {
1788 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED)
1790 path = xmlGetNodePath(
1791 xmlTextReaderCurrentNode(reader));
1795 "xmlPatternMatch and xmlStreamPush disagree\n");
1797 fprintf(stderr, " pattern %s node %s\n",
1800 fprintf(stderr, " pattern %s node %s\n",
1801 pattern, xmlTextReaderConstName(reader));
1805 if ((type == XML_READER_TYPE_END_ELEMENT) ||
1806 ((type == XML_READER_TYPE_ELEMENT) && (empty))) {
1807 ret = xmlStreamPop(patstream);
1809 fprintf(stderr, "xmlStreamPop() failure\n");
1810 xmlFreeStreamCtxt(patstream);
1821 static void streamFile(char *filename) {
1822 xmlTextReaderPtr reader;
1824 #ifdef HAVE_SYS_MMAN_H
1827 const char *base = NULL;
1828 xmlParserInputBufferPtr input = NULL;
1831 if (stat(filename, &info) < 0)
1833 if ((fd = open(filename, O_RDONLY)) < 0)
1835 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
1836 if (base == (void *) MAP_FAILED)
1839 reader = xmlReaderForMemory(base, info.st_size, filename,
1843 reader = xmlReaderForFile(filename, NULL, options);
1844 #ifdef LIBXML_PATTERN_ENABLED
1845 if (pattern != NULL) {
1846 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
1847 if (patternc == NULL) {
1848 xmlGenericError(xmlGenericErrorContext,
1849 "Pattern %s failed to compile\n", pattern);
1850 progresult = XMLLINT_ERR_SCHEMAPAT;
1854 if (patternc != NULL) {
1855 patstream = xmlPatternGetStreamCtxt(patternc);
1856 if (patstream != NULL) {
1857 ret = xmlStreamPush(patstream, NULL, NULL);
1859 fprintf(stderr, "xmlStreamPush() failure\n");
1860 xmlFreeStreamCtxt(patstream);
1868 if (reader != NULL) {
1869 #ifdef LIBXML_VALID_ENABLED
1871 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
1873 #endif /* LIBXML_VALID_ENABLED */
1874 xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1);
1875 #ifdef LIBXML_SCHEMAS_ENABLED
1876 if (relaxng != NULL) {
1877 if ((timing) && (!repeat)) {
1880 ret = xmlTextReaderRelaxNGValidate(reader, relaxng);
1882 xmlGenericError(xmlGenericErrorContext,
1883 "Relax-NG schema %s failed to compile\n", relaxng);
1884 progresult = XMLLINT_ERR_SCHEMACOMP;
1887 if ((timing) && (!repeat)) {
1888 endTimer("Compiling the schemas");
1891 if (schema != NULL) {
1892 if ((timing) && (!repeat)) {
1895 ret = xmlTextReaderSchemaValidate(reader, schema);
1897 xmlGenericError(xmlGenericErrorContext,
1898 "XSD schema %s failed to compile\n", schema);
1899 progresult = XMLLINT_ERR_SCHEMACOMP;
1902 if ((timing) && (!repeat)) {
1903 endTimer("Compiling the schemas");
1909 * Process all nodes in sequence
1911 if ((timing) && (!repeat)) {
1914 ret = xmlTextReaderRead(reader);
1917 #ifdef LIBXML_PATTERN_ENABLED
1921 processNode(reader);
1922 ret = xmlTextReaderRead(reader);
1924 if ((timing) && (!repeat)) {
1925 #ifdef LIBXML_SCHEMAS_ENABLED
1926 if (relaxng != NULL)
1927 endTimer("Parsing and validating");
1930 #ifdef LIBXML_VALID_ENABLED
1932 endTimer("Parsing and validating");
1935 endTimer("Parsing");
1938 #ifdef LIBXML_VALID_ENABLED
1940 if (xmlTextReaderIsValid(reader) != 1) {
1941 xmlGenericError(xmlGenericErrorContext,
1942 "Document %s does not validate\n", filename);
1943 progresult = XMLLINT_ERR_VALID;
1946 #endif /* LIBXML_VALID_ENABLED */
1947 #ifdef LIBXML_SCHEMAS_ENABLED
1948 if ((relaxng != NULL) || (schema != NULL)) {
1949 if (xmlTextReaderIsValid(reader) != 1) {
1950 fprintf(stderr, "%s fails to validate\n", filename);
1951 progresult = XMLLINT_ERR_VALID;
1953 fprintf(stderr, "%s validates\n", filename);
1958 * Done, cleanup and status
1960 xmlFreeTextReader(reader);
1962 fprintf(stderr, "%s : failed to parse\n", filename);
1963 progresult = XMLLINT_ERR_UNCLASS;
1966 fprintf(stderr, "Unable to open %s\n", filename);
1967 progresult = XMLLINT_ERR_UNCLASS;
1969 #ifdef LIBXML_PATTERN_ENABLED
1970 if (patstream != NULL) {
1971 xmlFreeStreamCtxt(patstream);
1975 #ifdef HAVE_SYS_MMAN_H
1977 xmlFreeParserInputBuffer(input);
1978 munmap((char *) base, info.st_size);
1984 static void walkDoc(xmlDocPtr doc) {
1985 xmlTextReaderPtr reader;
1988 #ifdef LIBXML_PATTERN_ENABLED
1990 const xmlChar *namespaces[22];
1994 root = xmlDocGetRootElement(doc);
1995 for (ns = root->nsDef, i = 0;ns != NULL && i < 20;ns=ns->next) {
1996 namespaces[i++] = ns->href;
1997 namespaces[i++] = ns->prefix;
1999 namespaces[i++] = NULL;
2000 namespaces[i] = NULL;
2002 if (pattern != NULL) {
2003 patternc = xmlPatterncompile((const xmlChar *) pattern, doc->dict,
2005 if (patternc == NULL) {
2006 xmlGenericError(xmlGenericErrorContext,
2007 "Pattern %s failed to compile\n", pattern);
2008 progresult = XMLLINT_ERR_SCHEMAPAT;
2012 if (patternc != NULL) {
2013 patstream = xmlPatternGetStreamCtxt(patternc);
2014 if (patstream != NULL) {
2015 ret = xmlStreamPush(patstream, NULL, NULL);
2017 fprintf(stderr, "xmlStreamPush() failure\n");
2018 xmlFreeStreamCtxt(patstream);
2023 #endif /* LIBXML_PATTERN_ENABLED */
2024 reader = xmlReaderWalker(doc);
2025 if (reader != NULL) {
2026 if ((timing) && (!repeat)) {
2029 ret = xmlTextReaderRead(reader);
2032 #ifdef LIBXML_PATTERN_ENABLED
2036 processNode(reader);
2037 ret = xmlTextReaderRead(reader);
2039 if ((timing) && (!repeat)) {
2040 endTimer("walking through the doc");
2042 xmlFreeTextReader(reader);
2044 fprintf(stderr, "failed to walk through the doc\n");
2045 progresult = XMLLINT_ERR_UNCLASS;
2048 fprintf(stderr, "Failed to crate a reader from the document\n");
2049 progresult = XMLLINT_ERR_UNCLASS;
2051 #ifdef LIBXML_PATTERN_ENABLED
2052 if (patstream != NULL) {
2053 xmlFreeStreamCtxt(patstream);
2058 #endif /* LIBXML_READER_ENABLED */
2060 #ifdef LIBXML_XPATH_ENABLED
2061 /************************************************************************
2065 ************************************************************************/
2067 static void doXPathDump(xmlXPathObjectPtr cur) {
2069 case XPATH_NODESET: {
2072 #ifdef LIBXML_OUTPUT_ENABLED
2073 xmlSaveCtxtPtr ctxt;
2075 if (cur->nodesetval->nodeNr <= 0) {
2076 fprintf(stderr, "XPath set is empty\n");
2077 progresult = XMLLINT_ERR_XPATH;
2080 ctxt = xmlSaveToFd(1, NULL, 0);
2082 fprintf(stderr, "Out of memory for XPath\n");
2083 progresult = XMLLINT_ERR_MEM;
2086 for (i = 0;i < cur->nodesetval->nodeNr;i++) {
2087 node = cur->nodesetval->nodeTab[i];
2088 xmlSaveTree(ctxt, node);
2092 printf("xpath returned %d nodes\n", cur->nodesetval->nodeNr);
2097 if (cur->boolval) printf("true");
2098 else printf("false");
2101 switch (xmlXPathIsInf(cur->floatval)) {
2106 printf("-Infinity");
2109 if (xmlXPathIsNaN(cur->floatval)) {
2112 printf("%0g", cur->floatval);
2117 printf("%s", (const char *) cur->stringval);
2119 case XPATH_UNDEFINED:
2120 fprintf(stderr, "XPath Object is uninitialized\n");
2121 progresult = XMLLINT_ERR_XPATH;
2124 fprintf(stderr, "XPath object of unexpected type\n");
2125 progresult = XMLLINT_ERR_XPATH;
2130 static void doXPathQuery(xmlDocPtr doc, const char *query) {
2131 xmlXPathContextPtr ctxt;
2132 xmlXPathObjectPtr res;
2134 ctxt = xmlXPathNewContext(doc);
2136 fprintf(stderr, "Out of memory for XPath\n");
2137 progresult = XMLLINT_ERR_MEM;
2140 ctxt->node = xmlDocGetRootElement(doc);
2141 res = xmlXPathEval(BAD_CAST query, ctxt);
2142 xmlXPathFreeContext(ctxt);
2145 fprintf(stderr, "XPath evaluation failure\n");
2146 progresult = XMLLINT_ERR_XPATH;
2150 xmlXPathFreeObject(res);
2152 #endif /* LIBXML_XPATH_ENABLED */
2154 /************************************************************************
2156 * Tree Test processing *
2158 ************************************************************************/
2159 static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
2160 xmlDocPtr doc = NULL;
2161 #ifdef LIBXML_TREE_ENABLED
2163 #endif /* LIBXML_TREE_ENABLED */
2165 if ((timing) && (!repeat))
2169 #ifdef LIBXML_TREE_ENABLED
2170 if (filename == NULL) {
2174 doc = xmlNewDoc(BAD_CAST "1.0");
2175 n = xmlNewDocNode(doc, NULL, BAD_CAST "info", NULL);
2176 xmlNodeSetContent(n, BAD_CAST "abc");
2177 xmlDocSetRootElement(doc, n);
2180 #endif /* LIBXML_TREE_ENABLED */
2181 #ifdef LIBXML_HTML_ENABLED
2182 #ifdef LIBXML_PUSH_ENABLED
2183 else if ((html) && (push)) {
2186 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
2187 f = fopen(filename, "rb");
2189 f = fopen(filename, "r");
2194 htmlParserCtxtPtr ctxt;
2198 res = fread(chars, 1, 4, f);
2200 ctxt = htmlCreatePushParserCtxt(NULL, NULL,
2201 chars, res, filename, XML_CHAR_ENCODING_NONE);
2202 while ((res = fread(chars, 1, size, f)) > 0) {
2203 htmlParseChunk(ctxt, chars, res, 0);
2205 htmlParseChunk(ctxt, chars, 0, 1);
2207 htmlFreeParserCtxt(ctxt);
2212 #endif /* LIBXML_PUSH_ENABLED */
2213 #ifdef HAVE_SYS_MMAN_H
2214 else if ((html) && (memory)) {
2218 if (stat(filename, &info) < 0)
2220 if ((fd = open(filename, O_RDONLY)) < 0)
2222 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
2223 if (base == (void *) MAP_FAILED)
2226 doc = htmlReadMemory((char *) base, info.st_size, filename,
2229 munmap((char *) base, info.st_size);
2234 doc = htmlReadFile(filename, NULL, options);
2236 #endif /* LIBXML_HTML_ENABLED */
2238 #ifdef LIBXML_PUSH_ENABLED
2240 * build an XML tree from a string;
2245 /* '-' Usually means stdin -<sven@zen.org> */
2246 if ((filename[0] == '-') && (filename[1] == 0)) {
2249 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
2250 f = fopen(filename, "rb");
2252 f = fopen(filename, "r");
2257 int res, size = 1024;
2259 xmlParserCtxtPtr ctxt;
2261 /* if (repeat) size = 1024; */
2262 res = fread(chars, 1, 4, f);
2264 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
2265 chars, res, filename);
2266 xmlCtxtUseOptions(ctxt, options);
2267 while ((res = fread(chars, 1, size, f)) > 0) {
2268 xmlParseChunk(ctxt, chars, res, 0);
2270 xmlParseChunk(ctxt, chars, 0, 1);
2272 ret = ctxt->wellFormed;
2273 xmlFreeParserCtxt(ctxt);
2283 #endif /* LIBXML_PUSH_ENABLED */
2285 if ((filename[0] == '-') && (filename[1] == 0)) {
2286 doc = xmlReadFd(0, NULL, NULL, options);
2290 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
2291 f = fopen(filename, "rb");
2293 f = fopen(filename, "r");
2297 doc = xmlReadIO((xmlInputReadCallback) myRead,
2298 (xmlInputCloseCallback) myClose, f,
2299 filename, NULL, options);
2301 doc = xmlCtxtReadIO(rectxt,
2302 (xmlInputReadCallback) myRead,
2303 (xmlInputCloseCallback) myClose, f,
2304 filename, NULL, options);
2308 } else if (htmlout) {
2309 xmlParserCtxtPtr ctxt;
2312 ctxt = xmlNewParserCtxt();
2318 ctxt->sax->error = xmlHTMLError;
2319 ctxt->sax->warning = xmlHTMLWarning;
2320 ctxt->vctxt.error = xmlHTMLValidityError;
2321 ctxt->vctxt.warning = xmlHTMLValidityWarning;
2323 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
2326 xmlFreeParserCtxt(ctxt);
2328 #ifdef HAVE_SYS_MMAN_H
2329 } else if (memory) {
2333 if (stat(filename, &info) < 0)
2335 if ((fd = open(filename, O_RDONLY)) < 0)
2337 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
2338 if (base == (void *) MAP_FAILED)
2342 doc = xmlReadMemory((char *) base, info.st_size,
2343 filename, NULL, options);
2345 doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size,
2346 filename, NULL, options);
2348 munmap((char *) base, info.st_size);
2351 #ifdef LIBXML_VALID_ENABLED
2353 xmlParserCtxtPtr ctxt = NULL;
2356 ctxt = xmlNewParserCtxt();
2362 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
2364 if (ctxt->valid == 0)
2365 progresult = XMLLINT_ERR_RDFILE;
2367 xmlFreeParserCtxt(ctxt);
2369 #endif /* LIBXML_VALID_ENABLED */
2372 doc = xmlCtxtReadFile(rectxt, filename, NULL, options);
2374 #ifdef LIBXML_SAX1_ENABLED
2376 doc = xmlParseFile(filename);
2378 #endif /* LIBXML_SAX1_ENABLED */
2379 doc = xmlReadFile(filename, NULL, options);
2385 * If we don't have a document we might as well give up. Do we
2386 * want an error message here? <sven@zen.org> */
2388 progresult = XMLLINT_ERR_UNCLASS;
2392 if ((timing) && (!repeat)) {
2393 endTimer("Parsing");
2397 * Remove DOCTYPE nodes
2402 dtd = xmlGetIntSubset(doc);
2404 xmlUnlinkNode((xmlNodePtr)dtd);
2409 #ifdef LIBXML_XINCLUDE_ENABLED
2411 if ((timing) && (!repeat)) {
2414 if (xmlXIncludeProcessFlags(doc, options) < 0)
2415 progresult = XMLLINT_ERR_UNCLASS;
2416 if ((timing) && (!repeat)) {
2417 endTimer("Xinclude processing");
2422 #ifdef LIBXML_XPATH_ENABLED
2423 if (xpathquery != NULL) {
2424 doXPathQuery(doc, xpathquery);
2428 #ifdef LIBXML_DEBUG_ENABLED
2429 #ifdef LIBXML_XPATH_ENABLED
2434 xmlXPathOrderDocElems(doc);
2435 xmlShell(doc, filename, xmlShellReadline, stdout);
2440 #ifdef LIBXML_TREE_ENABLED
2442 * test intermediate copy if needed.
2449 doc = xmlCopyDoc(doc, 1);
2451 endTimer("Copying");
2458 endTimer("Freeing original");
2461 #endif /* LIBXML_TREE_ENABLED */
2463 #ifdef LIBXML_VALID_ENABLED
2464 if ((insert) && (!html)) {
2465 const xmlChar* list[256];
2469 if (doc->children != NULL) {
2470 node = doc->children;
2471 while ((node != NULL) && (node->last == NULL)) node = node->next;
2473 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
2475 fprintf(stderr, "could not get valid list of elements\n");
2476 } else if (nb == 0) {
2477 fprintf(stderr, "No element can be inserted under root\n");
2479 fprintf(stderr, "%d element types can be inserted under root:\n",
2481 for (i = 0;i < nb;i++) {
2482 fprintf(stderr, "%s\n", (char *) list[i]);
2488 #endif /* LIBXML_VALID_ENABLED */
2489 #ifdef LIBXML_READER_ENABLED
2493 #endif /* LIBXML_READER_ENABLED */
2494 #ifdef LIBXML_OUTPUT_ENABLED
2501 #ifdef LIBXML_DEBUG_ENABLED
2504 if ((timing) && (!repeat)) {
2507 #ifdef LIBXML_HTML_ENABLED
2508 if ((html) && (!xmlout)) {
2510 htmlSaveFile(output ? output : "-", doc);
2512 else if (encoding != NULL) {
2514 htmlSaveFileFormat(output ? output : "-", doc, encoding, 1);
2517 htmlSaveFileFormat(output ? output : "-", doc, encoding, 0);
2520 else if (format == 1) {
2521 htmlSaveFileFormat(output ? output : "-", doc, NULL, 1);
2528 out = fopen(output,"wb");
2531 if (htmlDocDump(out, doc) < 0)
2532 progresult = XMLLINT_ERR_OUT;
2537 fprintf(stderr, "failed to open %s\n", output);
2538 progresult = XMLLINT_ERR_OUT;
2541 if ((timing) && (!repeat)) {
2546 #ifdef LIBXML_C14N_ENABLED
2548 xmlChar *result = NULL;
2551 size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_0, NULL, 1, &result);
2553 write(1, result, size);
2556 fprintf(stderr, "Failed to canonicalize\n");
2557 progresult = XMLLINT_ERR_OUT;
2559 } else if (canonical) {
2560 xmlChar *result = NULL;
2563 size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_1, NULL, 1, &result);
2565 write(1, result, size);
2568 fprintf(stderr, "Failed to canonicalize\n");
2569 progresult = XMLLINT_ERR_OUT;
2572 if (exc_canonical) {
2573 xmlChar *result = NULL;
2576 size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_EXCLUSIVE_1_0, NULL, 1, &result);
2578 write(1, result, size);
2581 fprintf(stderr, "Failed to canonicalize\n");
2582 progresult = XMLLINT_ERR_OUT;
2586 #ifdef HAVE_SYS_MMAN_H
2591 if (encoding != NULL) {
2593 xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);
2595 xmlDocDumpMemoryEnc(doc, &result, &len, encoding);
2599 xmlDocDumpFormatMemory(doc, &result, &len, 1);
2601 xmlDocDumpMemory(doc, &result, &len);
2603 if (result == NULL) {
2604 fprintf(stderr, "Failed to save\n");
2605 progresult = XMLLINT_ERR_OUT;
2607 write(1, result, len);
2612 #endif /* HAVE_SYS_MMAN_H */
2614 xmlSaveFile(output ? output : "-", doc);
2615 } else if (oldout) {
2616 if (encoding != NULL) {
2618 ret = xmlSaveFormatFileEnc(output ? output : "-", doc,
2622 ret = xmlSaveFileEnc(output ? output : "-", doc,
2626 fprintf(stderr, "failed save to %s\n",
2627 output ? output : "-");
2628 progresult = XMLLINT_ERR_OUT;
2630 } else if (format == 1) {
2631 ret = xmlSaveFormatFile(output ? output : "-", doc, 1);
2633 fprintf(stderr, "failed save to %s\n",
2634 output ? output : "-");
2635 progresult = XMLLINT_ERR_OUT;
2642 out = fopen(output,"wb");
2645 if (xmlDocDump(out, doc) < 0)
2646 progresult = XMLLINT_ERR_OUT;
2651 fprintf(stderr, "failed to open %s\n", output);
2652 progresult = XMLLINT_ERR_OUT;
2656 xmlSaveCtxtPtr ctxt;
2660 saveOpts |= XML_SAVE_FORMAT;
2661 else if (format == 2)
2662 saveOpts |= XML_SAVE_WSNONSIG;
2664 #if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
2666 saveOpts |= XML_SAVE_AS_XML;
2670 ctxt = xmlSaveToFd(1, encoding, saveOpts);
2672 ctxt = xmlSaveToFilename(output, encoding, saveOpts);
2675 if (xmlSaveDoc(ctxt, doc) < 0) {
2676 fprintf(stderr, "failed save to %s\n",
2677 output ? output : "-");
2678 progresult = XMLLINT_ERR_OUT;
2682 progresult = XMLLINT_ERR_OUT;
2685 if ((timing) && (!repeat)) {
2688 #ifdef LIBXML_DEBUG_ENABLED
2694 out = fopen(output,"wb");
2697 xmlDebugDumpDocument(out, doc);
2702 fprintf(stderr, "failed to open %s\n", output);
2703 progresult = XMLLINT_ERR_OUT;
2708 #endif /* LIBXML_OUTPUT_ENABLED */
2710 #ifdef LIBXML_VALID_ENABLED
2712 * A posteriori validation test
2714 if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {
2717 if ((timing) && (!repeat)) {
2720 if (dtdvalid != NULL)
2721 dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
2723 dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL);
2724 if ((timing) && (!repeat)) {
2725 endTimer("Parsing DTD");
2728 if (dtdvalid != NULL)
2729 xmlGenericError(xmlGenericErrorContext,
2730 "Could not parse DTD %s\n", dtdvalid);
2732 xmlGenericError(xmlGenericErrorContext,
2733 "Could not parse DTD %s\n", dtdvalidfpi);
2734 progresult = XMLLINT_ERR_DTD;
2736 xmlValidCtxtPtr cvp;
2738 if ((cvp = xmlNewValidCtxt()) == NULL) {
2739 xmlGenericError(xmlGenericErrorContext,
2740 "Couldn't allocate validation context\n");
2743 cvp->userData = (void *) stderr;
2744 cvp->error = (xmlValidityErrorFunc) fprintf;
2745 cvp->warning = (xmlValidityWarningFunc) fprintf;
2747 if ((timing) && (!repeat)) {
2750 if (!xmlValidateDtd(cvp, doc, dtd)) {
2751 if (dtdvalid != NULL)
2752 xmlGenericError(xmlGenericErrorContext,
2753 "Document %s does not validate against %s\n",
2754 filename, dtdvalid);
2756 xmlGenericError(xmlGenericErrorContext,
2757 "Document %s does not validate against %s\n",
2758 filename, dtdvalidfpi);
2759 progresult = XMLLINT_ERR_VALID;
2761 if ((timing) && (!repeat)) {
2762 endTimer("Validating against DTD");
2764 xmlFreeValidCtxt(cvp);
2767 } else if (postvalid) {
2768 xmlValidCtxtPtr cvp;
2770 if ((cvp = xmlNewValidCtxt()) == NULL) {
2771 xmlGenericError(xmlGenericErrorContext,
2772 "Couldn't allocate validation context\n");
2776 if ((timing) && (!repeat)) {
2779 cvp->userData = (void *) stderr;
2780 cvp->error = (xmlValidityErrorFunc) fprintf;
2781 cvp->warning = (xmlValidityWarningFunc) fprintf;
2782 if (!xmlValidateDocument(cvp, doc)) {
2783 xmlGenericError(xmlGenericErrorContext,
2784 "Document %s does not validate\n", filename);
2785 progresult = XMLLINT_ERR_VALID;
2787 if ((timing) && (!repeat)) {
2788 endTimer("Validating");
2790 xmlFreeValidCtxt(cvp);
2792 #endif /* LIBXML_VALID_ENABLED */
2793 #ifdef LIBXML_SCHEMATRON_ENABLED
2794 if (wxschematron != NULL) {
2795 xmlSchematronValidCtxtPtr ctxt;
2799 if ((timing) && (!repeat)) {
2804 flag = XML_SCHEMATRON_OUT_XML;
2806 flag = XML_SCHEMATRON_OUT_TEXT;
2808 flag |= XML_SCHEMATRON_OUT_QUIET;
2809 ctxt = xmlSchematronNewValidCtxt(wxschematron, flag);
2811 xmlSchematronSetValidErrors(ctxt,
2812 (xmlSchematronValidityErrorFunc) fprintf,
2813 (xmlSchematronValidityWarningFunc) fprintf,
2816 ret = xmlSchematronValidateDoc(ctxt, doc);
2818 fprintf(stderr, "%s validates\n", filename);
2819 } else if (ret > 0) {
2820 fprintf(stderr, "%s fails to validate\n", filename);
2821 progresult = XMLLINT_ERR_VALID;
2823 fprintf(stderr, "%s validation generated an internal error\n",
2825 progresult = XMLLINT_ERR_VALID;
2827 xmlSchematronFreeValidCtxt(ctxt);
2828 if ((timing) && (!repeat)) {
2829 endTimer("Validating");
2833 #ifdef LIBXML_SCHEMAS_ENABLED
2834 if (relaxngschemas != NULL) {
2835 xmlRelaxNGValidCtxtPtr ctxt;
2838 if ((timing) && (!repeat)) {
2842 ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
2843 xmlRelaxNGSetValidErrors(ctxt,
2844 (xmlRelaxNGValidityErrorFunc) fprintf,
2845 (xmlRelaxNGValidityWarningFunc) fprintf,
2847 ret = xmlRelaxNGValidateDoc(ctxt, doc);
2849 fprintf(stderr, "%s validates\n", filename);
2850 } else if (ret > 0) {
2851 fprintf(stderr, "%s fails to validate\n", filename);
2852 progresult = XMLLINT_ERR_VALID;
2854 fprintf(stderr, "%s validation generated an internal error\n",
2856 progresult = XMLLINT_ERR_VALID;
2858 xmlRelaxNGFreeValidCtxt(ctxt);
2859 if ((timing) && (!repeat)) {
2860 endTimer("Validating");
2862 } else if (wxschemas != NULL) {
2863 xmlSchemaValidCtxtPtr ctxt;
2866 if ((timing) && (!repeat)) {
2870 ctxt = xmlSchemaNewValidCtxt(wxschemas);
2871 xmlSchemaSetValidErrors(ctxt,
2872 (xmlSchemaValidityErrorFunc) fprintf,
2873 (xmlSchemaValidityWarningFunc) fprintf,
2875 ret = xmlSchemaValidateDoc(ctxt, doc);
2877 fprintf(stderr, "%s validates\n", filename);
2878 } else if (ret > 0) {
2879 fprintf(stderr, "%s fails to validate\n", filename);
2880 progresult = XMLLINT_ERR_VALID;
2882 fprintf(stderr, "%s validation generated an internal error\n",
2884 progresult = XMLLINT_ERR_VALID;
2886 xmlSchemaFreeValidCtxt(ctxt);
2887 if ((timing) && (!repeat)) {
2888 endTimer("Validating");
2893 #ifdef LIBXML_DEBUG_ENABLED
2894 #if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
2895 if ((debugent) && (!html))
2896 xmlDebugDumpEntities(stderr, doc);
2903 if ((timing) && (!repeat)) {
2907 if ((timing) && (!repeat)) {
2908 endTimer("Freeing");
2912 /************************************************************************
2916 ************************************************************************/
2918 static void showVersion(const char *name) {
2919 fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);
2920 fprintf(stderr, " compiled with: ");
2921 if (xmlHasFeature(XML_WITH_THREAD)) fprintf(stderr, "Threads ");
2922 if (xmlHasFeature(XML_WITH_TREE)) fprintf(stderr, "Tree ");
2923 if (xmlHasFeature(XML_WITH_OUTPUT)) fprintf(stderr, "Output ");
2924 if (xmlHasFeature(XML_WITH_PUSH)) fprintf(stderr, "Push ");
2925 if (xmlHasFeature(XML_WITH_READER)) fprintf(stderr, "Reader ");
2926 if (xmlHasFeature(XML_WITH_PATTERN)) fprintf(stderr, "Patterns ");
2927 if (xmlHasFeature(XML_WITH_WRITER)) fprintf(stderr, "Writer ");
2928 if (xmlHasFeature(XML_WITH_SAX1)) fprintf(stderr, "SAXv1 ");
2929 if (xmlHasFeature(XML_WITH_FTP)) fprintf(stderr, "FTP ");
2930 if (xmlHasFeature(XML_WITH_HTTP)) fprintf(stderr, "HTTP ");
2931 if (xmlHasFeature(XML_WITH_VALID)) fprintf(stderr, "DTDValid ");
2932 if (xmlHasFeature(XML_WITH_HTML)) fprintf(stderr, "HTML ");
2933 if (xmlHasFeature(XML_WITH_LEGACY)) fprintf(stderr, "Legacy ");
2934 if (xmlHasFeature(XML_WITH_C14N)) fprintf(stderr, "C14N ");
2935 if (xmlHasFeature(XML_WITH_CATALOG)) fprintf(stderr, "Catalog ");
2936 if (xmlHasFeature(XML_WITH_XPATH)) fprintf(stderr, "XPath ");
2937 if (xmlHasFeature(XML_WITH_XPTR)) fprintf(stderr, "XPointer ");
2938 if (xmlHasFeature(XML_WITH_XINCLUDE)) fprintf(stderr, "XInclude ");
2939 if (xmlHasFeature(XML_WITH_ICONV)) fprintf(stderr, "Iconv ");
2940 if (xmlHasFeature(XML_WITH_ISO8859X)) fprintf(stderr, "ISO8859X ");
2941 if (xmlHasFeature(XML_WITH_UNICODE)) fprintf(stderr, "Unicode ");
2942 if (xmlHasFeature(XML_WITH_REGEXP)) fprintf(stderr, "Regexps ");
2943 if (xmlHasFeature(XML_WITH_AUTOMATA)) fprintf(stderr, "Automata ");
2944 if (xmlHasFeature(XML_WITH_EXPR)) fprintf(stderr, "Expr ");
2945 if (xmlHasFeature(XML_WITH_SCHEMAS)) fprintf(stderr, "Schemas ");
2946 if (xmlHasFeature(XML_WITH_SCHEMATRON)) fprintf(stderr, "Schematron ");
2947 if (xmlHasFeature(XML_WITH_MODULES)) fprintf(stderr, "Modules ");
2948 if (xmlHasFeature(XML_WITH_DEBUG)) fprintf(stderr, "Debug ");
2949 if (xmlHasFeature(XML_WITH_DEBUG_MEM)) fprintf(stderr, "MemDebug ");
2950 if (xmlHasFeature(XML_WITH_DEBUG_RUN)) fprintf(stderr, "RunDebug ");
2951 if (xmlHasFeature(XML_WITH_ZLIB)) fprintf(stderr, "Zlib ");
2952 fprintf(stderr, "\n");
2955 static void usage(const char *name) {
2956 printf("Usage : %s [options] XMLfiles ...\n", name);
2957 #ifdef LIBXML_OUTPUT_ENABLED
2958 printf("\tParse the XML files and output the result of the parsing\n");
2960 printf("\tParse the XML files\n");
2961 #endif /* LIBXML_OUTPUT_ENABLED */
2962 printf("\t--version : display the version of the XML library used\n");
2963 #ifdef LIBXML_DEBUG_ENABLED
2964 printf("\t--debug : dump a debug tree of the in-memory document\n");
2965 printf("\t--shell : run a navigating shell\n");
2966 printf("\t--debugent : debug the entities defined in the document\n");
2968 #ifdef LIBXML_READER_ENABLED
2969 printf("\t--debug : dump the nodes content when using --stream\n");
2970 #endif /* LIBXML_READER_ENABLED */
2972 #ifdef LIBXML_TREE_ENABLED
2973 printf("\t--copy : used to test the internal copy implementation\n");
2974 #endif /* LIBXML_TREE_ENABLED */
2975 printf("\t--recover : output what was parsable on broken XML documents\n");
2976 printf("\t--huge : remove any internal arbitrary parser limits\n");
2977 printf("\t--noent : substitute entity references by their value\n");
2978 printf("\t--noout : don't output the result tree\n");
2979 printf("\t--path 'paths' : provide a set of paths for resources\n");
2980 printf("\t--load-trace : print trace of all external entites loaded\n");
2981 printf("\t--nonet : refuse to fetch DTDs or entities over network\n");
2982 printf("\t--nocompact : do not generate compact text nodes\n");
2983 printf("\t--htmlout : output results as HTML\n");
2984 printf("\t--nowrap : do not put HTML doc wrapper\n");
2985 #ifdef LIBXML_VALID_ENABLED
2986 printf("\t--valid : validate the document in addition to std well-formed check\n");
2987 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
2988 printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
2989 printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
2990 #endif /* LIBXML_VALID_ENABLED */
2991 printf("\t--timing : print some timings\n");
2992 printf("\t--output file or -o file: save to a given file\n");
2993 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
2994 printf("\t--insert : ad-hoc test for valid insertions\n");
2995 #ifdef LIBXML_OUTPUT_ENABLED
2997 printf("\t--compress : turn on gzip compression of output\n");
2999 #endif /* LIBXML_OUTPUT_ENABLED */
3000 #ifdef LIBXML_HTML_ENABLED
3001 printf("\t--html : use the HTML parser\n");
3002 printf("\t--xmlout : force to use the XML serializer when using --html\n");
3003 printf("\t--nodefdtd : do not default HTML doctype\n");
3005 #ifdef LIBXML_PUSH_ENABLED
3006 printf("\t--push : use the push mode of the parser\n");
3007 #endif /* LIBXML_PUSH_ENABLED */
3008 #ifdef HAVE_SYS_MMAN_H
3009 printf("\t--memory : parse from memory\n");
3011 printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
3012 printf("\t--nowarning : do not emit warnings from parser/validator\n");
3013 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
3014 printf("\t--nocdata : replace cdata section with text nodes\n");
3015 #ifdef LIBXML_OUTPUT_ENABLED
3016 printf("\t--format : reformat/reindent the input\n");
3017 printf("\t--encode encoding : output in the given encoding\n");
3018 printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
3019 printf("\t--pretty STYLE : pretty-print in a particular style\n");
3020 printf("\t 0 Do not pretty print\n");
3021 printf("\t 1 Format the XML content, as --format\n");
3022 printf("\t 2 Add whitespace inside tags, preserving content\n");
3023 #endif /* LIBXML_OUTPUT_ENABLED */
3024 printf("\t--c14n : save in W3C canonical format v1.0 (with comments)\n");
3025 printf("\t--c14n11 : save in W3C canonical format v1.1 (with comments)\n");
3026 printf("\t--exc-c14n : save in W3C exclusive canonical format (with comments)\n");
3027 #ifdef LIBXML_C14N_ENABLED
3028 #endif /* LIBXML_C14N_ENABLED */
3029 printf("\t--nsclean : remove redundant namespace declarations\n");
3030 printf("\t--testIO : test user I/O support\n");
3031 #ifdef LIBXML_CATALOG_ENABLED
3032 printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
3033 printf("\t otherwise XML Catalogs starting from \n");
3034 printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
3035 printf("\t--nocatalogs : deactivate all catalogs\n");
3037 printf("\t--auto : generate a small doc on the fly\n");
3038 #ifdef LIBXML_XINCLUDE_ENABLED
3039 printf("\t--xinclude : do XInclude processing\n");
3040 printf("\t--noxincludenode : same but do not generate XInclude nodes\n");
3041 printf("\t--nofixup-base-uris : do not fixup xml:base uris\n");
3043 printf("\t--loaddtd : fetch external DTD\n");
3044 printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
3045 #ifdef LIBXML_READER_ENABLED
3046 printf("\t--stream : use the streaming interface to process very large files\n");
3047 printf("\t--walker : create a reader and walk though the resulting doc\n");
3048 #endif /* LIBXML_READER_ENABLED */
3049 #ifdef LIBXML_PATTERN_ENABLED
3050 printf("\t--pattern pattern_value : test the pattern support\n");
3052 printf("\t--chkregister : verify the node registration code\n");
3053 #ifdef LIBXML_SCHEMAS_ENABLED
3054 printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
3055 printf("\t--schema schema : do validation against the WXS schema\n");
3057 #ifdef LIBXML_SCHEMATRON_ENABLED
3058 printf("\t--schematron schema : do validation against a schematron\n");
3060 #ifdef LIBXML_SAX1_ENABLED
3061 printf("\t--sax1: use the old SAX1 interfaces for processing\n");
3063 printf("\t--sax: do not build a tree but work just at the SAX level\n");
3064 printf("\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n");
3065 #ifdef LIBXML_XPATH_ENABLED
3066 printf("\t--xpath expr: evaluate the XPath expression, inply --noout\n");
3069 printf("\nLibxml project home page: http://xmlsoft.org/\n");
3070 printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
3073 static void registerNode(xmlNodePtr node)
3075 node->_private = malloc(sizeof(long));
3076 *(long*)node->_private = (long) 0x81726354;
3080 static void deregisterNode(xmlNodePtr node)
3082 assert(node->_private != NULL);
3083 assert(*(long*)node->_private == (long) 0x81726354);
3084 free(node->_private);
3089 main(int argc, char **argv) {
3100 for (i = 1; i < argc ; i++) {
3101 if (!strcmp(argv[i], "-"))
3104 if (argv[i][0] != '-')
3106 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
3109 #ifdef LIBXML_DEBUG_ENABLED
3110 if ((!strcmp(argv[i], "-shell")) ||
3111 (!strcmp(argv[i], "--shell"))) {
3116 #ifdef LIBXML_TREE_ENABLED
3117 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
3120 #endif /* LIBXML_TREE_ENABLED */
3121 if ((!strcmp(argv[i], "-recover")) ||
3122 (!strcmp(argv[i], "--recover"))) {
3124 options |= XML_PARSE_RECOVER;
3125 } else if ((!strcmp(argv[i], "-huge")) ||
3126 (!strcmp(argv[i], "--huge"))) {
3127 options |= XML_PARSE_HUGE;
3128 } else if ((!strcmp(argv[i], "-noent")) ||
3129 (!strcmp(argv[i], "--noent"))) {
3131 options |= XML_PARSE_NOENT;
3132 } else if ((!strcmp(argv[i], "-nsclean")) ||
3133 (!strcmp(argv[i], "--nsclean"))) {
3134 options |= XML_PARSE_NSCLEAN;
3135 } else if ((!strcmp(argv[i], "-nocdata")) ||
3136 (!strcmp(argv[i], "--nocdata"))) {
3137 options |= XML_PARSE_NOCDATA;
3138 } else if ((!strcmp(argv[i], "-nodict")) ||
3139 (!strcmp(argv[i], "--nodict"))) {
3140 options |= XML_PARSE_NODICT;
3141 } else if ((!strcmp(argv[i], "-version")) ||
3142 (!strcmp(argv[i], "--version"))) {
3143 showVersion(argv[0]);
3145 } else if ((!strcmp(argv[i], "-noout")) ||
3146 (!strcmp(argv[i], "--noout")))
3148 #ifdef LIBXML_OUTPUT_ENABLED
3149 else if ((!strcmp(argv[i], "-o")) ||
3150 (!strcmp(argv[i], "-output")) ||
3151 (!strcmp(argv[i], "--output"))) {
3155 #endif /* LIBXML_OUTPUT_ENABLED */
3156 else if ((!strcmp(argv[i], "-htmlout")) ||
3157 (!strcmp(argv[i], "--htmlout")))
3159 else if ((!strcmp(argv[i], "-nowrap")) ||
3160 (!strcmp(argv[i], "--nowrap")))
3162 #ifdef LIBXML_HTML_ENABLED
3163 else if ((!strcmp(argv[i], "-html")) ||
3164 (!strcmp(argv[i], "--html"))) {
3167 else if ((!strcmp(argv[i], "-xmlout")) ||
3168 (!strcmp(argv[i], "--xmlout"))) {
3170 } else if ((!strcmp(argv[i], "-nodefdtd")) ||
3171 (!strcmp(argv[i], "--nodefdtd"))) {
3173 options |= HTML_PARSE_NODEFDTD;
3175 #endif /* LIBXML_HTML_ENABLED */
3176 else if ((!strcmp(argv[i], "-loaddtd")) ||
3177 (!strcmp(argv[i], "--loaddtd"))) {
3179 options |= XML_PARSE_DTDLOAD;
3180 } else if ((!strcmp(argv[i], "-dtdattr")) ||
3181 (!strcmp(argv[i], "--dtdattr"))) {
3184 options |= XML_PARSE_DTDATTR;
3186 #ifdef LIBXML_VALID_ENABLED
3187 else if ((!strcmp(argv[i], "-valid")) ||
3188 (!strcmp(argv[i], "--valid"))) {
3190 options |= XML_PARSE_DTDVALID;
3191 } else if ((!strcmp(argv[i], "-postvalid")) ||
3192 (!strcmp(argv[i], "--postvalid"))) {
3195 options |= XML_PARSE_DTDLOAD;
3196 } else if ((!strcmp(argv[i], "-dtdvalid")) ||
3197 (!strcmp(argv[i], "--dtdvalid"))) {
3201 options |= XML_PARSE_DTDLOAD;
3202 } else if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
3203 (!strcmp(argv[i], "--dtdvalidfpi"))) {
3205 dtdvalidfpi = argv[i];
3207 options |= XML_PARSE_DTDLOAD;
3209 #endif /* LIBXML_VALID_ENABLED */
3210 else if ((!strcmp(argv[i], "-dropdtd")) ||
3211 (!strcmp(argv[i], "--dropdtd")))
3213 else if ((!strcmp(argv[i], "-insert")) ||
3214 (!strcmp(argv[i], "--insert")))
3216 else if ((!strcmp(argv[i], "-timing")) ||
3217 (!strcmp(argv[i], "--timing")))
3219 else if ((!strcmp(argv[i], "-auto")) ||
3220 (!strcmp(argv[i], "--auto")))
3222 else if ((!strcmp(argv[i], "-repeat")) ||
3223 (!strcmp(argv[i], "--repeat"))) {
3229 #ifdef LIBXML_PUSH_ENABLED
3230 else if ((!strcmp(argv[i], "-push")) ||
3231 (!strcmp(argv[i], "--push")))
3233 #endif /* LIBXML_PUSH_ENABLED */
3234 #ifdef HAVE_SYS_MMAN_H
3235 else if ((!strcmp(argv[i], "-memory")) ||
3236 (!strcmp(argv[i], "--memory")))
3239 else if ((!strcmp(argv[i], "-testIO")) ||
3240 (!strcmp(argv[i], "--testIO")))
3242 #ifdef LIBXML_XINCLUDE_ENABLED
3243 else if ((!strcmp(argv[i], "-xinclude")) ||
3244 (!strcmp(argv[i], "--xinclude"))) {
3246 options |= XML_PARSE_XINCLUDE;
3248 else if ((!strcmp(argv[i], "-noxincludenode")) ||
3249 (!strcmp(argv[i], "--noxincludenode"))) {
3251 options |= XML_PARSE_XINCLUDE;
3252 options |= XML_PARSE_NOXINCNODE;
3254 else if ((!strcmp(argv[i], "-nofixup-base-uris")) ||
3255 (!strcmp(argv[i], "--nofixup-base-uris"))) {
3257 options |= XML_PARSE_XINCLUDE;
3258 options |= XML_PARSE_NOBASEFIX;
3261 #ifdef LIBXML_OUTPUT_ENABLED
3263 else if ((!strcmp(argv[i], "-compress")) ||
3264 (!strcmp(argv[i], "--compress"))) {
3266 xmlSetCompressMode(9);
3269 #endif /* LIBXML_OUTPUT_ENABLED */
3270 else if ((!strcmp(argv[i], "-nowarning")) ||
3271 (!strcmp(argv[i], "--nowarning"))) {
3272 xmlGetWarningsDefaultValue = 0;
3273 xmlPedanticParserDefault(0);
3274 options |= XML_PARSE_NOWARNING;
3276 else if ((!strcmp(argv[i], "-pedantic")) ||
3277 (!strcmp(argv[i], "--pedantic"))) {
3278 xmlGetWarningsDefaultValue = 1;
3279 xmlPedanticParserDefault(1);
3280 options |= XML_PARSE_PEDANTIC;
3282 #ifdef LIBXML_DEBUG_ENABLED
3283 else if ((!strcmp(argv[i], "-debugent")) ||
3284 (!strcmp(argv[i], "--debugent"))) {
3286 xmlParserDebugEntities = 1;
3289 #ifdef LIBXML_C14N_ENABLED
3290 else if ((!strcmp(argv[i], "-c14n")) ||
3291 (!strcmp(argv[i], "--c14n"))) {
3293 options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD;
3295 else if ((!strcmp(argv[i], "-c14n11")) ||
3296 (!strcmp(argv[i], "--c14n11"))) {
3298 options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD;
3300 else if ((!strcmp(argv[i], "-exc-c14n")) ||
3301 (!strcmp(argv[i], "--exc-c14n"))) {
3303 options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD;
3306 #ifdef LIBXML_CATALOG_ENABLED
3307 else if ((!strcmp(argv[i], "-catalogs")) ||
3308 (!strcmp(argv[i], "--catalogs"))) {
3310 } else if ((!strcmp(argv[i], "-nocatalogs")) ||
3311 (!strcmp(argv[i], "--nocatalogs"))) {
3315 else if ((!strcmp(argv[i], "-encode")) ||
3316 (!strcmp(argv[i], "--encode"))) {
3320 * OK it's for testing purposes
3322 xmlAddEncodingAlias("UTF-8", "DVEnc");
3324 else if ((!strcmp(argv[i], "-noblanks")) ||
3325 (!strcmp(argv[i], "--noblanks"))) {
3327 xmlKeepBlanksDefault(0);
3329 else if ((!strcmp(argv[i], "-maxmem")) ||
3330 (!strcmp(argv[i], "--maxmem"))) {
3332 if (sscanf(argv[i], "%d", &maxmem) == 1) {
3333 xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc,
3339 else if ((!strcmp(argv[i], "-format")) ||
3340 (!strcmp(argv[i], "--format"))) {
3342 #ifdef LIBXML_OUTPUT_ENABLED
3344 #endif /* LIBXML_OUTPUT_ENABLED */
3345 xmlKeepBlanksDefault(0);
3347 else if ((!strcmp(argv[i], "-pretty")) ||
3348 (!strcmp(argv[i], "--pretty"))) {
3350 #ifdef LIBXML_OUTPUT_ENABLED
3351 format = atoi(argv[i]);
3352 #endif /* LIBXML_OUTPUT_ENABLED */
3355 xmlKeepBlanksDefault(0);
3358 #ifdef LIBXML_READER_ENABLED
3359 else if ((!strcmp(argv[i], "-stream")) ||
3360 (!strcmp(argv[i], "--stream"))) {
3363 else if ((!strcmp(argv[i], "-walker")) ||
3364 (!strcmp(argv[i], "--walker"))) {
3368 #endif /* LIBXML_READER_ENABLED */
3369 #ifdef LIBXML_SAX1_ENABLED
3370 else if ((!strcmp(argv[i], "-sax1")) ||
3371 (!strcmp(argv[i], "--sax1"))) {
3373 options |= XML_PARSE_SAX1;
3375 #endif /* LIBXML_SAX1_ENABLED */
3376 else if ((!strcmp(argv[i], "-sax")) ||
3377 (!strcmp(argv[i], "--sax"))) {
3380 else if ((!strcmp(argv[i], "-chkregister")) ||
3381 (!strcmp(argv[i], "--chkregister"))) {
3383 #ifdef LIBXML_SCHEMAS_ENABLED
3384 } else if ((!strcmp(argv[i], "-relaxng")) ||
3385 (!strcmp(argv[i], "--relaxng"))) {
3389 options |= XML_PARSE_NOENT;
3390 } else if ((!strcmp(argv[i], "-schema")) ||
3391 (!strcmp(argv[i], "--schema"))) {
3396 #ifdef LIBXML_SCHEMATRON_ENABLED
3397 } else if ((!strcmp(argv[i], "-schematron")) ||
3398 (!strcmp(argv[i], "--schematron"))) {
3400 schematron = argv[i];
3403 } else if ((!strcmp(argv[i], "-nonet")) ||
3404 (!strcmp(argv[i], "--nonet"))) {
3405 options |= XML_PARSE_NONET;
3406 xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
3407 } else if ((!strcmp(argv[i], "-nocompact")) ||
3408 (!strcmp(argv[i], "--nocompact"))) {
3409 options &= ~XML_PARSE_COMPACT;
3410 } else if ((!strcmp(argv[i], "-load-trace")) ||
3411 (!strcmp(argv[i], "--load-trace"))) {
3413 } else if ((!strcmp(argv[i], "-path")) ||
3414 (!strcmp(argv[i], "--path"))) {
3416 parsePath(BAD_CAST argv[i]);
3417 #ifdef LIBXML_PATTERN_ENABLED
3418 } else if ((!strcmp(argv[i], "-pattern")) ||
3419 (!strcmp(argv[i], "--pattern"))) {
3423 #ifdef LIBXML_XPATH_ENABLED
3424 } else if ((!strcmp(argv[i], "-xpath")) ||
3425 (!strcmp(argv[i], "--xpath"))) {
3428 xpathquery = argv[i];
3430 } else if ((!strcmp(argv[i], "-oldxml10")) ||
3431 (!strcmp(argv[i], "--oldxml10"))) {
3433 options |= XML_PARSE_OLD10;
3435 fprintf(stderr, "Unknown option %s\n", argv[i]);
3441 #ifdef LIBXML_CATALOG_ENABLED
3442 if (nocatalogs == 0) {
3446 catal = getenv("SGML_CATALOG_FILES");
3447 if (catal != NULL) {
3448 xmlLoadCatalogs(catal);
3450 fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
3456 #ifdef LIBXML_SAX1_ENABLED
3458 xmlSAXDefaultVersion(1);
3460 xmlSAXDefaultVersion(2);
3461 #endif /* LIBXML_SAX1_ENABLED */
3464 xmlRegisterNodeDefault(registerNode);
3465 xmlDeregisterNodeDefault(deregisterNode);
3468 indent = getenv("XMLLINT_INDENT");
3469 if(indent != NULL) {
3470 xmlTreeIndentString = indent;
3474 defaultEntityLoader = xmlGetExternalEntityLoader();
3475 xmlSetExternalEntityLoader(xmllintExternalEntityLoader);
3477 xmlLineNumbersDefault(1);
3479 xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
3481 xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
3482 if (noent != 0) xmlSubstituteEntitiesDefault(1);
3483 #ifdef LIBXML_VALID_ENABLED
3484 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
3485 #endif /* LIBXML_VALID_ENABLED */
3486 if ((htmlout) && (!nowrap)) {
3487 xmlGenericError(xmlGenericErrorContext,
3488 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
3489 xmlGenericError(xmlGenericErrorContext,
3490 "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
3491 xmlGenericError(xmlGenericErrorContext,
3492 "<html><head><title>%s output</title></head>\n",
3494 xmlGenericError(xmlGenericErrorContext,
3495 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
3499 #ifdef LIBXML_SCHEMATRON_ENABLED
3500 if ((schematron != NULL) && (sax == 0)
3501 #ifdef LIBXML_READER_ENABLED
3503 #endif /* LIBXML_READER_ENABLED */
3505 xmlSchematronParserCtxtPtr ctxt;
3507 /* forces loading the DTDs */
3508 xmlLoadExtDtdDefaultValue |= 1;
3509 options |= XML_PARSE_DTDLOAD;
3513 ctxt = xmlSchematronNewParserCtxt(schematron);
3515 xmlSchematronSetParserErrors(ctxt,
3516 (xmlSchematronValidityErrorFunc) fprintf,
3517 (xmlSchematronValidityWarningFunc) fprintf,
3520 wxschematron = xmlSchematronParse(ctxt);
3521 if (wxschematron == NULL) {
3522 xmlGenericError(xmlGenericErrorContext,
3523 "Schematron schema %s failed to compile\n", schematron);
3524 progresult = XMLLINT_ERR_SCHEMACOMP;
3527 xmlSchematronFreeParserCtxt(ctxt);
3529 endTimer("Compiling the schemas");
3533 #ifdef LIBXML_SCHEMAS_ENABLED
3534 if ((relaxng != NULL) && (sax == 0)
3535 #ifdef LIBXML_READER_ENABLED
3537 #endif /* LIBXML_READER_ENABLED */
3539 xmlRelaxNGParserCtxtPtr ctxt;
3541 /* forces loading the DTDs */
3542 xmlLoadExtDtdDefaultValue |= 1;
3543 options |= XML_PARSE_DTDLOAD;
3547 ctxt = xmlRelaxNGNewParserCtxt(relaxng);
3548 xmlRelaxNGSetParserErrors(ctxt,
3549 (xmlRelaxNGValidityErrorFunc) fprintf,
3550 (xmlRelaxNGValidityWarningFunc) fprintf,
3552 relaxngschemas = xmlRelaxNGParse(ctxt);
3553 if (relaxngschemas == NULL) {
3554 xmlGenericError(xmlGenericErrorContext,
3555 "Relax-NG schema %s failed to compile\n", relaxng);
3556 progresult = XMLLINT_ERR_SCHEMACOMP;
3559 xmlRelaxNGFreeParserCtxt(ctxt);
3561 endTimer("Compiling the schemas");
3563 } else if ((schema != NULL)
3564 #ifdef LIBXML_READER_ENABLED
3568 xmlSchemaParserCtxtPtr ctxt;
3573 ctxt = xmlSchemaNewParserCtxt(schema);
3574 xmlSchemaSetParserErrors(ctxt,
3575 (xmlSchemaValidityErrorFunc) fprintf,
3576 (xmlSchemaValidityWarningFunc) fprintf,
3578 wxschemas = xmlSchemaParse(ctxt);
3579 if (wxschemas == NULL) {
3580 xmlGenericError(xmlGenericErrorContext,
3581 "WXS schema %s failed to compile\n", schema);
3582 progresult = XMLLINT_ERR_SCHEMACOMP;
3585 xmlSchemaFreeParserCtxt(ctxt);
3587 endTimer("Compiling the schemas");
3590 #endif /* LIBXML_SCHEMAS_ENABLED */
3591 #ifdef LIBXML_PATTERN_ENABLED
3592 if ((pattern != NULL)
3593 #ifdef LIBXML_READER_ENABLED
3597 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
3598 if (patternc == NULL) {
3599 xmlGenericError(xmlGenericErrorContext,
3600 "Pattern %s failed to compile\n", pattern);
3601 progresult = XMLLINT_ERR_SCHEMAPAT;
3605 #endif /* LIBXML_PATTERN_ENABLED */
3606 for (i = 1; i < argc ; i++) {
3607 if ((!strcmp(argv[i], "-encode")) ||
3608 (!strcmp(argv[i], "--encode"))) {
3611 } else if ((!strcmp(argv[i], "-o")) ||
3612 (!strcmp(argv[i], "-output")) ||
3613 (!strcmp(argv[i], "--output"))) {
3617 #ifdef LIBXML_VALID_ENABLED
3618 if ((!strcmp(argv[i], "-dtdvalid")) ||
3619 (!strcmp(argv[i], "--dtdvalid"))) {
3623 if ((!strcmp(argv[i], "-path")) ||
3624 (!strcmp(argv[i], "--path"))) {
3628 if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
3629 (!strcmp(argv[i], "--dtdvalidfpi"))) {
3633 #endif /* LIBXML_VALID_ENABLED */
3634 if ((!strcmp(argv[i], "-relaxng")) ||
3635 (!strcmp(argv[i], "--relaxng"))) {
3639 if ((!strcmp(argv[i], "-maxmem")) ||
3640 (!strcmp(argv[i], "--maxmem"))) {
3644 if ((!strcmp(argv[i], "-pretty")) ||
3645 (!strcmp(argv[i], "--pretty"))) {
3649 if ((!strcmp(argv[i], "-schema")) ||
3650 (!strcmp(argv[i], "--schema"))) {
3654 if ((!strcmp(argv[i], "-schematron")) ||
3655 (!strcmp(argv[i], "--schematron"))) {
3659 #ifdef LIBXML_PATTERN_ENABLED
3660 if ((!strcmp(argv[i], "-pattern")) ||
3661 (!strcmp(argv[i], "--pattern"))) {
3666 #ifdef LIBXML_XPATH_ENABLED
3667 if ((!strcmp(argv[i], "-xpath")) ||
3668 (!strcmp(argv[i], "--xpath"))) {
3673 if ((timing) && (repeat))
3675 /* Remember file names. "-" means stdin. <sven@zen.org> */
3676 if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
3678 xmlParserCtxtPtr ctxt = NULL;
3680 for (acount = 0;acount < repeat;acount++) {
3681 #ifdef LIBXML_READER_ENABLED
3683 streamFile(argv[i]);
3685 #endif /* LIBXML_READER_ENABLED */
3690 ctxt = xmlNewParserCtxt();
3691 parseAndPrintFile(argv[i], ctxt);
3693 #ifdef LIBXML_READER_ENABLED
3695 #endif /* LIBXML_READER_ENABLED */
3698 xmlFreeParserCtxt(ctxt);
3702 #ifdef LIBXML_READER_ENABLED
3704 streamFile(argv[i]);
3706 #endif /* LIBXML_READER_ENABLED */
3710 parseAndPrintFile(argv[i], NULL);
3713 if ((chkregister) && (nbregister != 0)) {
3714 fprintf(stderr, "Registration count off: %d\n", nbregister);
3715 progresult = XMLLINT_ERR_RDREGIS;
3719 if ((timing) && (repeat)) {
3720 endTimer("%d iterations", repeat);
3725 parseAndPrintFile(NULL, NULL);
3726 if ((htmlout) && (!nowrap)) {
3727 xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
3729 if ((files == 0) && (!generate) && (version == 0)) {
3732 #ifdef LIBXML_SCHEMATRON_ENABLED
3733 if (wxschematron != NULL)
3734 xmlSchematronFree(wxschematron);
3736 #ifdef LIBXML_SCHEMAS_ENABLED
3737 if (relaxngschemas != NULL)
3738 xmlRelaxNGFree(relaxngschemas);
3739 if (wxschemas != NULL)
3740 xmlSchemaFree(wxschemas);
3741 xmlRelaxNGCleanupTypes();
3743 #ifdef LIBXML_PATTERN_ENABLED
3744 if (patternc != NULL)
3745 xmlFreePattern(patternc);