/* * call-seq: * XML.default_pedantic_parser = true|false * * Controls whether parsers are pedantic by default. */ static VALUE rxml_default_pedantic_parser_set(VALUE klass, VALUE value) { if (value == Qfalse) { xmlPedanticParserDefault(0); return (Qfalse); } else { xmlPedanticParserDefault(1); return (Qtrue); } }
XMLParser::XMLParser() : m_SchemaParserCtxt(0), m_Schema(0), m_SchemaValidCtxt(0), m_DTD(0), m_DTDValidCtxt(0), m_Doc(0) { xmlPedanticParserDefault(1); xmlSetGenericErrorFunc(this, errorOutputFunc); xmlDoValidityCheckingDefaultValue = 0; }
int main(int argc, char **argv) { int ch; char *encoding = "utf8"; char *filename; int quiet = 0; int exitcode = EXIT_OK; xmlDocPtr doc = NULL; xmlDtdPtr dtd = NULL; xmlCharEncoding enc; xmlCharEncodingHandlerPtr enchandler; xmlOutputBufferPtr out; /* LibXML version checking */ LIBXML_TEST_VERSION; /* Who am I? */ if ((progname = rindex(argv[0], '/'))) progname++; else progname = argv[0]; /* Parsing CLI */ while ((ch = getopt(argc, argv, "hqe:")) != -1) switch (ch) { case 'q': quiet = 1; break; case 'e': encoding = optarg; break; case 'h': /* FALL THROUGH */ case '?': usage(EXIT_OK); break; default: usage(EXIT_USAGE); break; } argc -= optind; argv += optind; switch (argc) { case 1: filename = argv[0]; break; case 0: filename = "-"; break; default: usage(EXIT_USAGE); } /* Get user encoding */ if ((enc = xmlParseCharEncoding(encoding)) == XML_CHAR_ENCODING_ERROR) { fprintf(stderr, "Unknown encoding: %s\n", encoding); usage(EXIT_USAGE); } enchandler = xmlGetCharEncodingHandler(enc); /* Shut up */ xmlSetGenericErrorFunc(NULL, &noerror_handler); xmlGetWarningsDefaultValue = 0; xmlPedanticParserDefault(0); /* File exists? (race condition below) */ if (strcmp(filename, "-") && (open(filename, O_RDONLY) < 0)) { if (!quiet) fprintf(stderr, "ERROR: unable to open %s\n", filename); exitcode = EXIT_NOFILE; goto exit; } /* Parse document */ if ((doc = xmlParseFile(filename)) == NULL) { if (!quiet) fprintf(stderr, "ERROR: badly formed document\n"); exitcode = EXIT_BADXML; goto exit; } /* Extract DTD (if any) */ dtd = xmlGetIntSubset(doc); /* Create output buffer */ if ((out = xmlOutputBufferCreateFd(1, enchandler)) == NULL) { if (!quiet) fprintf(stderr, "ERROR: unable to open output channel\n"); exitcode = EXIT_INTERNAL; goto exit; } /* Dump information */ if (doc->version) { xmlOutputBufferWriteString(out, "Version : "); xmlOutputBufferWriteString(out, doc->version); xmlOutputBufferWriteString(out, "\n"); } if (doc->encoding) { xmlOutputBufferWriteString(out, "Encoding : "); xmlOutputBufferWriteString(out, doc->encoding); xmlOutputBufferWriteString(out, "\n"); } if (dtd && dtd->name) { xmlOutputBufferWriteString(out, "Name : "); xmlOutputBufferWriteString(out, dtd->name); xmlOutputBufferWriteString(out, "\n"); } if (dtd && dtd->ExternalID) { xmlOutputBufferWriteString(out, "Identifier: "); xmlOutputBufferWriteString(out, dtd->ExternalID); xmlOutputBufferWriteString(out, "\n"); } if (dtd && dtd->SystemID) { xmlOutputBufferWriteString(out, "URI : "); xmlOutputBufferWriteString(out, dtd->SystemID); xmlOutputBufferWriteString(out, "\n"); xmlOutputBufferFlush(out); } /* Free resources */ if (doc) xmlFreeDoc(doc); xmlCleanupParser(); /* OK */ exit: exit(exitcode); }
gboolean _gtk_source_language_file_parse_version2 (GtkSourceLanguage *language, GtkSourceContextData *ctx_data) { GHashTable *defined_regexes, *styles; gboolean success; GError *error = NULL; gchar *filename; GHashTable *loaded_lang_ids; GQueue *replacements; g_return_val_if_fail (ctx_data != NULL, FALSE); filename = language->priv->lang_file_name; /* TODO: as an optimization tell the parser to merge CDATA * as text nodes (XML_PARSE_NOCDATA), and to ignore blank * nodes (XML_PARSE_NOBLANKS), if it is possible with * xmlTextReader. */ xmlKeepBlanksDefault (0); xmlLineNumbersDefault (1); xmlSubstituteEntitiesDefault (1); DEBUG (xmlPedanticParserDefault (1)); defined_regexes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); styles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) _gtk_source_style_info_free); loaded_lang_ids = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) xmlFree, NULL); replacements = g_queue_new (); success = file_parse (filename, language, ctx_data, defined_regexes, styles, loaded_lang_ids, replacements, &error); if (success) success = _gtk_source_context_data_finish_parse (ctx_data, replacements->head, &error); if (success) g_hash_table_foreach_steal (styles, (GHRFunc) steal_styles_mapping, language->priv->styles); g_queue_foreach (replacements, (GFunc) _gtk_source_context_replace_free, NULL); g_queue_free (replacements); g_hash_table_destroy (loaded_lang_ids); g_hash_table_destroy (defined_regexes); g_hash_table_destroy (styles); if (!success) { g_warning ("Failed to load '%s': %s", filename, error->message); g_error_free (error); return FALSE; } return TRUE; }