int xml_validate(struct xml_node_ctx *ctx, xml_node_t *node, const char *xml_schema_fname, char **ret_err) { xmlDocPtr doc; xmlNodePtr n; xmlSchemaParserCtxtPtr pctx; xmlSchemaValidCtxtPtr vctx; xmlSchemaPtr schema; int ret; struct str_buf errors; if (ret_err) *ret_err = NULL; doc = xmlNewDoc((xmlChar *) "1.0"); if (doc == NULL) return -1; n = xmlDocCopyNode((xmlNodePtr) node, doc, 1); if (n == NULL) { xmlFreeDoc(doc); return -1; } xmlDocSetRootElement(doc, n); os_memset(&errors, 0, sizeof(errors)); pctx = xmlSchemaNewParserCtxt(xml_schema_fname); xmlSchemaSetParserErrors(pctx, (xmlSchemaValidityErrorFunc) add_str, (xmlSchemaValidityWarningFunc) add_str, &errors); schema = xmlSchemaParse(pctx); xmlSchemaFreeParserCtxt(pctx); vctx = xmlSchemaNewValidCtxt(schema); xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) add_str, (xmlSchemaValidityWarningFunc) add_str, &errors); ret = xmlSchemaValidateDoc(vctx, doc); xmlSchemaFreeValidCtxt(vctx); xmlFreeDoc(doc); xmlSchemaFree(schema); if (ret == 0) { os_free(errors.buf); return 0; } else if (ret > 0) { if (ret_err) *ret_err = errors.buf; else os_free(errors.buf); return -1; } else { if (ret_err) *ret_err = errors.buf; else os_free(errors.buf); return -1; } }
/** * Initializes the libxml2 parser. * @param dtd_filename - path to the DTD or NULL if none * @param xsd_filename - path to the XSD or NULL if none * @returns 1 on success or 0 on error */ int parser_init(char *dtd_filename, char *xsd_filename) { if (dtd_filename){ dtd = xmlParseDTD(NULL,(unsigned char*)dtd_filename); if (!dtd){ LM_ERR("unsuccesful DTD parsing from file <%s>\n", dtd_filename); return 0; } dtdCtxt = xmlNewValidCtxt(); dtdCtxt->userData = (void*)stderr; dtdCtxt->error = (xmlValidityErrorFunc) fprintf; dtdCtxt->warning = (xmlValidityWarningFunc) fprintf; } if (xsd_filename){ xmlSchemaParserCtxtPtr ctxt; ctxt = xmlSchemaNewParserCtxt(xsd_filename); if (!ctxt) { LM_ERR("unsuccesful XSD parsing from file <%s>\n", xsd_filename); return 0; } xmlSchemaSetParserErrors(ctxt,(xmlValidityErrorFunc) fprintf,(xmlValidityWarningFunc) fprintf,stderr); xsd = xmlSchemaParse(ctxt); xmlSchemaFreeParserCtxt(ctxt); xsdCtxt = xmlSchemaNewValidCtxt(xsd); xmlSchemaSetValidErrors(xsdCtxt,(xmlValidityErrorFunc) fprintf,(xmlValidityWarningFunc) fprintf,stderr); } ctxtInit=1; return 1; }
static CPLXMLSchemaPtr CPLLoadXMLSchema(const char* pszXSDFilename) { char* pszStr = CPLLoadSchemaStr(pszXSDFilename); if (pszStr == NULL) return NULL; xmlExternalEntityLoader pfnLibXMLOldExtranerEntityLoaderLocal = NULL; pfnLibXMLOldExtranerEntityLoaderLocal = xmlGetExternalEntityLoader(); pfnLibXMLOldExtranerEntityLoader = pfnLibXMLOldExtranerEntityLoaderLocal; xmlSetExternalEntityLoader(CPLExternalEntityLoader); xmlSchemaParserCtxtPtr pSchemaParserCtxt = xmlSchemaNewMemParserCtxt(pszStr, static_cast<int>(strlen(pszStr))); xmlSchemaSetParserErrors(pSchemaParserCtxt, CPLLibXMLWarningErrorCallback, CPLLibXMLWarningErrorCallback, NULL); xmlSchemaPtr pSchema = xmlSchemaParse(pSchemaParserCtxt); xmlSchemaFreeParserCtxt(pSchemaParserCtxt); xmlSetExternalEntityLoader(pfnLibXMLOldExtranerEntityLoaderLocal); CPLFree(pszStr); return (CPLXMLSchemaPtr) pSchema; }
static inline xmlSchemaPtr Schema_parse(xmlSchemaParserCtxtPtr spctx) { TRACE("(%p)\n", spctx); xmlSchemaSetParserErrors(spctx, parser_error, parser_warning, NULL); #ifdef HAVE_XMLSCHEMASSETPARSERSTRUCTUREDERRORS xmlSchemaSetParserStructuredErrors(spctx, parser_serror, NULL); #endif return xmlSchemaParse(spctx); }
static bool CPLHasLibXMLBug() { if (bHasLibXMLBug >= 0) return CPL_TO_BOOL(bHasLibXMLBug); static const char szLibXMLBugTester[] = "<schema targetNamespace=\"http://foo\" xmlns:foo=\"http://foo\" xmlns=\"http://www.w3.org/2001/XMLSchema\">" "<simpleType name=\"t1\">" "<list itemType=\"double\"/>" "</simpleType>" "<complexType name=\"t2\">" "<simpleContent>" "<extension base=\"foo:t1\"/>" "</simpleContent>" "</complexType>" "<complexType name=\"t3\">" "<simpleContent>" "<restriction base=\"foo:t2\">" "<length value=\"2\"/>" "</restriction>" "</simpleContent>" "</complexType>" "</schema>"; xmlSchemaParserCtxtPtr pSchemaParserCtxt; xmlSchemaPtr pSchema; pSchemaParserCtxt = xmlSchemaNewMemParserCtxt(szLibXMLBugTester, strlen(szLibXMLBugTester)); xmlSchemaSetParserErrors(pSchemaParserCtxt, CPLHasLibXMLBugWarningCallback, CPLHasLibXMLBugWarningCallback, NULL); pSchema = xmlSchemaParse(pSchemaParserCtxt); xmlSchemaFreeParserCtxt(pSchemaParserCtxt); bHasLibXMLBug = (pSchema == NULL); if (pSchema) xmlSchemaFree(pSchema); if (bHasLibXMLBug) { CPLDebug("CPL", "LibXML bug found (cf https://bugzilla.gnome.org/show_bug.cgi?id=630130). " "Will try to workaround for GML schemas."); } return CPL_TO_BOOL(bHasLibXMLBug); }
void validateDoc(xmlDocPtr doc, std::string baseUri, std::string schemaFile) { xmlSchemaParserCtxtPtr ctx = xmlSchemaNewParserCtxt(schemaFile.c_str()); if (ctx) { xmlSchemaSetParserErrors(ctx,(xmlSchemaValidityErrorFunc)errorHandler,(xmlSchemaValidityWarningFunc)warningHandler,nullptr); xmlSchemaPtr schema = xmlSchemaParse(ctx); xmlSchemaFreeParserCtxt(ctx); // validate xmlSchemaValidCtxtPtr vctx = xmlSchemaNewValidCtxt(schema); xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc)errorHandler, (xmlSchemaValidityErrorFunc)warningHandler,nullptr); int ret = xmlSchemaValidateDoc(vctx, doc); xmlSchemaFreeValidCtxt(vctx); xmlSchemaFree(schema); if (ret != 0) { THROW_EXC("xml file '" << baseUri << "' is not valid"); } } }
void CLibXmlValidator::validate() { if (!xmlFile.length() && !xml.length()) throw MakeStringException(XMLERR_MissingSource, "Source XML not provided"); if (!xsdFile.length() && !xsd.length()) throw MakeStringException(XMLERR_MissingSource, "XML Schema not provided"); xmlParserInputBufferPtr input; if (xmlFile.length()) input = xmlParserInputBufferCreateFilename(xmlFile.get(), XML_CHAR_ENCODING_NONE); else input = xmlParserInputBufferCreateMem(xml.str(), xml.length()+1, XML_CHAR_ENCODING_NONE); if (!input) throw MakeStringException(XMLERR_InvalidXml, "Failed to create XML input stream"); xmlSchemaParserCtxtPtr xsdParser; if (xsdFile.length()) xsdParser = xmlSchemaNewParserCtxt(xsdFile.get()); else xsdParser = xmlSchemaNewMemParserCtxt(xsd.str(), xsd.length()); if (!xsdParser) throw MakeStringException(XMLERR_InvalidXsd, "Failed to load XML Schema"); xmlSchemaSetParserErrors(xsdParser, libxmlXsdErrorMsgHandler, libxmlXsdErrorMsgHandler, this); xmlSchemaPtr schema = xmlSchemaParse(xsdParser); xmlSchemaFreeParserCtxt(xsdParser); if (!schema) throw MakeStringException(XMLERR_InvalidXsd, "XSD schema parsing failed"); xmlSchemaValidCtxtPtr validator = xmlSchemaNewValidCtxt(schema); xmlSchemaSetValidErrors(validator, libxmlXsdErrorMsgHandler, libxmlXsdErrorMsgHandler, this); int ret = xmlSchemaValidateStream(validator, input, XML_CHAR_ENCODING_NONE, emptySAXHandler, (void *)this); if (ret != 0) { ensureExceptions()->append(*MakeStringException(XMLERR_XsdValidationFailed, "XML validation failed")); throw exceptions.getClear(); } xmlSchemaFreeValidCtxt(validator); }
/* ************************************************** */ int do_configuration(void) { xmlSchemaValidCtxtPtr sv_ctxt = NULL; xmlSchemaParserCtxtPtr sp_ctxt = NULL; xmlSchemaPtr schema = NULL; xmlParserCtxtPtr p_ctxt = NULL; xmlDocPtr doc = NULL; xmlXPathContextPtr xp_ctx = NULL; xmlXPathObjectPtr simul_xobj = NULL; xmlXPathObjectPtr entity_xobj = NULL; xmlXPathObjectPtr environment_xobj = NULL; xmlXPathObjectPtr bundle_xobj = NULL; xmlXPathObjectPtr node_xobj = NULL; xmlNodeSetPtr nodeset; xmlpathobj_t xpathobj[] = {{&simul_xobj, (xmlChar *) XML_X_SIMULATION}, {&entity_xobj, (xmlChar *) XML_X_ENTITY}, {&environment_xobj, (xmlChar *) XML_X_ENVIRONMENT}, {&bundle_xobj, (xmlChar *) XML_X_BUNDLE}, {&node_xobj, (xmlChar *) XML_X_NODE}}; int ok = 0, i; /* Check XML version */ LIBXML_TEST_VERSION; /* Initialise and parse schema */ sp_ctxt = xmlSchemaNewParserCtxt(schemafile); if (sp_ctxt == NULL) { fprintf(stderr, "config: XML schema parser initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } xmlSchemaSetParserErrors(sp_ctxt, (xmlSchemaValidityErrorFunc) xml_error, (xmlSchemaValidityWarningFunc) xml_warning, NULL); schema = xmlSchemaParse(sp_ctxt); if (schema == NULL) { fprintf(stderr, "config: error in schema %s (do_configuration())\n", schemafile); ok = -1; goto cleanup; } xmlSchemaSetValidErrors(sv_ctxt, (xmlSchemaValidityErrorFunc) xml_error, (xmlSchemaValidityWarningFunc) xml_warning, NULL); sv_ctxt = xmlSchemaNewValidCtxt(schema); if (sv_ctxt == NULL) { fprintf(stderr, "config: XML schema validator initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } /* Initialise and parse document */ p_ctxt = xmlNewParserCtxt(); if (p_ctxt == NULL) { fprintf(stderr, "config: XML parser initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } doc = xmlCtxtReadFile(p_ctxt, configfile, NULL, XML_PARSE_NONET | XML_PARSE_NOBLANKS | XML_PARSE_NSCLEAN); if (doc == NULL) { fprintf(stderr, "config: failed to parse %s (do_configuration())\n", configfile); ok = -1; goto cleanup; } /* Validate document */ if (xmlSchemaValidateDoc(sv_ctxt, doc)) { fprintf(stderr, "config: error in configuration file %s (do_configuration())\n", configfile); ok = -1; goto cleanup; } /* Create xpath context */ xp_ctx = xmlXPathNewContext(doc); if (xp_ctx == NULL) { fprintf(stderr, "config: XPath initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } xmlXPathRegisterNs(xp_ctx, (xmlChar *) XML_NS_ID, (xmlChar *) XML_NS_URL); /* Get xpath obj */ for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) { *xpathobj[i].ptr = xmlXPathEvalExpression(xpathobj[i].expr, xp_ctx); if (*xpathobj[i].ptr == NULL) { fprintf(stderr, "config: unable to evaluate xpath \"%s\" (do_configuration())\n", xpathobj[i].expr); ok = -1; goto cleanup; } } /***************/ /* Counting... */ /***************/ nodeset = entity_xobj->nodesetval; if ((entities.size = (nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no entity defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "\nFound %d entities...\n", entities.size); nodeset = environment_xobj->nodesetval; if (((nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no environment defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "Found 1 environment...\n"); nodeset = bundle_xobj->nodesetval; if ((bundles.size = (nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no bundle defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "Found %d bundles...\n", bundles.size); if ((dflt_params = das_create()) == NULL) { ok = -1; goto cleanup; } /**************/ /* Simulation */ /**************/ if (parse_simulation(simul_xobj->nodesetval)) { ok = -1; goto cleanup; } /**********/ /* Entity */ /**********/ /* initialize library paths */ config_set_usr_modulesdir(); user_path_list = g_strsplit(user_modulesdir, ":", 0); /* TOCLEAN */ sys_path_list = g_strsplit(sys_modulesdir, ":", 0); /* TOCLEAN */ /* parse */ if (parse_entities(entity_xobj->nodesetval)) { ok = -1; goto cleanup; } /**************/ /* Measure */ /**************/ if (parse_measure()) { ok = -1; goto cleanup; } /***************/ /* Environment */ /***************/ if (parse_environment(environment_xobj->nodesetval)) { ok = -1; goto cleanup; } /***************/ /* Bundle */ /***************/ if (parse_bundles(bundle_xobj->nodesetval)) { ok = -1; goto cleanup; } /***************/ /* Nodes */ /***************/ if (parse_nodes(node_xobj->nodesetval)) { ok = -1; goto cleanup; } /* edit by Quentin Lampin <*****@*****.**> */ gchar **path = NULL; for (path = user_path_list ; *path ; path++) { g_free(*path); } path = NULL; for (path = sys_path_list ; *path ; path++) { g_free(*path); } /* end of edition */ cleanup: clean_params(); for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) { xmlXPathFreeObject(*xpathobj[i].ptr); } if (xp_ctx) { xmlXPathFreeContext(xp_ctx); } if (sp_ctxt) { xmlSchemaFreeParserCtxt(sp_ctxt); } if (schema) { xmlSchemaFree(schema); } if (sv_ctxt) { xmlSchemaFreeValidCtxt(sv_ctxt); } if (doc) { xmlFreeDoc(doc); } if (p_ctxt) { xmlFreeParserCtxt(p_ctxt); } xmlCleanupParser(); return ok; }
int test (const char* base) { xmlDocPtr docPtr = NULL; char filename[100]; xmlSchemaPtr wxschemas = NULL; Handle2Path = xmlHashCreate(0); /* Read the schema. */ { /* There is no visitibility into parserCtxt. */ xmlSchemaParserCtxtPtr parserCtxt; /* parserCtxt->ctxtType is xmlSchemaTypePtr */ snprintf(filename, 100, "%s.xsd", base); printf("\n\n\n----------------------------------------------------------------\n\n\n"); printf("\n----> Reading schema %s...\n", filename); parserCtxt = xmlSchemaNewParserCtxt(filename); xmlSchemaSetParserErrors(parserCtxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stdout); xmlSchemaSetParserAnnotation(parserCtxt, schema_annotation_callback, NULL); wxschemas = xmlSchemaParse(parserCtxt); if (wxschemas == NULL) { printf("***** schema parsing failed!\n"); } xmlSchemaFreeParserCtxt(parserCtxt); printf("\n<---- Schema read!\n\n"); } /* Read the XML. */ { snprintf(filename, 100, "%s.xml", base); if ((docPtr = xmlReadFile(filename, NULL, 0)) == NULL) { printf("failed to parse \"%s\".\n", filename); return -1; } } if (!SKIP) { /* There is no visibility into schemaCtxt. */ xmlSchemaValidCtxtPtr schemaCtxt; int ret; printf("\n----------------------------------------------------------------\n"); printf("\n----> Validating document %s...\n", filename); /* This sets up the schemaCtxt, including a pointer to wxschemas. */ schemaCtxt = xmlSchemaNewValidCtxt(wxschemas); xmlSchemaSetValidErrors(schemaCtxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stdout); ret = xmlSchemaValidateDoc(schemaCtxt, docPtr); /* read me! */ if (ret == 0) { /* printf("%s validates\n", filename); */ } else if (ret > 0) { printf("%s fails to validate\n", filename); } else { printf("%s validation generated an internal error\n", filename); } xmlSchemaFreeValidCtxt(schemaCtxt); printf("\n<---- Document validated!\n"); } /* Generate a doc and validate it. */ { xmlDocPtr newDoc = xmlNewDoc(BAD_CAST "1.0"); { xmlSchemaValidCtxtPtr schemaCtxt; int ret; schemaCtxt = xmlSchemaNewValidCtxt(wxschemas); xmlSchemaSetValidErrors(schemaCtxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stdout); xmlSchemaSetGeneratorCallback(schemaCtxt, BAD_CAST "people", NULL, &generation_callback, newDoc); ret = xmlSchemaValidateDoc(schemaCtxt, newDoc); if (ret == 0) { /* xmlDocSetRootElement(newDoc, vctxt->node); */ dump_doc(newDoc, NULL); } else if (ret > 0) printf("%s fails to validate\n", filename); else printf("%s validation generated an internal error\n", filename); xmlSchemaFreeValidCtxt(schemaCtxt); printf("\n<---- Schema read!\n\n"); } { xmlSchemaValidCtxtPtr schemaCtxt; int ret; schemaCtxt = xmlSchemaNewValidCtxt(wxschemas); xmlSchemaSetValidErrors(schemaCtxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stdout); ret = xmlSchemaValidateDoc(schemaCtxt, newDoc); if (ret == 0) ; else if (ret > 0) printf("%s fails to validate\n", filename); else printf("%s validation generated an internal error\n", filename); xmlSchemaFreeValidCtxt(schemaCtxt); printf("\n<---- Schema read!\n\n"); } xmlFreeDoc(newDoc); } #if 0 /* why can't I just start with doc->children? */ tree_trunk = xmlDocGetRootElement(docPtr); #endif #if 0 tree_trunk = docPtr->children; printf("\n\n\n----------------------------------------------------------------\n\n\n"); printf("\nWalking doc tree...\n"); walk_doc_tree(tree_trunk, 0); printf("\n"); #endif printf("\n\n\n----------------------------------------------------------------\n\n\n"); printf("\nWalking schema tree...\n"); walk_schema_tree(wxschemas); printf("\n"); /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ /* This will tell me, for example, how to decode sequences. */ printf("\n\n\n----------------------------------------------------------------\n\n\n"); xmlSchemaDump(stdout, wxschemas); /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ xmlFreeDoc(docPtr); xmlCleanupParser(); xmlHashFree(Handle2Path, NULL); return 0; }
int main(int argc, char **argv) { int i; int files = 0; xmlSchemaPtr schema = NULL; for (i = 1; i < argc ; i++) { #ifdef LIBXML_DEBUG_ENABLED if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) debug++; else #endif #ifdef HAVE_SYS_MMAN_H if ((!strcmp(argv[i], "-memory")) || (!strcmp(argv[i], "--memory"))) { memory++; } else #endif if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) { noout++; } } /*xmlLineNumbersDefault(1);*/ for (i = 1; i < argc ; i++) { if (argv[i][0] != '-') { if (schema == NULL) { xmlSchemaParserCtxtPtr ctxt; #ifdef HAVE_SYS_MMAN_H if (memory) { int fd; struct stat info; const char *base; if (stat(argv[i], &info) < 0) break; if ((fd = open(argv[i], O_RDONLY)) < 0) break; base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; if (base == (void *) MAP_FAILED) break; ctxt = xmlSchemaNewMemParserCtxt((char *)base,info.st_size); xmlSchemaSetParserErrors(ctxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr); schema = xmlSchemaParse(ctxt); xmlSchemaFreeParserCtxt(ctxt); munmap((char *) base, info.st_size); } else #endif { /*printf("\n**** CALLING :: xmlSchemaNewParserCtxt argv[i] = %s \n ", argv[i]);*/ printf("\n**** CALLING :: xmlSchemaNewParserCtxt \n "); ctxt = xmlSchemaNewParserCtxt(argv[i]); //ctxt = xmlSchemaNewParserCtxt("/root/Code/libxml2-2.6.15/ixml/basic/memory_test.xsd"); printf("\n**** CALLING :: xmlSchemaParse \n "); xmlSchemaSetParserErrors(ctxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr); printf("\n**** CALLING :: xmlSchemaParse \n "); schema = xmlSchemaParse(ctxt); xmlSchemaFreeParserCtxt(ctxt); } #if 0 #ifdef LIBXML_OUTPUT_ENABLED #ifdef LIBXML_DEBUG_ENABLED if (debug) xmlSchemaDump(stdout, schema); #endif #endif /* LIBXML_OUTPUT_ENABLED */ #endif /*#if 0*/ if (schema == NULL) goto failed_schemas; } else { IXML_Document *doc; printf("\n ***** CALLING :: xmlReadFile:> %s ", argv[i]); //doc = xmlReadFile(argv[i],NULL,0); //doc = ixmlLoadDocument("/root/Code/libxml2-2.6.15/ixml/basic/memory_test.xml"); doc = ixmlLoadDocument(argv[i]); #if 0 printf("nodeName = %s\n",doc->n.firstChild->nodeName); printf("firstAttr->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeName); printf("firstAttr->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeValue); printf("firstAttr->nextSibling->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeName); printf("firstAttr->nextSibling->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeValue); #endif if (doc == NULL) { fprintf(stderr, "Could not parse %s\n", argv[i]); } else { xmlSchemaValidCtxtPtr ctxt; int ret; printf("\n ***** CALLING :: xmlSchemaNewValidCtxt *****\n "); ctxt = xmlSchemaNewValidCtxt(schema); printf("\n ***** CALLING :: xmlSchemaSetValidErrors *****\n "); xmlSchemaSetValidErrors(ctxt, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr); ret = xmlSchemaValidateDoc(ctxt, doc); #if 0 printf("nodeName = %s\n",doc->n.firstChild->nodeName); printf("firstAttr->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeName); printf("firstAttr->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeValue); printf("firstAttr->nextSibling->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeName); printf("firstAttr->nextSibling->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeValue); #endif if (ret == 0) { printf("%s validates\n", argv[i]); } else if (ret > 0) { printf("%s fails to validate\n", argv[i]); } else { printf("%s validation generated an internal error\n", argv[i]); } xmlSchemaFreeValidCtxt(ctxt); ixmlDocument_free(doc); } } files ++; } } if (schema != NULL) xmlSchemaFree(schema); if (files == 0) { printf("Usage : %s [--debug] [--noout] schemas XMLfiles ...\n", argv[0]); printf("\tParse the HTML files and output the result of the parsing\n"); #ifdef LIBXML_DEBUG_ENABLED printf("\t--debug : dump a debug tree of the in-memory document\n"); #endif printf("\t--noout : do not print the result\n"); #ifdef HAVE_SYS_MMAN_H printf("\t--memory : test the schemas in memory parsing\n"); #endif } failed_schemas: /*printf("\n**** failed_schemas\n");*/ xmlSchemaCleanupTypes(); /*xmlCleanupParser(); xmlResetLastError(); xmlMemoryDump();*/ return(0); }