void xml_node_deinit_ctx(struct xml_node_ctx *ctx) { xmlSchemaCleanupTypes(); xmlCleanupParser(); xmlMemoryDump(); os_free(ctx); }
/* * Valid an xml string against an XML schema * Inpired from: http://xml.developpez.com/sources/?page=validation#validate_XSD_CppCLI_2 * taken from tinyows.org */ int msOWSSchemaValidation(const char* xml_schema, const char* xml) { xmlSchemaPtr schema; xmlSchemaParserCtxtPtr ctxt; xmlSchemaValidCtxtPtr validctxt; int ret; xmlDocPtr doc; if (!xml_schema || !xml) return MS_FAILURE; xmlInitParser(); schema = NULL; ret = -1; /* Open XML Schema File */ ctxt = xmlSchemaNewParserCtxt(xml_schema); /* else ctxt = xmlSchemaNewMemParserCtxt(xml_schema); */ /* xmlSchemaSetParserErrors(ctxt, (xmlSchemaValidityErrorFunc) libxml2_callback, (xmlSchemaValidityWarningFunc) libxml2_callback, stderr); */ schema = xmlSchemaParse(ctxt); xmlSchemaFreeParserCtxt(ctxt); /* If XML Schema hasn't been rightly loaded */ if (schema == NULL) { xmlSchemaCleanupTypes(); xmlMemoryDump(); xmlCleanupParser(); return ret; } doc = xmlParseDoc((xmlChar *)xml); if (doc != NULL) { /* Loading XML Schema content */ validctxt = xmlSchemaNewValidCtxt(schema); /* xmlSchemaSetValidErrors(validctxt, (xmlSchemaValidityErrorFunc) libxml2_callback, (xmlSchemaValidityWarningFunc) libxml2_callback, stderr); */ /* validation */ ret = xmlSchemaValidateDoc(validctxt, doc); xmlSchemaFreeValidCtxt(validctxt); } xmlSchemaFree(schema); xmlFreeDoc(doc); xmlCleanupParser(); return ret; }
/** * Destroys the parser */ void parser_destroy() { if (dtdCtxt){ xmlFreeValidCtxt(dtdCtxt); } if (xsdCtxt){ xmlSchemaFreeValidCtxt(xsdCtxt); xmlSchemaCleanupTypes(); } xmlCleanupParser(); }
/* Global functions ---------------- */ #if defined (WX_USER_INTERFACE) bool wxCmguiApp::OnInit() { return (true); } wxAppTraits * wxCmguiApp::CreateTraits() { return new wxGUIAppTraits; } void wxCmguiApp::OnIdle(wxIdleEvent& event) { if (event_dispatcher) { if (Event_dispatcher_process_idle_event(event_dispatcher)) { event.RequestMore(); } } } void wxCmguiApp::SetEventDispatcher(Event_dispatcher *event_dispatcher_in) { event_dispatcher = event_dispatcher_in; } BEGIN_EVENT_TABLE(wxCmguiApp, wxApp) EVT_IDLE(wxCmguiApp::OnIdle) END_EVENT_TABLE() IMPLEMENT_APP_NO_MAIN(wxCmguiApp) #endif /*defined (WX_USER_INTERFACE)*/ #if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER) int main(int argc,const char *argv[]) #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ int WINAPI WinMain(HINSTANCE current_instance,HINSTANCE previous_instance, LPSTR command_line,int initial_main_window_state) /* using WinMain as the entry point tells Windows that it is a gui and to use the graphics device interface functions for I/O */ /*???DB. WINDOWS a zero return code if WinMain does get into the message loop. Other application interfaces may expect something else. Should this failure code be #define'd ? */ /*???DB. Win32 SDK says that don't have to call it WinMain */ #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ /******************************************************************************* LAST MODIFIED : 7 January 2003 DESCRIPTION : Main program for the CMISS Graphical User Interface ==============================================================================*/ { int return_code = 0; #if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER) int argc = 1, i; const char **argv; char *p, *q; #endif /* defined (WIN32_USER_INTERFACE) */ struct Cmiss_context_app *context = NULL; struct User_interface_module *UI_module = NULL; struct Cmiss_command_data *command_data; #if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER) ENTER(main); #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ ENTER(WinMain); //_CrtSetBreakAlloc(28336); for (p = command_line; p != NULL && *p != 0;) { p = strchr(p, ' '); if (p != NULL) p++; argc++; } argv = (const char **)malloc(sizeof(*argv) * argc); argv[0] = "cmgui"; for (i = 1, p = command_line; p != NULL && *p != 0;) { q = strchr(p, ' '); if (q != NULL) *q++ = 0; if (p != NULL) argv[i++] = p; p = q; } #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ /* display the version */ display_message(INFORMATION_MESSAGE, "%s version %s\n%s\n" "Build information: %s %s\n", CMISS_NAME_STRING, CMISS_VERSION_STRING, CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING, CMISS_SVN_REVISION_STRING); #if defined (CARBON_USER_INTERFACE) || (defined (WX_USER_INTERFACE) && defined (DARWIN)) ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN,kProcessTransformToForegroundApplication); #endif context = Cmiss_context_app_create("default"); #if defined (WX_USER_INTERFACE) int wx_entry_started = 0; #endif if (context) { #if defined (WX_USER_INTERFACE) || (!defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)) UI_module = Cmiss_context_create_user_interface(context, argc, argv, NULL); #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ UI_module = Cmiss_context_create_user_interface(context, argc, argv, current_instance, previous_instance, command_line, initial_main_window_state, NULL); #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ if (UI_module) { #if defined (WX_USER_INTERFACE) if (UI_module->user_interface) { char **temp_argv = NULL, **cleanup_argv = NULL; int temp_argc = argc, cleanup_argc = argc; if (cleanup_argc > 0) { ALLOCATE(temp_argv, char *, cleanup_argc); ALLOCATE(cleanup_argv, char *, cleanup_argc); for (int i = 0; i < cleanup_argc; i++) { cleanup_argv[i] = temp_argv[i] = duplicate_string(argv[i]); } } if (wxEntryStart(temp_argc, temp_argv)) { wx_entry_started = 1; wxXmlResource::Get()->InitAllHandlers(); wxCmguiApp &app = wxGetApp(); if (&app) { app.SetEventDispatcher(UI_module->event_dispatcher); } else { display_message(ERROR_MESSAGE, "initialiseWxApp. wxCmguiApp not initialised."); } } else { display_message(ERROR_MESSAGE, "initialiseWxApp. Invalid arguments."); } if (cleanup_argv) { for (int i = 0; i < cleanup_argc; i++) { DEALLOCATE(cleanup_argv[i]); } DEALLOCATE(temp_argv); DEALLOCATE(cleanup_argv); } } #endif Cmiss_graphics_module_id graphics_module = NULL; if (NULL != (graphics_module = Cmiss_context_get_default_graphics_module(Cmiss_context_app_get_core_context(context)))) { Cmiss_graphics_module_define_standard_materials(graphics_module); Cmiss_graphics_module_destroy(&graphics_module); } if (NULL != (command_data = Cmiss_context_get_default_command_interpreter(context))) { Cmiss_command_data_set_cmgui_string(command_data, CMISS_NAME_STRING, CMISS_VERSION_STRING, "CMISS_DATE_STRING", CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING, CMISS_SVN_REVISION_STRING); Cmiss_command_data_main_loop(command_data); Cmiss_command_data_destroy(&command_data); return_code = 0; } else { return_code = 1; } User_interface_module_destroy(&UI_module); } else { return_code = 1; } Cmiss_context_app_destroy(&context); Context_internal_cleanup(); #if defined (WX_USER_INTERFACE) if (wx_entry_started) wxEntryCleanup(); #endif /* FieldML does not cleanup the global varaibles xmlParser, xmlSchematypes and * xmlCatalog at this moment, so we clean it up here instead*/ xmlCatalogCleanup(); xmlSchemaCleanupTypes(); xmlCleanupParser(); } else { return_code = 1; } #if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER) free(argv) #endif LEAVE; return (return_code); } /* main */
/** * This is the main function for 'validate' option */ int valMain(int argc, char **argv) { int start; static valOptions ops; static ErrorInfo errorInfo; int invalidFound = 0; int options = XML_PARSE_DTDLOAD | XML_PARSE_DTDATTR; if (argc <= 2) valUsage(argc, argv, EXIT_BAD_ARGS); valInitOptions(&ops); start = valParseOptions(&ops, argc, argv); if (ops.nonet) options |= XML_PARSE_NONET; errorInfo.verbose = ops.err; xmlSetStructuredErrorFunc(&errorInfo, reportError); xmlLineNumbersDefault(1); if (ops.dtd) { /* xmlReader doesn't work with external dtd, have to use SAX * interface */ int i; for (i=start; i<argc; i++) { xmlDocPtr doc; int ret; ret = 0; doc = NULL; errorInfo.filename = argv[i]; doc = xmlReadFile(argv[i], NULL, options); if (doc) { /* TODO: precompile DTD once */ ret = valAgainstDtd(&ops, ops.dtd, doc, argv[i]); xmlFreeDoc(doc); } else { ret = 1; /* Malformed XML or could not open file */ if ((ops.listGood < 0) && !ops.show_val_res) { fprintf(stdout, "%s\n", argv[i]); } } if (ret) invalidFound = 1; if (ops.show_val_res) { if (ret == 0) fprintf(stdout, "%s - valid\n", argv[i]); else fprintf(stdout, "%s - invalid\n", argv[i]); } } } else if (ops.schema || ops.relaxng || ops.embed || ops.wellFormed) { int i; xmlTextReaderPtr reader = NULL; #ifdef LIBXML_SCHEMAS_ENABLED xmlSchemaPtr schema = NULL; xmlSchemaParserCtxtPtr schemaParserCtxt = NULL; xmlSchemaValidCtxtPtr schemaCtxt = NULL; xmlRelaxNGPtr relaxng = NULL; xmlRelaxNGParserCtxtPtr relaxngParserCtxt = NULL; /* there is no xmlTextReaderRelaxNGValidateCtxt() !? */ /* TODO: Do not print debug stuff */ if (ops.schema) { schemaParserCtxt = xmlSchemaNewParserCtxt(ops.schema); if (!schemaParserCtxt) { invalidFound = 2; goto schemaCleanup; } errorInfo.filename = ops.schema; schema = xmlSchemaParse(schemaParserCtxt); if (!schema) { invalidFound = 2; goto schemaCleanup; } xmlSchemaFreeParserCtxt(schemaParserCtxt); schemaCtxt = xmlSchemaNewValidCtxt(schema); if (!schemaCtxt) { invalidFound = 2; goto schemaCleanup; } } else if (ops.relaxng) { relaxngParserCtxt = xmlRelaxNGNewParserCtxt(ops.relaxng); if (!relaxngParserCtxt) { invalidFound = 2; goto schemaCleanup; } errorInfo.filename = ops.relaxng; relaxng = xmlRelaxNGParse(relaxngParserCtxt); if (!relaxng) { invalidFound = 2; goto schemaCleanup; } } #endif /* LIBXML_SCHEMAS_ENABLED */ for (i=start; i<argc; i++) { int ret = 0; if (ops.embed) options |= XML_PARSE_DTDVALID; if (!reader) { reader = xmlReaderForFile(argv[i], NULL, options); } else { ret = xmlReaderNewFile(reader, argv[i], NULL, options); } errorInfo.xmlReader = reader; errorInfo.filename = argv[i]; if (reader && ret == 0) { #ifdef LIBXML_SCHEMAS_ENABLED if (schemaCtxt) { ret = xmlTextReaderSchemaValidateCtxt(reader, schemaCtxt, 0); } else if (relaxng) { ret = xmlTextReaderRelaxNGSetSchema(reader, relaxng); } #endif /* LIBXML_SCHEMAS_ENABLED */ if (ret == 0) { do { ret = xmlTextReaderRead(reader); } while (ret == 1); if (ret != -1 && (schema || relaxng || ops.embed)) ret = !xmlTextReaderIsValid(reader); } } else { if (ops.err) fprintf(stderr, "couldn't read file '%s'\n", errorInfo.filename); ret = 1; /* could not open file */ } if (ret) invalidFound = 1; if (!ops.show_val_res) { if ((ops.listGood > 0) && (ret == 0)) fprintf(stdout, "%s\n", argv[i]); if ((ops.listGood < 0) && (ret != 0)) fprintf(stdout, "%s\n", argv[i]); } else { if (ret == 0) fprintf(stdout, "%s - valid\n", argv[i]); else fprintf(stdout, "%s - invalid\n", argv[i]); } } errorInfo.xmlReader = NULL; xmlFreeTextReader(reader); #ifdef LIBXML_SCHEMAS_ENABLED schemaCleanup: xmlSchemaFreeValidCtxt(schemaCtxt); xmlRelaxNGFree(relaxng); xmlSchemaFree(schema); xmlRelaxNGCleanupTypes(); xmlSchemaCleanupTypes(); #endif /* LIBXML_SCHEMAS_ENABLED */ } xmlCleanupParser(); return invalidFound; }
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); }