diff --git a/.gitattributes b/.gitattributes index 4ad1cdd8..5fd0c468 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ *.txt text -*.h text -*.c text -*.rb text +*.h text eol=lf +*.c text eol=lf +*.rb text eol=lf *.yml text *.vcproj text eol=crlf -*.sh text eol=lf \ No newline at end of file +*.sh text eol=lf diff --git a/ext/libxml/ruby_xml.c b/ext/libxml/ruby_xml.c index 5994ead7..0d421d95 100644 --- a/ext/libxml/ruby_xml.c +++ b/ext/libxml/ruby_xml.c @@ -1,556 +1,556 @@ -#include "ruby_libxml.h" -#include "ruby_xml.h" - -#include - -VALUE mXML; - -/* - * call-seq: - * XML.catalog_dump -> true - * - * Dump all the global catalog content stdout. - */ -static VALUE rxml_catalog_dump(VALUE self) -{ - xmlCatalogDump(stdout); - return (Qtrue); -} - -/* - * call-seq: - * XML.catalog_remove(catalog) -> true - * - * Remove the specified resource catalog. - */ -static VALUE rxml_catalog_remove(VALUE self, VALUE cat) -{ - Check_Type(cat, T_STRING); - xmlCatalogRemove((xmlChar *) StringValuePtr(cat)); - return (Qtrue); -} - -/* - * call-seq: - * XML.check_lib_versions -> true - * - * Check LIBXML version matches version the bindings - * were compiled to. Throws an exception if not. - */ -static VALUE rxml_check_lib_versions(VALUE klass) -{ - xmlCheckVersion(LIBXML_VERSION); - return (Qtrue); -} - -/* - * call-seq: - * XML.enabled_automata? -> (true|false) - * - * Determine whether libxml regexp automata support is enabled. - */ -static VALUE rxml_enabled_automata_q(VALUE klass) -{ -#ifdef LIBXML_AUTOMATA_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_c14n? -> (true|false) - * - * Determine whether libxml 'canonical XML' support is enabled. - * See "Canonical XML" (http://www.w3.org/TR/xml-c14n) - */ -static VALUE rxml_enabled_c14n_q(VALUE klass) -{ -#ifdef LIBXML_C14N_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_catalog? -> (true|false) - * - * Determine whether libxml resource catalog support is enabled. - */ -static VALUE rxml_enabled_catalog_q(VALUE klass) -{ -#ifdef LIBXML_CATALOG_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_debug? -> (true|false) - * - * Determine whether libxml debugging support is enabled. - */ -static VALUE rxml_enabled_debug_q(VALUE klass) -{ -#ifdef LIBXML_DEBUG_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_docbook? -> (true|false) - * - * Determine whether libxml docbook support is enabled. - */ -static VALUE rxml_enabled_docbook_q(VALUE klass) -{ -#ifdef LIBXML_DOCB_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_ftp? -> (true|false) - * - * Determine whether libxml ftp client support is enabled. - */ -static VALUE rxml_enabled_ftp_q(VALUE klass) -{ -#ifdef LIBXML_FTP_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_http? -> (true|false) - * - * Determine whether libxml http client support is enabled. - */ -static VALUE rxml_enabled_http_q(VALUE klass) -{ -#ifdef LIBXML_HTTP_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_html? -> (true|false) - * - * Determine whether libxml html support is enabled. - */ -static VALUE rxml_enabled_html_q(VALUE klass) -{ -#ifdef LIBXML_HTML_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_iconv? -> (true|false) - * - * Determine whether libxml iconv support is enabled. - */ -static VALUE rxml_enabled_iconv_q(VALUE klass) -{ -#ifdef LIBXML_ICONV_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_memory_debug? -> (true|false) - * - * Determine whether libxml memory location debugging support - * is enabled. - */ -static VALUE rxml_enabled_memory_debug_location_q(VALUE klass) -{ -#ifdef DEBUG_MEMORY_LOCATION - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_regexp? -> (true|false) - * - * Determine whether libxml regular expression support is enabled. - */ -static VALUE rxml_enabled_regexp_q(VALUE klass) -{ -#ifdef LIBXML_REGEXP_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_schemas? -> (true|false) - * - * Determine whether libxml schema support is enabled. - */ -static VALUE rxml_enabled_schemas_q(VALUE klass) -{ -#ifdef LIBXML_SCHEMAS_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_thread? -> (true|false) - * - * Determine whether thread-safe semantics support for libxml is enabled and - * is used by this ruby extension. Threading support in libxml uses pthread - * on Unix-like systems and Win32 threads on Windows. - */ -static VALUE rxml_enabled_thread_q(VALUE klass) -{ - /* This won't be defined unless this code is compiled with _REENTRANT or __MT__ - * defined or the compiler is in C99 mode. - * - * Note the relevant portion libxml/xmlversion.h on a thread-enabled build: - * - * #if defined(_REENTRANT) || defined(__MT__) || \ - * (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 >= 199506L)) - * #define LIBXML_THREAD_ENABLED - * #endif - * - */ -#ifdef LIBXML_THREAD_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_unicode? -> (true|false) - * - * Determine whether libxml unicode support is enabled. - */ -static VALUE rxml_enabled_unicode_q(VALUE klass) -{ -#ifdef LIBXML_UNICODE_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_xinclude? -> (true|false) - * - * Determine whether libxml xinclude support is enabled. - */ -static VALUE rxml_enabled_xinclude_q(VALUE klass) -{ -#ifdef LIBXML_XINCLUDE_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_xpath? -> (true|false) - * - * Determine whether libxml xpath support is enabled. - */ -static VALUE rxml_enabled_xpath_q(VALUE klass) -{ -#ifdef LIBXML_XPATH_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_xpointer? -> (true|false) - * - * Determine whether libxml xpointer support is enabled. - */ -static VALUE rxml_enabled_xpointer_q(VALUE klass) -{ -#ifdef LIBXML_XPTR_ENABLED - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.enabled_zlib? -> (true|false) - * - * Determine whether libxml zlib support is enabled. - */ -static VALUE rxml_enabled_zlib_q(VALUE klass) -{ -#ifdef HAVE_ZLIB_H - return(Qtrue); -#else - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.default_tree_indent_string -> "string" - * - * Obtain the default string used by parsers to indent the XML tree - * for output. - */ -static VALUE rxml_default_tree_indent_string_get(VALUE klass) -{ - if (xmlTreeIndentString == NULL) - return (Qnil); - else - return (rb_str_new2(xmlTreeIndentString)); -} - -/* - * call-seq: - * XML.default_tree_indent_string = "string" - * - * Set the default string used by parsers to indent the XML tree - * for output. - */ -static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string) -{ - Check_Type(string, T_STRING); - xmlTreeIndentString = (const char *)xmlStrdup((xmlChar *)StringValuePtr(string)); - return (string); -} - -/* - * call-seq: - * XML.default_compression -> (true|false) - * - * Determine whether parsers use Zlib compression by default - * (requires libxml to be compiled with Zlib support). - */ -static VALUE rxml_default_compression_get(VALUE klass) -{ -#ifdef HAVE_ZLIB_H - return(INT2FIX(xmlGetCompressMode())); -#else - rb_warn("libxml was compiled without zlib support"); - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.default_compression = true|false - * - * Controls whether parsers use Zlib compression by default - * (requires libxml to be compiled with Zlib support). - */ -static VALUE rxml_default_compression_set(VALUE klass, VALUE num) -{ -#ifdef HAVE_ZLIB_H - Check_Type(num, T_FIXNUM); - xmlSetCompressMode(FIX2INT(num)); - return(num); -#else - rb_warn("libxml was compiled without zlib support"); - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.default_save_no_empty_tags -> (true|false) - * - * Determine whether serializer outputs empty tags by default. - */ -static VALUE rxml_default_save_no_empty_tags_get(VALUE klass) -{ - if (xmlSaveNoEmptyTags) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * XML.default_save_no_empty_tags = true|false - * - * Controls whether serializer outputs empty tags by default. - */ -static VALUE rxml_default_save_no_empty_tags_set(VALUE klass, VALUE value) -{ - if (value == Qfalse) - { - xmlSaveNoEmptyTags = 0; - return (Qfalse); - } - else if (value == Qtrue) - { - xmlSaveNoEmptyTags = 1; - return (Qtrue); - } - else - { - rb_raise(rb_eArgError, "Invalid argument, must be a boolean"); - } -} - -/* - * call-seq: - * XML.indent_tree_output -> (true|false) - * - * Determines whether XML output will be indented - * (using the string supplied to +default_indent_tree_string+) - */ -static VALUE rxml_indent_tree_output_get(VALUE klass) -{ - if (xmlIndentTreeOutput) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * XML.indent_tree_output = true|false - * - * Controls whether XML output will be indented - * (using the string supplied to +default_indent_tree_string+) - */ -static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE value) -{ - if (value == Qtrue) - { - xmlIndentTreeOutput = 1; - return (Qtrue); - } - else if (value == Qfalse) - { - xmlIndentTreeOutput = 0; - return (Qfalse); - } - else - { - rb_raise(rb_eArgError, "Invalid argument, must be boolean"); - } -} - -/* - * call-seq: - * XML.memory_dump -> (true|false) - * - * Perform a parser memory dump (requires memory debugging - * support in libxml). - */ -static VALUE rxml_memory_dump(VALUE self) -{ -#ifdef DEBUG_MEMORY_LOCATION - xmlMemoryDump(); - return(Qtrue); -#else - rb_warn("libxml was compiled without memory debugging support"); - return (Qfalse); -#endif -} - -/* - * call-seq: - * XML.memory_used -> num_bytes - * - * Perform a parser memory dump (requires memory debugging - * support in libxml). - */ -static VALUE rxml_memory_used(VALUE self) -{ -#ifdef DEBUG_MEMORY_LOCATION - return(INT2NUM(xmlMemUsed())); -#else - rb_warn("libxml was compiled without memory debugging support"); - return (Qfalse); -#endif -} - -/* The libxml gem provides Ruby language bindings for GNOME's Libxml2 - * XML toolkit. Refer to the README file to get started - * and the LICENSE file for copyright and distribution information. -*/ - -void rxml_init_xml(void) -{ - mXML = rb_define_module_under(mLibXML, "XML"); - - /* Constants */ - rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION)); - rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION)); - rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM)); - rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*) XML_XML_NAMESPACE)); - - rb_define_module_function(mXML, "enabled_automata?", rxml_enabled_automata_q, 0); - rb_define_module_function(mXML, "enabled_c14n?", rxml_enabled_c14n_q, 0); - rb_define_module_function(mXML, "enabled_catalog?", rxml_enabled_catalog_q, 0); - rb_define_module_function(mXML, "enabled_debug?", rxml_enabled_debug_q, 0); - rb_define_module_function(mXML, "enabled_docbook?", rxml_enabled_docbook_q, 0); - rb_define_module_function(mXML, "enabled_ftp?", rxml_enabled_ftp_q, 0); - rb_define_module_function(mXML, "enabled_http?", rxml_enabled_http_q, 0); - rb_define_module_function(mXML, "enabled_html?", rxml_enabled_html_q, 0); - rb_define_module_function(mXML, "enabled_iconv?", rxml_enabled_iconv_q, 0); - rb_define_module_function(mXML, "enabled_memory_debug?", rxml_enabled_memory_debug_location_q, 0); - rb_define_module_function(mXML, "enabled_regexp?", rxml_enabled_regexp_q, 0); - rb_define_module_function(mXML, "enabled_schemas?", rxml_enabled_schemas_q, 0); - rb_define_module_function(mXML, "enabled_thread?", rxml_enabled_thread_q, 0); - rb_define_module_function(mXML, "enabled_unicode?", rxml_enabled_unicode_q, 0); - rb_define_module_function(mXML, "enabled_xinclude?", rxml_enabled_xinclude_q, 0); - rb_define_module_function(mXML, "enabled_xpath?", rxml_enabled_xpath_q, 0); - rb_define_module_function(mXML, "enabled_xpointer?", rxml_enabled_xpointer_q, 0); - rb_define_module_function(mXML, "enabled_zlib?", rxml_enabled_zlib_q, 0); - - rb_define_module_function(mXML, "catalog_dump", rxml_catalog_dump, 0); - rb_define_module_function(mXML, "catalog_remove", rxml_catalog_remove, 1); - rb_define_module_function(mXML, "check_lib_versions", rxml_check_lib_versions, 0); - rb_define_module_function(mXML, "default_compression", rxml_default_compression_get, 0); - rb_define_module_function(mXML, "default_compression=", rxml_default_compression_set, 1); - rb_define_module_function(mXML, "default_tree_indent_string", rxml_default_tree_indent_string_get, 0); - rb_define_module_function(mXML, "default_tree_indent_string=", rxml_default_tree_indent_string_set, 1); - rb_define_module_function(mXML, "default_save_no_empty_tags", rxml_default_save_no_empty_tags_get, 0); - rb_define_module_function(mXML, "default_save_no_empty_tags=", rxml_default_save_no_empty_tags_set, 1); - rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0); - rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1); - rb_define_module_function(mXML, "memory_dump", rxml_memory_dump, 0); - rb_define_module_function(mXML, "memory_used", rxml_memory_used, 0); -} +#include "ruby_libxml.h" +#include "ruby_xml.h" + +#include + +VALUE mXML; + +/* + * call-seq: + * XML.catalog_dump -> true + * + * Dump all the global catalog content stdout. + */ +static VALUE rxml_catalog_dump(VALUE self) +{ + xmlCatalogDump(stdout); + return (Qtrue); +} + +/* + * call-seq: + * XML.catalog_remove(catalog) -> true + * + * Remove the specified resource catalog. + */ +static VALUE rxml_catalog_remove(VALUE self, VALUE cat) +{ + Check_Type(cat, T_STRING); + xmlCatalogRemove((xmlChar *) StringValuePtr(cat)); + return (Qtrue); +} + +/* + * call-seq: + * XML.check_lib_versions -> true + * + * Check LIBXML version matches version the bindings + * were compiled to. Throws an exception if not. + */ +static VALUE rxml_check_lib_versions(VALUE klass) +{ + xmlCheckVersion(LIBXML_VERSION); + return (Qtrue); +} + +/* + * call-seq: + * XML.enabled_automata? -> (true|false) + * + * Determine whether libxml regexp automata support is enabled. + */ +static VALUE rxml_enabled_automata_q(VALUE klass) +{ +#ifdef LIBXML_AUTOMATA_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_c14n? -> (true|false) + * + * Determine whether libxml 'canonical XML' support is enabled. + * See "Canonical XML" (http://www.w3.org/TR/xml-c14n) + */ +static VALUE rxml_enabled_c14n_q(VALUE klass) +{ +#ifdef LIBXML_C14N_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_catalog? -> (true|false) + * + * Determine whether libxml resource catalog support is enabled. + */ +static VALUE rxml_enabled_catalog_q(VALUE klass) +{ +#ifdef LIBXML_CATALOG_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_debug? -> (true|false) + * + * Determine whether libxml debugging support is enabled. + */ +static VALUE rxml_enabled_debug_q(VALUE klass) +{ +#ifdef LIBXML_DEBUG_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_docbook? -> (true|false) + * + * Determine whether libxml docbook support is enabled. + */ +static VALUE rxml_enabled_docbook_q(VALUE klass) +{ +#ifdef LIBXML_DOCB_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_ftp? -> (true|false) + * + * Determine whether libxml ftp client support is enabled. + */ +static VALUE rxml_enabled_ftp_q(VALUE klass) +{ +#ifdef LIBXML_FTP_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_http? -> (true|false) + * + * Determine whether libxml http client support is enabled. + */ +static VALUE rxml_enabled_http_q(VALUE klass) +{ +#ifdef LIBXML_HTTP_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_html? -> (true|false) + * + * Determine whether libxml html support is enabled. + */ +static VALUE rxml_enabled_html_q(VALUE klass) +{ +#ifdef LIBXML_HTML_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_iconv? -> (true|false) + * + * Determine whether libxml iconv support is enabled. + */ +static VALUE rxml_enabled_iconv_q(VALUE klass) +{ +#ifdef LIBXML_ICONV_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_memory_debug? -> (true|false) + * + * Determine whether libxml memory location debugging support + * is enabled. + */ +static VALUE rxml_enabled_memory_debug_location_q(VALUE klass) +{ +#ifdef DEBUG_MEMORY_LOCATION + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_regexp? -> (true|false) + * + * Determine whether libxml regular expression support is enabled. + */ +static VALUE rxml_enabled_regexp_q(VALUE klass) +{ +#ifdef LIBXML_REGEXP_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_schemas? -> (true|false) + * + * Determine whether libxml schema support is enabled. + */ +static VALUE rxml_enabled_schemas_q(VALUE klass) +{ +#ifdef LIBXML_SCHEMAS_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_thread? -> (true|false) + * + * Determine whether thread-safe semantics support for libxml is enabled and + * is used by this ruby extension. Threading support in libxml uses pthread + * on Unix-like systems and Win32 threads on Windows. + */ +static VALUE rxml_enabled_thread_q(VALUE klass) +{ + /* This won't be defined unless this code is compiled with _REENTRANT or __MT__ + * defined or the compiler is in C99 mode. + * + * Note the relevant portion libxml/xmlversion.h on a thread-enabled build: + * + * #if defined(_REENTRANT) || defined(__MT__) || \ + * (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 >= 199506L)) + * #define LIBXML_THREAD_ENABLED + * #endif + * + */ +#ifdef LIBXML_THREAD_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_unicode? -> (true|false) + * + * Determine whether libxml unicode support is enabled. + */ +static VALUE rxml_enabled_unicode_q(VALUE klass) +{ +#ifdef LIBXML_UNICODE_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_xinclude? -> (true|false) + * + * Determine whether libxml xinclude support is enabled. + */ +static VALUE rxml_enabled_xinclude_q(VALUE klass) +{ +#ifdef LIBXML_XINCLUDE_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_xpath? -> (true|false) + * + * Determine whether libxml xpath support is enabled. + */ +static VALUE rxml_enabled_xpath_q(VALUE klass) +{ +#ifdef LIBXML_XPATH_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_xpointer? -> (true|false) + * + * Determine whether libxml xpointer support is enabled. + */ +static VALUE rxml_enabled_xpointer_q(VALUE klass) +{ +#ifdef LIBXML_XPTR_ENABLED + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.enabled_zlib? -> (true|false) + * + * Determine whether libxml zlib support is enabled. + */ +static VALUE rxml_enabled_zlib_q(VALUE klass) +{ +#ifdef HAVE_ZLIB_H + return(Qtrue); +#else + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.default_tree_indent_string -> "string" + * + * Obtain the default string used by parsers to indent the XML tree + * for output. + */ +static VALUE rxml_default_tree_indent_string_get(VALUE klass) +{ + if (xmlTreeIndentString == NULL) + return (Qnil); + else + return (rb_str_new2(xmlTreeIndentString)); +} + +/* + * call-seq: + * XML.default_tree_indent_string = "string" + * + * Set the default string used by parsers to indent the XML tree + * for output. + */ +static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string) +{ + Check_Type(string, T_STRING); + xmlTreeIndentString = (const char *)xmlStrdup((xmlChar *)StringValuePtr(string)); + return (string); +} + +/* + * call-seq: + * XML.default_compression -> (true|false) + * + * Determine whether parsers use Zlib compression by default + * (requires libxml to be compiled with Zlib support). + */ +static VALUE rxml_default_compression_get(VALUE klass) +{ +#ifdef HAVE_ZLIB_H + return(INT2FIX(xmlGetCompressMode())); +#else + rb_warn("libxml was compiled without zlib support"); + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.default_compression = true|false + * + * Controls whether parsers use Zlib compression by default + * (requires libxml to be compiled with Zlib support). + */ +static VALUE rxml_default_compression_set(VALUE klass, VALUE num) +{ +#ifdef HAVE_ZLIB_H + Check_Type(num, T_FIXNUM); + xmlSetCompressMode(FIX2INT(num)); + return(num); +#else + rb_warn("libxml was compiled without zlib support"); + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.default_save_no_empty_tags -> (true|false) + * + * Determine whether serializer outputs empty tags by default. + */ +static VALUE rxml_default_save_no_empty_tags_get(VALUE klass) +{ + if (xmlSaveNoEmptyTags) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * XML.default_save_no_empty_tags = true|false + * + * Controls whether serializer outputs empty tags by default. + */ +static VALUE rxml_default_save_no_empty_tags_set(VALUE klass, VALUE value) +{ + if (value == Qfalse) + { + xmlSaveNoEmptyTags = 0; + return (Qfalse); + } + else if (value == Qtrue) + { + xmlSaveNoEmptyTags = 1; + return (Qtrue); + } + else + { + rb_raise(rb_eArgError, "Invalid argument, must be a boolean"); + } +} + +/* + * call-seq: + * XML.indent_tree_output -> (true|false) + * + * Determines whether XML output will be indented + * (using the string supplied to +default_indent_tree_string+) + */ +static VALUE rxml_indent_tree_output_get(VALUE klass) +{ + if (xmlIndentTreeOutput) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * XML.indent_tree_output = true|false + * + * Controls whether XML output will be indented + * (using the string supplied to +default_indent_tree_string+) + */ +static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE value) +{ + if (value == Qtrue) + { + xmlIndentTreeOutput = 1; + return (Qtrue); + } + else if (value == Qfalse) + { + xmlIndentTreeOutput = 0; + return (Qfalse); + } + else + { + rb_raise(rb_eArgError, "Invalid argument, must be boolean"); + } +} + +/* + * call-seq: + * XML.memory_dump -> (true|false) + * + * Perform a parser memory dump (requires memory debugging + * support in libxml). + */ +static VALUE rxml_memory_dump(VALUE self) +{ +#ifdef DEBUG_MEMORY_LOCATION + xmlMemoryDump(); + return(Qtrue); +#else + rb_warn("libxml was compiled without memory debugging support"); + return (Qfalse); +#endif +} + +/* + * call-seq: + * XML.memory_used -> num_bytes + * + * Perform a parser memory dump (requires memory debugging + * support in libxml). + */ +static VALUE rxml_memory_used(VALUE self) +{ +#ifdef DEBUG_MEMORY_LOCATION + return(INT2NUM(xmlMemUsed())); +#else + rb_warn("libxml was compiled without memory debugging support"); + return (Qfalse); +#endif +} + +/* The libxml gem provides Ruby language bindings for GNOME's Libxml2 + * XML toolkit. Refer to the README file to get started + * and the LICENSE file for copyright and distribution information. +*/ + +void rxml_init_xml(void) +{ + mXML = rb_define_module_under(mLibXML, "XML"); + + /* Constants */ + rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION)); + rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION)); + rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM)); + rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*) XML_XML_NAMESPACE)); + + rb_define_module_function(mXML, "enabled_automata?", rxml_enabled_automata_q, 0); + rb_define_module_function(mXML, "enabled_c14n?", rxml_enabled_c14n_q, 0); + rb_define_module_function(mXML, "enabled_catalog?", rxml_enabled_catalog_q, 0); + rb_define_module_function(mXML, "enabled_debug?", rxml_enabled_debug_q, 0); + rb_define_module_function(mXML, "enabled_docbook?", rxml_enabled_docbook_q, 0); + rb_define_module_function(mXML, "enabled_ftp?", rxml_enabled_ftp_q, 0); + rb_define_module_function(mXML, "enabled_http?", rxml_enabled_http_q, 0); + rb_define_module_function(mXML, "enabled_html?", rxml_enabled_html_q, 0); + rb_define_module_function(mXML, "enabled_iconv?", rxml_enabled_iconv_q, 0); + rb_define_module_function(mXML, "enabled_memory_debug?", rxml_enabled_memory_debug_location_q, 0); + rb_define_module_function(mXML, "enabled_regexp?", rxml_enabled_regexp_q, 0); + rb_define_module_function(mXML, "enabled_schemas?", rxml_enabled_schemas_q, 0); + rb_define_module_function(mXML, "enabled_thread?", rxml_enabled_thread_q, 0); + rb_define_module_function(mXML, "enabled_unicode?", rxml_enabled_unicode_q, 0); + rb_define_module_function(mXML, "enabled_xinclude?", rxml_enabled_xinclude_q, 0); + rb_define_module_function(mXML, "enabled_xpath?", rxml_enabled_xpath_q, 0); + rb_define_module_function(mXML, "enabled_xpointer?", rxml_enabled_xpointer_q, 0); + rb_define_module_function(mXML, "enabled_zlib?", rxml_enabled_zlib_q, 0); + + rb_define_module_function(mXML, "catalog_dump", rxml_catalog_dump, 0); + rb_define_module_function(mXML, "catalog_remove", rxml_catalog_remove, 1); + rb_define_module_function(mXML, "check_lib_versions", rxml_check_lib_versions, 0); + rb_define_module_function(mXML, "default_compression", rxml_default_compression_get, 0); + rb_define_module_function(mXML, "default_compression=", rxml_default_compression_set, 1); + rb_define_module_function(mXML, "default_tree_indent_string", rxml_default_tree_indent_string_get, 0); + rb_define_module_function(mXML, "default_tree_indent_string=", rxml_default_tree_indent_string_set, 1); + rb_define_module_function(mXML, "default_save_no_empty_tags", rxml_default_save_no_empty_tags_get, 0); + rb_define_module_function(mXML, "default_save_no_empty_tags=", rxml_default_save_no_empty_tags_set, 1); + rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0); + rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1); + rb_define_module_function(mXML, "memory_dump", rxml_memory_dump, 0); + rb_define_module_function(mXML, "memory_used", rxml_memory_used, 0); +} diff --git a/ext/libxml/ruby_xml_attributes.h b/ext/libxml/ruby_xml_attributes.h index 2f5dfed3..f498e0ea 100644 --- a/ext/libxml/ruby_xml_attributes.h +++ b/ext/libxml/ruby_xml_attributes.h @@ -1,17 +1,17 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#ifndef __RXML_ATTRIBUTES__ -#define __RXML_ATTRIBUTES__ - -#include - -extern VALUE cXMLAttributesibutes; - -void rxml_init_attributes(void); -VALUE rxml_attributes_new(xmlNodePtr xnode); - -VALUE rxml_attributes_attribute_get(VALUE self, VALUE name); -VALUE rxml_attributes_attribute_set(VALUE self, VALUE name, VALUE value); - - -#endif +/* Please see the LICENSE file for copyright and distribution information */ + +#ifndef __RXML_ATTRIBUTES__ +#define __RXML_ATTRIBUTES__ + +#include + +extern VALUE cXMLAttributesibutes; + +void rxml_init_attributes(void); +VALUE rxml_attributes_new(xmlNodePtr xnode); + +VALUE rxml_attributes_attribute_get(VALUE self, VALUE name); +VALUE rxml_attributes_attribute_set(VALUE self, VALUE name, VALUE value); + + +#endif diff --git a/ext/libxml/ruby_xml_document.c b/ext/libxml/ruby_xml_document.c index fe39a8d2..59c0a39b 100644 --- a/ext/libxml/ruby_xml_document.c +++ b/ext/libxml/ruby_xml_document.c @@ -1,1129 +1,1129 @@ -/* - * Document-class: LibXML::XML::Document - * - * The XML::Document class provides a tree based API for working - * with xml documents. You may directly create a document and - * manipulate it, or create a document from a data source by - * using an XML::Parser object. - * - * To read a document from a file: - * - * doc = XML::Document.file('my_file') - * - * To use a parser to read a document: - * - * parser = XML::Parser.file('my_file') - * doc = parser.parse - * - * To create a document from scratch: - * - * doc = XML::Document.new() - * doc.root = XML::Node.new('root_node') - * doc.root << XML::Node.new('elem1') - * doc.save(filename, :indent => true, :encoding => XML::Encoding::UTF_8) - * - * To write a document to a file: - * - * doc = XML::Document.new() - * doc.root = XML::Node.new('root_node') - * root = doc.root - * - * root << elem1 = XML::Node.new('elem1') - * elem1['attr1'] = 'val1' - * elem1['attr2'] = 'val2' - * - * root << elem2 = XML::Node.new('elem2') - * elem2['attr1'] = 'val1' - * elem2['attr2'] = 'val2' - * - * root << elem3 = XML::Node.new('elem3') - * elem3 << elem4 = XML::Node.new('elem4') - * elem3 << elem5 = XML::Node.new('elem5') - * - * elem5 << elem6 = XML::Node.new('elem6') - * elem6 << 'Content for element 6' - * - * elem3['attr'] = 'baz' - * - * doc.save(filename, :indent => true, :encoding => XML::Encoding::UTF_8) - */ - -#include -#include "ruby_libxml.h" -#include "ruby_xml_document.h" - -#include -#include -#include -#include -#include - -VALUE cXMLDocument; - -void rxml_document_free(xmlDocPtr xdoc) -{ - xdoc->_private = NULL; - xmlFreeDoc(xdoc); -} - -VALUE rxml_document_wrap(xmlDocPtr xdoc) -{ - VALUE result = Qnil; - - // Is this node is already wrapped? - if (xdoc->_private != NULL) - { - result = (VALUE)xdoc->_private; - } - else - { - result = Data_Wrap_Struct(cXMLDocument, NULL, rxml_document_free, xdoc); - xdoc->_private = (void*)result; - } - - return result; -} - -/* - * call-seq: - * XML::Document.alloc(xml_version = 1.0) -> document - * - * Alocates a new XML::Document, optionally specifying the - * XML version. - */ -static VALUE rxml_document_alloc(VALUE klass) -{ - return Data_Wrap_Struct(klass, NULL, rxml_document_free, NULL); -} - -/* - * call-seq: - * XML::Document.initialize(xml_version = 1.0) -> document - * - * Initializes a new XML::Document, optionally specifying the - * XML version. - */ -static VALUE rxml_document_initialize(int argc, VALUE *argv, VALUE self) -{ - xmlDocPtr xdoc; - VALUE xmlver; - - switch (argc) - { - case 0: - xmlver = rb_str_new2("1.0"); - break; - case 1: - rb_scan_args(argc, argv, "01", &xmlver); - break; - default: - rb_raise(rb_eArgError, "wrong number of arguments (need 0 or 1)"); - } - - Check_Type(xmlver, T_STRING); - xdoc = xmlNewDoc((xmlChar*) StringValuePtr(xmlver)); - - // Link the ruby object to the document and the document to the ruby object - RDATA(self)->data = xdoc; - xdoc->_private = (void*)self; - - return self; -} - -/* XML_C14N_1* constants are not defined until libxml 1.1.25, so if they - are not defined then define these constants to map to zero, - the same value as XML_C14N_1_0. */ - -/* XML_C14N* constants are not defined until libxml 1.1.25, so define them - if needed so things compile. */ -#ifndef XML_C14N_1_0 -#define XML_C14N_1_0 0 -#define XML_C14N_EXCLUSIVE_1_0 XML_C14N_1_0 -#define XML_C14N_1_1 XML_C14N_1_0 -#endif - -/* - * :call-seq: - * document.canonicalize -> String - * document.canonicalize(options) -> String - * - * Returns a string containing the canonicalized form of the document. - * Implemented to include all of the functionality of the libxml2 - * {xmlC14NDocDumpMemory}[http://xmlsoft.org/html/libxml-c14n.html#xmlC14NDocDumpMemory] - * method. - * - * === Options - * [comments] - * * *Type:* Boolean - * * *Default:* false - * Specifies if comments should be output. - * * Must be boolean, otherwise defaults to false. - * [inclusive_ns_prefixes] - * * *Type:* Array of strings - * * *Default:* empty array - * Array of namespace prefixes to include in exclusive canonicalization only. - * * The last item in the list is reserved for a NULL value because the C method demands it, therefore - * up to the first 255 valid entries will be used. - * * Only used for *XML_C14N_EXCLUSIVE_1_0* mode. Ignored otherwise. - * [mode] - * * *Type:* XML::Document Constant - * * *Default:* XML_C14N_1_0 - * Specifies the mode of canonicalization. - * * *NOTE:* XML_C14N_1_1 may not be fully implemented upon compilation due to C library compatibility. - * Please check if XML_C14N_1_0 and XML_C14N_1_1 are the same value prior to using XML_C14N_1_1. - * [nodes] - * * *Type:* Array of XML::Node objects - * * *Default:* empty array - * XML::Nodes to include in the canonicalization process - * * For large lists of more than 256 valid namespaces, up to the first 256 valid entries will be used. - */ -#define C14N_NS_LIMIT 256 -#define C14N_NODESET_LIMIT 256 - -static VALUE -rxml_document_canonicalize(int argc, VALUE *argv, VALUE self) -{ - VALUE result = Qnil; - xmlDocPtr xdoc; - xmlChar *buffer = NULL; - VALUE option_hash = Qnil; - VALUE o_nodes = Qnil; - - // :comments option - int comments = 0; - // :mode option - int c14n_mode = XML_C14N_1_0; - // :inclusive_ns_prefixes option (ARRAY) - - xmlChar * inc_ns_prefixes_ptr[C14N_NS_LIMIT]; - - // :nodes option (ARRAY) - xmlNodePtr node_ptr_array[C14N_NODESET_LIMIT]; - xmlNodeSet nodeset = { - 0, C14N_NODESET_LIMIT, NULL - }; - - /* At least one NULL value must be defined in the array or the extension will - * segfault when using XML_C14N_EXCLUSIVE_1_0 mode. - * API docs: "list of inclusive namespace prefixes ended with a NULL" - */ - inc_ns_prefixes_ptr[0] = NULL; - - rb_scan_args(argc, argv, "01", &option_hash); - // Do stuff if ruby hash passed as argument - if (!NIL_P(option_hash)) - { - VALUE o_comments = Qnil; - VALUE o_mode = Qnil; - VALUE o_i_ns_prefixes = Qnil; - - Check_Type(option_hash, T_HASH); - - o_comments = rb_hash_aref(option_hash, ID2SYM(rb_intern("comments"))); - comments = (RTEST(o_comments) ? 1 : 0); - - o_mode = rb_hash_aref(option_hash, ID2SYM(rb_intern("mode"))); - if (!NIL_P(o_mode)) - { - Check_Type(o_mode, T_FIXNUM); - c14n_mode = NUM2INT(o_mode); - //TODO: clean this up - //if (c14n_mode > 2) { c14n_mode = 0; } - //mode_int = (NUM2INT(o_mode) > 2 ? 0 : NUM2INT(o_mode)); - } - - o_i_ns_prefixes = rb_hash_aref(option_hash, ID2SYM(rb_intern("inclusive_ns_prefixes"))); - if (!NIL_P(o_i_ns_prefixes)) - { - int i; - int p = 0; //pointer array index - VALUE *list_in = NULL; - long list_size = 0; - - Check_Type(o_i_ns_prefixes, T_ARRAY); - list_in = RARRAY_PTR(o_i_ns_prefixes); - list_size = RARRAY_LEN(o_i_ns_prefixes); - - if (list_size > 0) - { - for(i=0; i < list_size; ++i) { - if (p >= C14N_NS_LIMIT) { break; } - - if (RTEST(list_in[i])) - { - if (TYPE(list_in[i]) == T_STRING) - { - inc_ns_prefixes_ptr[p] = (xmlChar *)StringValueCStr(list_in[i]); - p++; - } - } - } - } - - // ensure p is not out of bound - p = (p >= C14N_NS_LIMIT ? (C14N_NS_LIMIT-1) : p); - - // API docs: "list of inclusive namespace prefixes ended with a NULL" - // Set last element to NULL - inc_ns_prefixes_ptr[p] = NULL; - } - //o_ns_prefixes will free at end of block - - o_nodes = rb_hash_aref(option_hash, ID2SYM(rb_intern("nodes"))); - if (!NIL_P(o_nodes)) - { - int i; - int p = 0; // index of pointer array - VALUE * list_in = NULL; - long node_list_size = 0; - - if (CLASS_OF(o_nodes) == cXMLXPathObject) - { - o_nodes = rb_funcall(o_nodes, rb_intern("to_a"), 0); - } - else - { - Check_Type(o_nodes, T_ARRAY); - } - list_in = RARRAY_PTR(o_nodes); - node_list_size = RARRAY_LEN(o_nodes); - - for (i=0; i < node_list_size; ++i) - { - if (p >= C14N_NODESET_LIMIT) { break; } - - if (RTEST(list_in[i])) - { - xmlNodePtr node_ptr; - Data_Get_Struct(list_in[i], xmlNode, node_ptr); - node_ptr_array[p] = node_ptr; - p++; - } - } - - // Need to set values in nodeset struct - nodeset.nodeNr = (node_list_size > C14N_NODESET_LIMIT ? - C14N_NODESET_LIMIT : - (int)node_list_size); - nodeset.nodeTab = node_ptr_array; - } - }//option_hash - - Data_Get_Struct(self, xmlDoc, xdoc); - xmlC14NDocDumpMemory(xdoc, - (nodeset.nodeNr == 0 ? NULL : &nodeset), - c14n_mode, - inc_ns_prefixes_ptr, - comments, - &buffer); - - if (buffer) - { - result = rxml_new_cstr( buffer, NULL); - xmlFree(buffer); - } - - return result; -} - - -/* - * call-seq: - * document.compression -> num - * - * Obtain this document's compression mode identifier. - */ -static VALUE rxml_document_compression_get(VALUE self) -{ -#ifdef HAVE_ZLIB_H - xmlDocPtr xdoc; - - int compmode; - Data_Get_Struct(self, xmlDoc, xdoc); - - compmode = xmlGetDocCompressMode(xdoc); - if (compmode == -1) - return(Qnil); - else - return(INT2NUM(compmode)); -#else - rb_warn("libxml not compiled with zlib support"); - return (Qfalse); -#endif -} - -/* - * call-seq: - * document.compression = num - * - * Set this document's compression mode. - */ -static VALUE rxml_document_compression_set(VALUE self, VALUE num) -{ -#ifdef HAVE_ZLIB_H - xmlDocPtr xdoc; - - int compmode; - Check_Type(num, T_FIXNUM); - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc == NULL) - { - return(Qnil); - } - else - { - xmlSetDocCompressMode(xdoc, NUM2INT(num)); - - compmode = xmlGetDocCompressMode(xdoc); - if (compmode == -1) - return(Qnil); - else - return(INT2NUM(compmode)); - } -#else - rb_warn("libxml compiled without zlib support"); - return (Qfalse); -#endif -} - -/* - * call-seq: - * document.compression? -> (true|false) - * - * Determine whether this document is compressed. - */ -static VALUE rxml_document_compression_q(VALUE self) -{ -#ifdef HAVE_ZLIB_H - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->compression != -1) - return(Qtrue); - else - return(Qfalse); -#else - rb_warn("libxml compiled without zlib support"); - return (Qfalse); -#endif -} - -/* - * call-seq: - * document.child -> node - * - * Get this document's child node. - */ -static VALUE rxml_document_child_get(VALUE self) -{ - xmlDocPtr xdoc; - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->children == NULL) - return (Qnil); - - return rxml_node_wrap(xdoc->children); -} - -/* - * call-seq: - * document.child? -> (true|false) - * - * Determine whether this document has a child node. - */ -static VALUE rxml_document_child_q(VALUE self) -{ - xmlDocPtr xdoc; - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->children == NULL) - return (Qfalse); - else - return (Qtrue); -} - - -/* - * call-seq: - * node.debug -> true|false - * - * Print libxml debugging information to stdout. - * Requires that libxml was compiled with debugging enabled. -*/ -static VALUE rxml_document_debug(VALUE self) -{ -#ifdef LIBXML_DEBUG_ENABLED - xmlDocPtr xdoc; - Data_Get_Struct(self, xmlDoc, xdoc); - xmlDebugDumpDocument(NULL, xdoc); - return Qtrue; -#else - rb_warn("libxml was compiled without debugging support."); - return Qfalse; -#endif -} - -/* - * call-seq: - * document.encoding -> XML::Encoding::UTF_8 - * - * Returns the LibXML encoding constant specified by this document. - */ -static VALUE rxml_document_encoding_get(VALUE self) -{ - xmlDocPtr xdoc; - const char *xencoding; - Data_Get_Struct(self, xmlDoc, xdoc); - - xencoding = (const char*)xdoc->encoding; - return INT2NUM(xmlParseCharEncoding(xencoding)); -} - - -/* - * call-seq: - * document.rb_encoding -> Encoding - * - * Returns the Ruby encoding specified by this document - * (available on Ruby 1.9.x and higher). - */ -static VALUE rxml_document_rb_encoding_get(VALUE self) -{ - xmlDocPtr xdoc; - rb_encoding* rbencoding; - Data_Get_Struct(self, xmlDoc, xdoc); - - rbencoding = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlParseCharEncoding((const char*)xdoc->encoding)); - return rb_enc_from_encoding(rbencoding); -} - -/* - * call-seq: - * document.encoding = XML::Encoding::UTF_8 - * - * Set the encoding for this document. - */ -static VALUE rxml_document_encoding_set(VALUE self, VALUE encoding) -{ - xmlDocPtr xdoc; - const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding)); - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->encoding != NULL) - xmlFree((xmlChar *) xdoc->encoding); - - xdoc->encoding = xmlStrdup((xmlChar *)xencoding); - return self; -} - -/* - * call-seq: - * document.import(node) -> XML::Node - * - * Creates a copy of the node that can be inserted into the - * current document. - * - * IMPORTANT - The returned node MUST be inserted into the document. - * This is because the returned node refereces internal LibXML data - * structures owned by the document. Therefore, if the document is - * is freed before the the node is freed a segmentation fault will occur. - */ -static VALUE rxml_document_import(VALUE self, VALUE node) -{ - xmlDocPtr xdoc; - xmlNodePtr xnode, xresult; - - Data_Get_Struct(self, xmlDoc, xdoc); - Data_Get_Struct(node, xmlNode, xnode); - - xresult = xmlDocCopyNode(xnode, xdoc, 1); - - if (xresult == NULL) - rxml_raise(xmlGetLastError()); - - return rxml_node_wrap(xresult); -} - -/* - * call-seq: - * document.last -> node - * - * Obtain the last node. - */ -static VALUE rxml_document_last_get(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->last == NULL) - return (Qnil); - - return rxml_node_wrap(xdoc->last); -} - -/* - * call-seq: - * document.last? -> (true|false) - * - * Determine whether there is a last node. - */ -static VALUE rxml_document_last_q(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->last == NULL) - return (Qfalse); - else - return (Qtrue); -} - -/* - * call-seq: - * document.next -> node - * - * Obtain the next node. - */ -static VALUE rxml_document_next_get(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->next == NULL) - return (Qnil); - - return rxml_node_wrap(xdoc->next); -} - -/* - * call-seq: - * document.next? -> (true|false) - * - * Determine whether there is a next node. - */ -static VALUE rxml_document_next_q(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->next == NULL) - return (Qfalse); - else - return (Qtrue); -} - -/* - * call-seq: - * node.type -> num - * - * Obtain this node's type identifier. - */ -static VALUE rxml_document_node_type(VALUE self) -{ - xmlNodePtr xnode; - Data_Get_Struct(self, xmlNode, xnode); - return (INT2NUM(xnode->type)); -} - -/* - * call-seq: - * document.parent -> node - * - * Obtain the parent node. - */ -static VALUE rxml_document_parent_get(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->parent == NULL) - return (Qnil); - - return rxml_node_wrap(xdoc->parent); -} - -/* - * call-seq: - * document.parent? -> (true|false) - * - * Determine whether there is a parent node. - */ -static VALUE rxml_document_parent_q(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->parent == NULL) - return (Qfalse); - else - return (Qtrue); -} - -/* - * call-seq: - * document.prev -> node - * - * Obtain the previous node. - */ -static VALUE rxml_document_prev_get(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->prev == NULL) - return (Qnil); - - return rxml_node_wrap(xdoc->prev); -} - -/* - * call-seq: - * document.prev? -> (true|false) - * - * Determine whether there is a previous node. - */ -static VALUE rxml_document_prev_q(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - - if (xdoc->prev == NULL) - return (Qfalse); - else - return (Qtrue); -} - -/* - * call-seq: - * document.root -> node - * - * Obtain the root node. - */ -static VALUE rxml_document_root_get(VALUE self) -{ - xmlDocPtr xdoc; - xmlNodePtr root; - - Data_Get_Struct(self, xmlDoc, xdoc); - root = xmlDocGetRootElement(xdoc); - - if (root == NULL) - return (Qnil); - - return rxml_node_wrap(root); -} - -/* - * call-seq: - * document.root = node - * - * Set the root node. - */ -static VALUE rxml_document_root_set(VALUE self, VALUE node) -{ - xmlDocPtr xdoc; - xmlNodePtr xnode; - - if (rb_obj_is_kind_of(node, cXMLNode) == Qfalse) - rb_raise(rb_eTypeError, "must pass an XML::Node type object"); - - Data_Get_Struct(self, xmlDoc, xdoc); - Data_Get_Struct(node, xmlNode, xnode); - - if (xnode->doc != NULL && xnode->doc != xdoc) - rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import"); - - xmlDocSetRootElement(xdoc, xnode); - - // Ruby no longer manages this nodes memory - rxml_node_unmanage(xnode, node); - - return node; -} - -/* - * call-seq: - * document.save(filename) -> int - * document.save(filename, :indent => true, :encoding => XML::Encoding::UTF_8) -> int - * - * Saves a document to a file. You may provide an optional hash table - * to control how the string is generated. Valid options are: - * - * :indent - Specifies if the string should be indented. The default value - * is true. Note that indentation is only added if both :indent is - * true and XML.indent_tree_output is true. If :indent is set to false, - * then both indentation and line feeds are removed from the result. - * - * :encoding - Specifies the output encoding of the string. It - * defaults to the original encoding of the document (see - * #encoding. To override the orginal encoding, use one of the - * XML::Encoding encoding constants. */ -static VALUE rxml_document_save(int argc, VALUE *argv, VALUE self) -{ - VALUE options = Qnil; - VALUE filename = Qnil; - xmlDocPtr xdoc; - int indent = 1; - const char *xfilename; - const xmlChar *xencoding; - int length; - - rb_scan_args(argc, argv, "11", &filename, &options); - - Check_Type(filename, T_STRING); - xfilename = StringValuePtr(filename); - - Data_Get_Struct(self, xmlDoc, xdoc); - xencoding = xdoc->encoding; - - if (!NIL_P(options)) - { - VALUE rencoding, rindent; - Check_Type(options, T_HASH); - rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding"))); - rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent"))); - - if (rindent == Qfalse) - indent = 0; - - if (rencoding != Qnil) - { - xencoding = (const xmlChar*)xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding)); - if (!xencoding) - rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding)); - } - } - - length = xmlSaveFormatFileEnc(xfilename, xdoc, (const char*)xencoding, indent); - - if (length == -1) - rxml_raise(xmlGetLastError()); - - return (INT2NUM(length)); -} - -/* - * call-seq: - * document.standalone? -> (true|false) - * - * Determine whether this is a standalone document. - */ -static VALUE rxml_document_standalone_q(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - if (xdoc->standalone) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * document.to_s -> "string" - * document.to_s(:indent => true, :encoding => XML::Encoding::UTF_8) -> "string" - * - * Converts a document, and all of its children, to a string representation. - * You may provide an optional hash table to control how the string is - * generated. Valid options are: - * - * :indent - Specifies if the string should be indented. The default value - * is true. Note that indentation is only added if both :indent is - * true and XML.indent_tree_output is true. If :indent is set to false, - * then both indentation and line feeds are removed from the result. - * - * :encoding - Specifies the output encoding of the string. It - * defaults to XML::Encoding::UTF8. To change it, use one of the - * XML::Encoding encoding constants. */ -static VALUE rxml_document_to_s(int argc, VALUE *argv, VALUE self) -{ - VALUE result; - VALUE options = Qnil; - xmlDocPtr xdoc; - int indent = 1; - const xmlChar *xencoding = (const xmlChar*) "UTF-8"; - xmlChar *buffer; - int length; - - rb_scan_args(argc, argv, "01", &options); - - if (!NIL_P(options)) - { - VALUE rencoding, rindent; - Check_Type(options, T_HASH); - rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding"))); - rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent"))); - - if (rindent == Qfalse) - indent = 0; - - if (rencoding != Qnil) - { - xencoding = (const xmlChar*)xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding)); - if (!xencoding) - rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding)); - } - } - - Data_Get_Struct(self, xmlDoc, xdoc); - xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xencoding, indent); - - result = rxml_new_cstr(buffer, xencoding); - xmlFree(buffer); - return result; -} - -/* - * call-seq: - * document.url -> "url" - * - * Obtain this document's source URL, if any. - */ -static VALUE rxml_document_url_get(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - if (xdoc->URL == NULL) - return (Qnil); - else - return (rxml_new_cstr( xdoc->URL, NULL)); -} - -/* - * call-seq: - * document.version -> "version" - * - * Obtain the XML version specified by this document. - */ -static VALUE rxml_document_version_get(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - if (xdoc->version == NULL) - return (Qnil); - else - return (rxml_new_cstr( xdoc->version, NULL)); -} - -/* - * call-seq: - * document.xhtml? -> (true|false) - * - * Determine whether this is an XHTML document. - */ -static VALUE rxml_document_xhtml_q(VALUE self) -{ - xmlDocPtr xdoc; - xmlDtdPtr xdtd; - Data_Get_Struct(self, xmlDoc, xdoc); - xdtd = xmlGetIntSubset(xdoc); - if (xdtd != NULL && xmlIsXHTML(xdtd->SystemID, xdtd->ExternalID) > 0) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * document.xinclude -> num - * - * Process xinclude directives in this document. - */ -static VALUE rxml_document_xinclude(VALUE self) -{ -#ifdef LIBXML_XINCLUDE_ENABLED - xmlDocPtr xdoc; - - int ret; - - Data_Get_Struct(self, xmlDoc, xdoc); - ret = xmlXIncludeProcess(xdoc); - if (ret >= 0) - { - return(INT2NUM(ret)); - } - else - { - rxml_raise(xmlGetLastError()); - return Qnil; - } -#else - rb_warn( - "libxml was compiled without XInclude support. Please recompile libxml and ruby-libxml"); - return (Qfalse); -#endif -} - -/* - * call-seq: - * document.order_elements! - * - * Call this routine to speed up XPath computation on static documents. - * This stamps all the element nodes with the document order. - */ -static VALUE rxml_document_order_elements(VALUE self) -{ - xmlDocPtr xdoc; - - Data_Get_Struct(self, xmlDoc, xdoc); - return LONG2FIX(xmlXPathOrderDocElems(xdoc)); -} - -/* - * call-seq: - * document.validate_schema(schema) - * - * Validate this document against the specified XML::Schema. - * If the document is valid the method returns true. Otherwise an - * exception is raised with validation information. - */ -static VALUE rxml_document_validate_schema(VALUE self, VALUE schema) -{ - xmlSchemaValidCtxtPtr vptr; - xmlDocPtr xdoc; - xmlSchemaPtr xschema; - int is_invalid; - - Data_Get_Struct(self, xmlDoc, xdoc); - Data_Get_Struct(schema, xmlSchema, xschema); - - vptr = xmlSchemaNewValidCtxt(xschema); - - is_invalid = xmlSchemaValidateDoc(vptr, xdoc); - xmlSchemaFreeValidCtxt(vptr); - if (is_invalid) - { - rxml_raise(xmlGetLastError()); - return Qfalse; - } - else - { - return Qtrue; - } -} - -/* - * call-seq: - * document.validate_relaxng(relaxng) - * - * Validate this document against the specified XML::RelaxNG. - * If the document is valid the method returns true. Otherwise an - * exception is raised with validation information. - */ -static VALUE rxml_document_validate_relaxng(VALUE self, VALUE relaxng) -{ - xmlRelaxNGValidCtxtPtr vptr; - xmlDocPtr xdoc; - xmlRelaxNGPtr xrelaxng; - int is_invalid; - - Data_Get_Struct(self, xmlDoc, xdoc); - Data_Get_Struct(relaxng, xmlRelaxNG, xrelaxng); - - vptr = xmlRelaxNGNewValidCtxt(xrelaxng); - - is_invalid = xmlRelaxNGValidateDoc(vptr, xdoc); - xmlRelaxNGFreeValidCtxt(vptr); - if (is_invalid) - { - rxml_raise(xmlGetLastError()); - return Qfalse; - } - else - { - return Qtrue; - } -} - -/* - * call-seq: - * document.validate(dtd) -> (true|false) - * - * Validate this document against the specified XML::DTD. - * If the document is valid the method returns true. Otherwise an - * exception is raised with validation information. - */ -static VALUE rxml_document_validate_dtd(VALUE self, VALUE dtd) -{ - xmlValidCtxt ctxt; - xmlDocPtr xdoc; - xmlDtdPtr xdtd; - - Data_Get_Struct(self, xmlDoc, xdoc); - Data_Get_Struct(dtd, xmlDtd, xdtd); - - /* Setup context */ - memset(&ctxt, 0, sizeof(xmlValidCtxt)); - - if (xmlValidateDtd(&ctxt, xdoc, xdtd)) - { - return Qtrue; - } - else - { - rxml_raise(xmlGetLastError()); - return Qfalse; - } -} - -void rxml_init_document(void) -{ - cXMLDocument = rb_define_class_under(mXML, "Document", rb_cObject); - rb_define_alloc_func(cXMLDocument, rxml_document_alloc); - - /* Original C14N 1.0 spec */ - rb_define_const(cXMLDocument, "XML_C14N_1_0", INT2NUM(XML_C14N_1_0)); - /* Exclusive C14N 1.0 spec */ - rb_define_const(cXMLDocument, "XML_C14N_EXCLUSIVE_1_0", INT2NUM(XML_C14N_EXCLUSIVE_1_0)); - /* C14N 1.1 spec */ - rb_define_const(cXMLDocument, "XML_C14N_1_1", INT2NUM(XML_C14N_1_1)); - - rb_define_method(cXMLDocument, "initialize", rxml_document_initialize, -1); - rb_define_method(cXMLDocument, "canonicalize", rxml_document_canonicalize, -1); - rb_define_method(cXMLDocument, "child", rxml_document_child_get, 0); - rb_define_method(cXMLDocument, "child?", rxml_document_child_q, 0); - rb_define_method(cXMLDocument, "compression", rxml_document_compression_get, 0); - rb_define_method(cXMLDocument, "compression=", rxml_document_compression_set, 1); - rb_define_method(cXMLDocument, "compression?", rxml_document_compression_q, 0); - rb_define_method(cXMLDocument, "debug", rxml_document_debug, 0); - rb_define_method(cXMLDocument, "encoding", rxml_document_encoding_get, 0); - rb_define_method(cXMLDocument, "rb_encoding", rxml_document_rb_encoding_get, 0); - rb_define_method(cXMLDocument, "encoding=", rxml_document_encoding_set, 1); - rb_define_method(cXMLDocument, "import", rxml_document_import, 1); - rb_define_method(cXMLDocument, "last", rxml_document_last_get, 0); - rb_define_method(cXMLDocument, "last?", rxml_document_last_q, 0); - rb_define_method(cXMLDocument, "next", rxml_document_next_get, 0); - rb_define_method(cXMLDocument, "next?", rxml_document_next_q, 0); - rb_define_method(cXMLDocument, "node_type", rxml_document_node_type, 0); - rb_define_method(cXMLDocument, "order_elements!", rxml_document_order_elements, 0); - rb_define_method(cXMLDocument, "parent", rxml_document_parent_get, 0); - rb_define_method(cXMLDocument, "parent?", rxml_document_parent_q, 0); - rb_define_method(cXMLDocument, "prev", rxml_document_prev_get, 0); - rb_define_method(cXMLDocument, "prev?", rxml_document_prev_q, 0); - rb_define_method(cXMLDocument, "root", rxml_document_root_get, 0); - rb_define_method(cXMLDocument, "root=", rxml_document_root_set, 1); - rb_define_method(cXMLDocument, "save", rxml_document_save, -1); - rb_define_method(cXMLDocument, "standalone?", rxml_document_standalone_q, 0); - rb_define_method(cXMLDocument, "to_s", rxml_document_to_s, -1); - rb_define_method(cXMLDocument, "url", rxml_document_url_get, 0); - rb_define_method(cXMLDocument, "version", rxml_document_version_get, 0); - rb_define_method(cXMLDocument, "xhtml?", rxml_document_xhtml_q, 0); - rb_define_method(cXMLDocument, "xinclude", rxml_document_xinclude, 0); - rb_define_method(cXMLDocument, "validate", rxml_document_validate_dtd, 1); - rb_define_method(cXMLDocument, "validate_schema", rxml_document_validate_schema, 1); - rb_define_method(cXMLDocument, "validate_relaxng", rxml_document_validate_relaxng, 1); -} +/* + * Document-class: LibXML::XML::Document + * + * The XML::Document class provides a tree based API for working + * with xml documents. You may directly create a document and + * manipulate it, or create a document from a data source by + * using an XML::Parser object. + * + * To read a document from a file: + * + * doc = XML::Document.file('my_file') + * + * To use a parser to read a document: + * + * parser = XML::Parser.file('my_file') + * doc = parser.parse + * + * To create a document from scratch: + * + * doc = XML::Document.new() + * doc.root = XML::Node.new('root_node') + * doc.root << XML::Node.new('elem1') + * doc.save(filename, :indent => true, :encoding => XML::Encoding::UTF_8) + * + * To write a document to a file: + * + * doc = XML::Document.new() + * doc.root = XML::Node.new('root_node') + * root = doc.root + * + * root << elem1 = XML::Node.new('elem1') + * elem1['attr1'] = 'val1' + * elem1['attr2'] = 'val2' + * + * root << elem2 = XML::Node.new('elem2') + * elem2['attr1'] = 'val1' + * elem2['attr2'] = 'val2' + * + * root << elem3 = XML::Node.new('elem3') + * elem3 << elem4 = XML::Node.new('elem4') + * elem3 << elem5 = XML::Node.new('elem5') + * + * elem5 << elem6 = XML::Node.new('elem6') + * elem6 << 'Content for element 6' + * + * elem3['attr'] = 'baz' + * + * doc.save(filename, :indent => true, :encoding => XML::Encoding::UTF_8) + */ + +#include +#include "ruby_libxml.h" +#include "ruby_xml_document.h" + +#include +#include +#include +#include +#include + +VALUE cXMLDocument; + +void rxml_document_free(xmlDocPtr xdoc) +{ + xdoc->_private = NULL; + xmlFreeDoc(xdoc); +} + +VALUE rxml_document_wrap(xmlDocPtr xdoc) +{ + VALUE result = Qnil; + + // Is this node is already wrapped? + if (xdoc->_private != NULL) + { + result = (VALUE)xdoc->_private; + } + else + { + result = Data_Wrap_Struct(cXMLDocument, NULL, rxml_document_free, xdoc); + xdoc->_private = (void*)result; + } + + return result; +} + +/* + * call-seq: + * XML::Document.alloc(xml_version = 1.0) -> document + * + * Alocates a new XML::Document, optionally specifying the + * XML version. + */ +static VALUE rxml_document_alloc(VALUE klass) +{ + return Data_Wrap_Struct(klass, NULL, rxml_document_free, NULL); +} + +/* + * call-seq: + * XML::Document.initialize(xml_version = 1.0) -> document + * + * Initializes a new XML::Document, optionally specifying the + * XML version. + */ +static VALUE rxml_document_initialize(int argc, VALUE *argv, VALUE self) +{ + xmlDocPtr xdoc; + VALUE xmlver; + + switch (argc) + { + case 0: + xmlver = rb_str_new2("1.0"); + break; + case 1: + rb_scan_args(argc, argv, "01", &xmlver); + break; + default: + rb_raise(rb_eArgError, "wrong number of arguments (need 0 or 1)"); + } + + Check_Type(xmlver, T_STRING); + xdoc = xmlNewDoc((xmlChar*) StringValuePtr(xmlver)); + + // Link the ruby object to the document and the document to the ruby object + RDATA(self)->data = xdoc; + xdoc->_private = (void*)self; + + return self; +} + +/* XML_C14N_1* constants are not defined until libxml 1.1.25, so if they + are not defined then define these constants to map to zero, + the same value as XML_C14N_1_0. */ + +/* XML_C14N* constants are not defined until libxml 1.1.25, so define them + if needed so things compile. */ +#ifndef XML_C14N_1_0 +#define XML_C14N_1_0 0 +#define XML_C14N_EXCLUSIVE_1_0 XML_C14N_1_0 +#define XML_C14N_1_1 XML_C14N_1_0 +#endif + +/* + * :call-seq: + * document.canonicalize -> String + * document.canonicalize(options) -> String + * + * Returns a string containing the canonicalized form of the document. + * Implemented to include all of the functionality of the libxml2 + * {xmlC14NDocDumpMemory}[http://xmlsoft.org/html/libxml-c14n.html#xmlC14NDocDumpMemory] + * method. + * + * === Options + * [comments] + * * *Type:* Boolean + * * *Default:* false + * Specifies if comments should be output. + * * Must be boolean, otherwise defaults to false. + * [inclusive_ns_prefixes] + * * *Type:* Array of strings + * * *Default:* empty array + * Array of namespace prefixes to include in exclusive canonicalization only. + * * The last item in the list is reserved for a NULL value because the C method demands it, therefore + * up to the first 255 valid entries will be used. + * * Only used for *XML_C14N_EXCLUSIVE_1_0* mode. Ignored otherwise. + * [mode] + * * *Type:* XML::Document Constant + * * *Default:* XML_C14N_1_0 + * Specifies the mode of canonicalization. + * * *NOTE:* XML_C14N_1_1 may not be fully implemented upon compilation due to C library compatibility. + * Please check if XML_C14N_1_0 and XML_C14N_1_1 are the same value prior to using XML_C14N_1_1. + * [nodes] + * * *Type:* Array of XML::Node objects + * * *Default:* empty array + * XML::Nodes to include in the canonicalization process + * * For large lists of more than 256 valid namespaces, up to the first 256 valid entries will be used. + */ +#define C14N_NS_LIMIT 256 +#define C14N_NODESET_LIMIT 256 + +static VALUE +rxml_document_canonicalize(int argc, VALUE *argv, VALUE self) +{ + VALUE result = Qnil; + xmlDocPtr xdoc; + xmlChar *buffer = NULL; + VALUE option_hash = Qnil; + VALUE o_nodes = Qnil; + + // :comments option + int comments = 0; + // :mode option + int c14n_mode = XML_C14N_1_0; + // :inclusive_ns_prefixes option (ARRAY) + + xmlChar * inc_ns_prefixes_ptr[C14N_NS_LIMIT]; + + // :nodes option (ARRAY) + xmlNodePtr node_ptr_array[C14N_NODESET_LIMIT]; + xmlNodeSet nodeset = { + 0, C14N_NODESET_LIMIT, NULL + }; + + /* At least one NULL value must be defined in the array or the extension will + * segfault when using XML_C14N_EXCLUSIVE_1_0 mode. + * API docs: "list of inclusive namespace prefixes ended with a NULL" + */ + inc_ns_prefixes_ptr[0] = NULL; + + rb_scan_args(argc, argv, "01", &option_hash); + // Do stuff if ruby hash passed as argument + if (!NIL_P(option_hash)) + { + VALUE o_comments = Qnil; + VALUE o_mode = Qnil; + VALUE o_i_ns_prefixes = Qnil; + + Check_Type(option_hash, T_HASH); + + o_comments = rb_hash_aref(option_hash, ID2SYM(rb_intern("comments"))); + comments = (RTEST(o_comments) ? 1 : 0); + + o_mode = rb_hash_aref(option_hash, ID2SYM(rb_intern("mode"))); + if (!NIL_P(o_mode)) + { + Check_Type(o_mode, T_FIXNUM); + c14n_mode = NUM2INT(o_mode); + //TODO: clean this up + //if (c14n_mode > 2) { c14n_mode = 0; } + //mode_int = (NUM2INT(o_mode) > 2 ? 0 : NUM2INT(o_mode)); + } + + o_i_ns_prefixes = rb_hash_aref(option_hash, ID2SYM(rb_intern("inclusive_ns_prefixes"))); + if (!NIL_P(o_i_ns_prefixes)) + { + int i; + int p = 0; //pointer array index + VALUE *list_in = NULL; + long list_size = 0; + + Check_Type(o_i_ns_prefixes, T_ARRAY); + list_in = RARRAY_PTR(o_i_ns_prefixes); + list_size = RARRAY_LEN(o_i_ns_prefixes); + + if (list_size > 0) + { + for(i=0; i < list_size; ++i) { + if (p >= C14N_NS_LIMIT) { break; } + + if (RTEST(list_in[i])) + { + if (TYPE(list_in[i]) == T_STRING) + { + inc_ns_prefixes_ptr[p] = (xmlChar *)StringValueCStr(list_in[i]); + p++; + } + } + } + } + + // ensure p is not out of bound + p = (p >= C14N_NS_LIMIT ? (C14N_NS_LIMIT-1) : p); + + // API docs: "list of inclusive namespace prefixes ended with a NULL" + // Set last element to NULL + inc_ns_prefixes_ptr[p] = NULL; + } + //o_ns_prefixes will free at end of block + + o_nodes = rb_hash_aref(option_hash, ID2SYM(rb_intern("nodes"))); + if (!NIL_P(o_nodes)) + { + int i; + int p = 0; // index of pointer array + VALUE * list_in = NULL; + long node_list_size = 0; + + if (CLASS_OF(o_nodes) == cXMLXPathObject) + { + o_nodes = rb_funcall(o_nodes, rb_intern("to_a"), 0); + } + else + { + Check_Type(o_nodes, T_ARRAY); + } + list_in = RARRAY_PTR(o_nodes); + node_list_size = RARRAY_LEN(o_nodes); + + for (i=0; i < node_list_size; ++i) + { + if (p >= C14N_NODESET_LIMIT) { break; } + + if (RTEST(list_in[i])) + { + xmlNodePtr node_ptr; + Data_Get_Struct(list_in[i], xmlNode, node_ptr); + node_ptr_array[p] = node_ptr; + p++; + } + } + + // Need to set values in nodeset struct + nodeset.nodeNr = (node_list_size > C14N_NODESET_LIMIT ? + C14N_NODESET_LIMIT : + (int)node_list_size); + nodeset.nodeTab = node_ptr_array; + } + }//option_hash + + Data_Get_Struct(self, xmlDoc, xdoc); + xmlC14NDocDumpMemory(xdoc, + (nodeset.nodeNr == 0 ? NULL : &nodeset), + c14n_mode, + inc_ns_prefixes_ptr, + comments, + &buffer); + + if (buffer) + { + result = rxml_new_cstr( buffer, NULL); + xmlFree(buffer); + } + + return result; +} + + +/* + * call-seq: + * document.compression -> num + * + * Obtain this document's compression mode identifier. + */ +static VALUE rxml_document_compression_get(VALUE self) +{ +#ifdef HAVE_ZLIB_H + xmlDocPtr xdoc; + + int compmode; + Data_Get_Struct(self, xmlDoc, xdoc); + + compmode = xmlGetDocCompressMode(xdoc); + if (compmode == -1) + return(Qnil); + else + return(INT2NUM(compmode)); +#else + rb_warn("libxml not compiled with zlib support"); + return (Qfalse); +#endif +} + +/* + * call-seq: + * document.compression = num + * + * Set this document's compression mode. + */ +static VALUE rxml_document_compression_set(VALUE self, VALUE num) +{ +#ifdef HAVE_ZLIB_H + xmlDocPtr xdoc; + + int compmode; + Check_Type(num, T_FIXNUM); + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc == NULL) + { + return(Qnil); + } + else + { + xmlSetDocCompressMode(xdoc, NUM2INT(num)); + + compmode = xmlGetDocCompressMode(xdoc); + if (compmode == -1) + return(Qnil); + else + return(INT2NUM(compmode)); + } +#else + rb_warn("libxml compiled without zlib support"); + return (Qfalse); +#endif +} + +/* + * call-seq: + * document.compression? -> (true|false) + * + * Determine whether this document is compressed. + */ +static VALUE rxml_document_compression_q(VALUE self) +{ +#ifdef HAVE_ZLIB_H + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->compression != -1) + return(Qtrue); + else + return(Qfalse); +#else + rb_warn("libxml compiled without zlib support"); + return (Qfalse); +#endif +} + +/* + * call-seq: + * document.child -> node + * + * Get this document's child node. + */ +static VALUE rxml_document_child_get(VALUE self) +{ + xmlDocPtr xdoc; + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->children == NULL) + return (Qnil); + + return rxml_node_wrap(xdoc->children); +} + +/* + * call-seq: + * document.child? -> (true|false) + * + * Determine whether this document has a child node. + */ +static VALUE rxml_document_child_q(VALUE self) +{ + xmlDocPtr xdoc; + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->children == NULL) + return (Qfalse); + else + return (Qtrue); +} + + +/* + * call-seq: + * node.debug -> true|false + * + * Print libxml debugging information to stdout. + * Requires that libxml was compiled with debugging enabled. +*/ +static VALUE rxml_document_debug(VALUE self) +{ +#ifdef LIBXML_DEBUG_ENABLED + xmlDocPtr xdoc; + Data_Get_Struct(self, xmlDoc, xdoc); + xmlDebugDumpDocument(NULL, xdoc); + return Qtrue; +#else + rb_warn("libxml was compiled without debugging support."); + return Qfalse; +#endif +} + +/* + * call-seq: + * document.encoding -> XML::Encoding::UTF_8 + * + * Returns the LibXML encoding constant specified by this document. + */ +static VALUE rxml_document_encoding_get(VALUE self) +{ + xmlDocPtr xdoc; + const char *xencoding; + Data_Get_Struct(self, xmlDoc, xdoc); + + xencoding = (const char*)xdoc->encoding; + return INT2NUM(xmlParseCharEncoding(xencoding)); +} + + +/* + * call-seq: + * document.rb_encoding -> Encoding + * + * Returns the Ruby encoding specified by this document + * (available on Ruby 1.9.x and higher). + */ +static VALUE rxml_document_rb_encoding_get(VALUE self) +{ + xmlDocPtr xdoc; + rb_encoding* rbencoding; + Data_Get_Struct(self, xmlDoc, xdoc); + + rbencoding = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlParseCharEncoding((const char*)xdoc->encoding)); + return rb_enc_from_encoding(rbencoding); +} + +/* + * call-seq: + * document.encoding = XML::Encoding::UTF_8 + * + * Set the encoding for this document. + */ +static VALUE rxml_document_encoding_set(VALUE self, VALUE encoding) +{ + xmlDocPtr xdoc; + const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding)); + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->encoding != NULL) + xmlFree((xmlChar *) xdoc->encoding); + + xdoc->encoding = xmlStrdup((xmlChar *)xencoding); + return self; +} + +/* + * call-seq: + * document.import(node) -> XML::Node + * + * Creates a copy of the node that can be inserted into the + * current document. + * + * IMPORTANT - The returned node MUST be inserted into the document. + * This is because the returned node refereces internal LibXML data + * structures owned by the document. Therefore, if the document is + * is freed before the the node is freed a segmentation fault will occur. + */ +static VALUE rxml_document_import(VALUE self, VALUE node) +{ + xmlDocPtr xdoc; + xmlNodePtr xnode, xresult; + + Data_Get_Struct(self, xmlDoc, xdoc); + Data_Get_Struct(node, xmlNode, xnode); + + xresult = xmlDocCopyNode(xnode, xdoc, 1); + + if (xresult == NULL) + rxml_raise(xmlGetLastError()); + + return rxml_node_wrap(xresult); +} + +/* + * call-seq: + * document.last -> node + * + * Obtain the last node. + */ +static VALUE rxml_document_last_get(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->last == NULL) + return (Qnil); + + return rxml_node_wrap(xdoc->last); +} + +/* + * call-seq: + * document.last? -> (true|false) + * + * Determine whether there is a last node. + */ +static VALUE rxml_document_last_q(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->last == NULL) + return (Qfalse); + else + return (Qtrue); +} + +/* + * call-seq: + * document.next -> node + * + * Obtain the next node. + */ +static VALUE rxml_document_next_get(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->next == NULL) + return (Qnil); + + return rxml_node_wrap(xdoc->next); +} + +/* + * call-seq: + * document.next? -> (true|false) + * + * Determine whether there is a next node. + */ +static VALUE rxml_document_next_q(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->next == NULL) + return (Qfalse); + else + return (Qtrue); +} + +/* + * call-seq: + * node.type -> num + * + * Obtain this node's type identifier. + */ +static VALUE rxml_document_node_type(VALUE self) +{ + xmlNodePtr xnode; + Data_Get_Struct(self, xmlNode, xnode); + return (INT2NUM(xnode->type)); +} + +/* + * call-seq: + * document.parent -> node + * + * Obtain the parent node. + */ +static VALUE rxml_document_parent_get(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->parent == NULL) + return (Qnil); + + return rxml_node_wrap(xdoc->parent); +} + +/* + * call-seq: + * document.parent? -> (true|false) + * + * Determine whether there is a parent node. + */ +static VALUE rxml_document_parent_q(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->parent == NULL) + return (Qfalse); + else + return (Qtrue); +} + +/* + * call-seq: + * document.prev -> node + * + * Obtain the previous node. + */ +static VALUE rxml_document_prev_get(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->prev == NULL) + return (Qnil); + + return rxml_node_wrap(xdoc->prev); +} + +/* + * call-seq: + * document.prev? -> (true|false) + * + * Determine whether there is a previous node. + */ +static VALUE rxml_document_prev_q(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + + if (xdoc->prev == NULL) + return (Qfalse); + else + return (Qtrue); +} + +/* + * call-seq: + * document.root -> node + * + * Obtain the root node. + */ +static VALUE rxml_document_root_get(VALUE self) +{ + xmlDocPtr xdoc; + xmlNodePtr root; + + Data_Get_Struct(self, xmlDoc, xdoc); + root = xmlDocGetRootElement(xdoc); + + if (root == NULL) + return (Qnil); + + return rxml_node_wrap(root); +} + +/* + * call-seq: + * document.root = node + * + * Set the root node. + */ +static VALUE rxml_document_root_set(VALUE self, VALUE node) +{ + xmlDocPtr xdoc; + xmlNodePtr xnode; + + if (rb_obj_is_kind_of(node, cXMLNode) == Qfalse) + rb_raise(rb_eTypeError, "must pass an XML::Node type object"); + + Data_Get_Struct(self, xmlDoc, xdoc); + Data_Get_Struct(node, xmlNode, xnode); + + if (xnode->doc != NULL && xnode->doc != xdoc) + rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import"); + + xmlDocSetRootElement(xdoc, xnode); + + // Ruby no longer manages this nodes memory + rxml_node_unmanage(xnode, node); + + return node; +} + +/* + * call-seq: + * document.save(filename) -> int + * document.save(filename, :indent => true, :encoding => XML::Encoding::UTF_8) -> int + * + * Saves a document to a file. You may provide an optional hash table + * to control how the string is generated. Valid options are: + * + * :indent - Specifies if the string should be indented. The default value + * is true. Note that indentation is only added if both :indent is + * true and XML.indent_tree_output is true. If :indent is set to false, + * then both indentation and line feeds are removed from the result. + * + * :encoding - Specifies the output encoding of the string. It + * defaults to the original encoding of the document (see + * #encoding. To override the orginal encoding, use one of the + * XML::Encoding encoding constants. */ +static VALUE rxml_document_save(int argc, VALUE *argv, VALUE self) +{ + VALUE options = Qnil; + VALUE filename = Qnil; + xmlDocPtr xdoc; + int indent = 1; + const char *xfilename; + const xmlChar *xencoding; + int length; + + rb_scan_args(argc, argv, "11", &filename, &options); + + Check_Type(filename, T_STRING); + xfilename = StringValuePtr(filename); + + Data_Get_Struct(self, xmlDoc, xdoc); + xencoding = xdoc->encoding; + + if (!NIL_P(options)) + { + VALUE rencoding, rindent; + Check_Type(options, T_HASH); + rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding"))); + rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent"))); + + if (rindent == Qfalse) + indent = 0; + + if (rencoding != Qnil) + { + xencoding = (const xmlChar*)xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding)); + if (!xencoding) + rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding)); + } + } + + length = xmlSaveFormatFileEnc(xfilename, xdoc, (const char*)xencoding, indent); + + if (length == -1) + rxml_raise(xmlGetLastError()); + + return (INT2NUM(length)); +} + +/* + * call-seq: + * document.standalone? -> (true|false) + * + * Determine whether this is a standalone document. + */ +static VALUE rxml_document_standalone_q(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + if (xdoc->standalone) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * document.to_s -> "string" + * document.to_s(:indent => true, :encoding => XML::Encoding::UTF_8) -> "string" + * + * Converts a document, and all of its children, to a string representation. + * You may provide an optional hash table to control how the string is + * generated. Valid options are: + * + * :indent - Specifies if the string should be indented. The default value + * is true. Note that indentation is only added if both :indent is + * true and XML.indent_tree_output is true. If :indent is set to false, + * then both indentation and line feeds are removed from the result. + * + * :encoding - Specifies the output encoding of the string. It + * defaults to XML::Encoding::UTF8. To change it, use one of the + * XML::Encoding encoding constants. */ +static VALUE rxml_document_to_s(int argc, VALUE *argv, VALUE self) +{ + VALUE result; + VALUE options = Qnil; + xmlDocPtr xdoc; + int indent = 1; + const xmlChar *xencoding = (const xmlChar*) "UTF-8"; + xmlChar *buffer; + int length; + + rb_scan_args(argc, argv, "01", &options); + + if (!NIL_P(options)) + { + VALUE rencoding, rindent; + Check_Type(options, T_HASH); + rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding"))); + rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent"))); + + if (rindent == Qfalse) + indent = 0; + + if (rencoding != Qnil) + { + xencoding = (const xmlChar*)xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding)); + if (!xencoding) + rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding)); + } + } + + Data_Get_Struct(self, xmlDoc, xdoc); + xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xencoding, indent); + + result = rxml_new_cstr(buffer, xencoding); + xmlFree(buffer); + return result; +} + +/* + * call-seq: + * document.url -> "url" + * + * Obtain this document's source URL, if any. + */ +static VALUE rxml_document_url_get(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + if (xdoc->URL == NULL) + return (Qnil); + else + return (rxml_new_cstr( xdoc->URL, NULL)); +} + +/* + * call-seq: + * document.version -> "version" + * + * Obtain the XML version specified by this document. + */ +static VALUE rxml_document_version_get(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + if (xdoc->version == NULL) + return (Qnil); + else + return (rxml_new_cstr( xdoc->version, NULL)); +} + +/* + * call-seq: + * document.xhtml? -> (true|false) + * + * Determine whether this is an XHTML document. + */ +static VALUE rxml_document_xhtml_q(VALUE self) +{ + xmlDocPtr xdoc; + xmlDtdPtr xdtd; + Data_Get_Struct(self, xmlDoc, xdoc); + xdtd = xmlGetIntSubset(xdoc); + if (xdtd != NULL && xmlIsXHTML(xdtd->SystemID, xdtd->ExternalID) > 0) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * document.xinclude -> num + * + * Process xinclude directives in this document. + */ +static VALUE rxml_document_xinclude(VALUE self) +{ +#ifdef LIBXML_XINCLUDE_ENABLED + xmlDocPtr xdoc; + + int ret; + + Data_Get_Struct(self, xmlDoc, xdoc); + ret = xmlXIncludeProcess(xdoc); + if (ret >= 0) + { + return(INT2NUM(ret)); + } + else + { + rxml_raise(xmlGetLastError()); + return Qnil; + } +#else + rb_warn( + "libxml was compiled without XInclude support. Please recompile libxml and ruby-libxml"); + return (Qfalse); +#endif +} + +/* + * call-seq: + * document.order_elements! + * + * Call this routine to speed up XPath computation on static documents. + * This stamps all the element nodes with the document order. + */ +static VALUE rxml_document_order_elements(VALUE self) +{ + xmlDocPtr xdoc; + + Data_Get_Struct(self, xmlDoc, xdoc); + return LONG2FIX(xmlXPathOrderDocElems(xdoc)); +} + +/* + * call-seq: + * document.validate_schema(schema) + * + * Validate this document against the specified XML::Schema. + * If the document is valid the method returns true. Otherwise an + * exception is raised with validation information. + */ +static VALUE rxml_document_validate_schema(VALUE self, VALUE schema) +{ + xmlSchemaValidCtxtPtr vptr; + xmlDocPtr xdoc; + xmlSchemaPtr xschema; + int is_invalid; + + Data_Get_Struct(self, xmlDoc, xdoc); + Data_Get_Struct(schema, xmlSchema, xschema); + + vptr = xmlSchemaNewValidCtxt(xschema); + + is_invalid = xmlSchemaValidateDoc(vptr, xdoc); + xmlSchemaFreeValidCtxt(vptr); + if (is_invalid) + { + rxml_raise(xmlGetLastError()); + return Qfalse; + } + else + { + return Qtrue; + } +} + +/* + * call-seq: + * document.validate_relaxng(relaxng) + * + * Validate this document against the specified XML::RelaxNG. + * If the document is valid the method returns true. Otherwise an + * exception is raised with validation information. + */ +static VALUE rxml_document_validate_relaxng(VALUE self, VALUE relaxng) +{ + xmlRelaxNGValidCtxtPtr vptr; + xmlDocPtr xdoc; + xmlRelaxNGPtr xrelaxng; + int is_invalid; + + Data_Get_Struct(self, xmlDoc, xdoc); + Data_Get_Struct(relaxng, xmlRelaxNG, xrelaxng); + + vptr = xmlRelaxNGNewValidCtxt(xrelaxng); + + is_invalid = xmlRelaxNGValidateDoc(vptr, xdoc); + xmlRelaxNGFreeValidCtxt(vptr); + if (is_invalid) + { + rxml_raise(xmlGetLastError()); + return Qfalse; + } + else + { + return Qtrue; + } +} + +/* + * call-seq: + * document.validate(dtd) -> (true|false) + * + * Validate this document against the specified XML::DTD. + * If the document is valid the method returns true. Otherwise an + * exception is raised with validation information. + */ +static VALUE rxml_document_validate_dtd(VALUE self, VALUE dtd) +{ + xmlValidCtxt ctxt; + xmlDocPtr xdoc; + xmlDtdPtr xdtd; + + Data_Get_Struct(self, xmlDoc, xdoc); + Data_Get_Struct(dtd, xmlDtd, xdtd); + + /* Setup context */ + memset(&ctxt, 0, sizeof(xmlValidCtxt)); + + if (xmlValidateDtd(&ctxt, xdoc, xdtd)) + { + return Qtrue; + } + else + { + rxml_raise(xmlGetLastError()); + return Qfalse; + } +} + +void rxml_init_document(void) +{ + cXMLDocument = rb_define_class_under(mXML, "Document", rb_cObject); + rb_define_alloc_func(cXMLDocument, rxml_document_alloc); + + /* Original C14N 1.0 spec */ + rb_define_const(cXMLDocument, "XML_C14N_1_0", INT2NUM(XML_C14N_1_0)); + /* Exclusive C14N 1.0 spec */ + rb_define_const(cXMLDocument, "XML_C14N_EXCLUSIVE_1_0", INT2NUM(XML_C14N_EXCLUSIVE_1_0)); + /* C14N 1.1 spec */ + rb_define_const(cXMLDocument, "XML_C14N_1_1", INT2NUM(XML_C14N_1_1)); + + rb_define_method(cXMLDocument, "initialize", rxml_document_initialize, -1); + rb_define_method(cXMLDocument, "canonicalize", rxml_document_canonicalize, -1); + rb_define_method(cXMLDocument, "child", rxml_document_child_get, 0); + rb_define_method(cXMLDocument, "child?", rxml_document_child_q, 0); + rb_define_method(cXMLDocument, "compression", rxml_document_compression_get, 0); + rb_define_method(cXMLDocument, "compression=", rxml_document_compression_set, 1); + rb_define_method(cXMLDocument, "compression?", rxml_document_compression_q, 0); + rb_define_method(cXMLDocument, "debug", rxml_document_debug, 0); + rb_define_method(cXMLDocument, "encoding", rxml_document_encoding_get, 0); + rb_define_method(cXMLDocument, "rb_encoding", rxml_document_rb_encoding_get, 0); + rb_define_method(cXMLDocument, "encoding=", rxml_document_encoding_set, 1); + rb_define_method(cXMLDocument, "import", rxml_document_import, 1); + rb_define_method(cXMLDocument, "last", rxml_document_last_get, 0); + rb_define_method(cXMLDocument, "last?", rxml_document_last_q, 0); + rb_define_method(cXMLDocument, "next", rxml_document_next_get, 0); + rb_define_method(cXMLDocument, "next?", rxml_document_next_q, 0); + rb_define_method(cXMLDocument, "node_type", rxml_document_node_type, 0); + rb_define_method(cXMLDocument, "order_elements!", rxml_document_order_elements, 0); + rb_define_method(cXMLDocument, "parent", rxml_document_parent_get, 0); + rb_define_method(cXMLDocument, "parent?", rxml_document_parent_q, 0); + rb_define_method(cXMLDocument, "prev", rxml_document_prev_get, 0); + rb_define_method(cXMLDocument, "prev?", rxml_document_prev_q, 0); + rb_define_method(cXMLDocument, "root", rxml_document_root_get, 0); + rb_define_method(cXMLDocument, "root=", rxml_document_root_set, 1); + rb_define_method(cXMLDocument, "save", rxml_document_save, -1); + rb_define_method(cXMLDocument, "standalone?", rxml_document_standalone_q, 0); + rb_define_method(cXMLDocument, "to_s", rxml_document_to_s, -1); + rb_define_method(cXMLDocument, "url", rxml_document_url_get, 0); + rb_define_method(cXMLDocument, "version", rxml_document_version_get, 0); + rb_define_method(cXMLDocument, "xhtml?", rxml_document_xhtml_q, 0); + rb_define_method(cXMLDocument, "xinclude", rxml_document_xinclude, 0); + rb_define_method(cXMLDocument, "validate", rxml_document_validate_dtd, 1); + rb_define_method(cXMLDocument, "validate_schema", rxml_document_validate_schema, 1); + rb_define_method(cXMLDocument, "validate_relaxng", rxml_document_validate_relaxng, 1); +} diff --git a/ext/libxml/ruby_xml_dtd.c b/ext/libxml/ruby_xml_dtd.c index 46dbe5fd..f66372a8 100644 --- a/ext/libxml/ruby_xml_dtd.c +++ b/ext/libxml/ruby_xml_dtd.c @@ -1,257 +1,257 @@ -#include "ruby_libxml.h" -#include "ruby_xml_dtd.h" - -/* - * Document-class: LibXML::XML::Dtd - * - * The XML::Dtd class is used to prepare DTD's for validation of xml - * documents. - * - * DTDs can be created from a string or a pair of public and system identifiers. - * Once a Dtd object is instantiated, an XML document can be validated by the - * XML::Document#validate method providing the XML::Dtd object as parameeter. - * The method will raise an exception if the document is - * not valid. - * - * Basic usage: - * - * # parse DTD - * dtd = XML::Dtd.new(< - * - * EOF - * - * # parse xml document to be validated - * instance = XML::Document.file('instance.xml') - * - * # validate - * instance.validate(dtd) - */ - -VALUE cXMLDtd; - -void rxml_dtd_free(xmlDtdPtr xdtd) -{ - if (xdtd->doc == NULL && xdtd->parent == NULL) - xmlFreeDtd(xdtd); -} - -void rxml_dtd_mark(xmlDtdPtr xdtd) -{ - if (xdtd && xdtd->doc) - { - VALUE doc = (VALUE)xdtd->doc->_private; - rb_gc_mark(doc); - } -} - -static VALUE rxml_dtd_alloc(VALUE klass) -{ - return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL); -} - -VALUE rxml_dtd_wrap(xmlDtdPtr xdtd) -{ - return Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd); -} - -/* - * call-seq: - * dtd.external_id -> "string" - * - * Obtain this dtd's external identifer (for a PUBLIC DTD). - */ -static VALUE rxml_dtd_external_id_get(VALUE self) -{ - xmlDtdPtr xdtd; - Data_Get_Struct(self, xmlDtd, xdtd); - - - if (xdtd->ExternalID == NULL) - return (Qnil); - else - return (rxml_new_cstr( xdtd->ExternalID, NULL)); -} - -/* - * call-seq: - * dtd.name -> "string" - * - * Obtain this dtd's name. - */ -static VALUE rxml_dtd_name_get(VALUE self) -{ - xmlDtdPtr xdtd; - Data_Get_Struct(self, xmlDtd, xdtd); - - - if (xdtd->name == NULL) - return (Qnil); - else - return (rxml_new_cstr( xdtd->name, NULL)); -} - - -/* - * call-seq: - * dtd.uri -> "string" - * - * Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD). - */ -static VALUE rxml_dtd_uri_get(VALUE self) -{ - xmlDtdPtr xdtd; - Data_Get_Struct(self, xmlDtd, xdtd); - - if (xdtd->SystemID == NULL) - return (Qnil); - else - return (rxml_new_cstr( xdtd->SystemID, NULL)); -} - -/* - * call-seq: - * node.type -> num - * - * Obtain this node's type identifier. - */ -static VALUE rxml_dtd_type(VALUE self) -{ - xmlDtdPtr xdtd; - Data_Get_Struct(self, xmlDtd, xdtd); - return (INT2NUM(xdtd->type)); -} - -/* - * call-seq: - * XML::Dtd.new(dtd_string) -> dtd - * XML::Dtd.new(external_id, system_id) -> dtd - * XML::Dtd.new(external_id, system_id, name, document, internal) -> dtd - * - * Create a new Dtd from the specified public and system identifiers: - * - * * The first usage creates a DTD from a string and requires 1 parameter. - * * The second usage loads and parses an external DTD and requires 2 parameters. - * * The third usage creates a new internal or external DTD and requires 2 parameters and 3 optional parameters. - * The DTD is then attached to the specified document if it is not nil. - * - * Parameters: - * - * dtd_string - A string that contains a complete DTD - * external_id - A string that specifies the DTD's external name. For example, "-//W3C//DTD XHTML 1.0 Transitional//EN" - * system_id - A string that specififies the DTD's system name. For example, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" - * name - A string that specifies the DTD's name. For example "xhtml1". - * document - A xml document. - * internal - Boolean value indicating whether this is an internal or external DTD. Optional. If not specified - * then external is assumed. - */ -static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self) -{ - xmlDtdPtr xdtd; - VALUE external, system; - - switch (argc) - { - case 3: - case 4: - case 5: - { - const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL; - xmlDocPtr xdoc = NULL; - - VALUE name, doc, internal; - rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal); - - Check_Type(external, T_STRING); - xpublic = (const xmlChar*) StringValuePtr(external); - - Check_Type(system, T_STRING); - xsystem = (const xmlChar*) StringValuePtr(system); - - if (name != Qnil) - { - Check_Type(name, T_STRING); - xname = (const xmlChar*)StringValuePtr(name); - } - - if (doc != Qnil) - { - if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse) - rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object"); - Data_Get_Struct(doc, xmlDoc, xdoc); - } - - if (internal == Qnil || internal == Qfalse) - xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem); - else - xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem); - - if (xdtd == NULL) - rxml_raise(xmlGetLastError()); - - /* The document will free the dtd so Ruby should not */ - RDATA(self)->dfree = NULL; - DATA_PTR(self) = xdtd; - - xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc); - } - break; - - case 2: - { - rb_scan_args(argc, argv, "20", &external, &system); - - Check_Type(external, T_STRING); - Check_Type(system, T_STRING); - - xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external), (xmlChar*) StringValuePtr(system)); - - if (xdtd == NULL) - rxml_raise(xmlGetLastError()); - - DATA_PTR(self) = xdtd; - - xmlSetTreeDoc((xmlNodePtr) xdtd, NULL); - break; - } - case 1: - { - VALUE dtd_string; - rb_scan_args(argc, argv, "10", &dtd_string); - Check_Type(dtd_string, T_STRING); - - /* Note that buffer is freed by xmlParserInputBufferPush*/ - xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; - xmlParserInputBufferPtr buffer = xmlAllocParserInputBuffer(enc); - xmlChar *new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string)); - xmlParserInputBufferPush(buffer, xmlStrlen(new_string), - (const char*) new_string); - - xdtd = xmlIOParseDTD(NULL, buffer, enc); - - if (xdtd == NULL) - rxml_raise(xmlGetLastError()); - - xmlFree(new_string); - - DATA_PTR(self) = xdtd; - break; - } - default: - rb_raise(rb_eArgError, "wrong number of arguments"); - } - - return self; -} - -void rxml_init_dtd(void) -{ - cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject); - rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc); - rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1); - rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0); - rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0); - rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0); - rb_define_method(cXMLDtd, "node_type", rxml_dtd_type, 0); - rb_define_alias(cXMLDtd, "system_id", "uri"); -} +#include "ruby_libxml.h" +#include "ruby_xml_dtd.h" + +/* + * Document-class: LibXML::XML::Dtd + * + * The XML::Dtd class is used to prepare DTD's for validation of xml + * documents. + * + * DTDs can be created from a string or a pair of public and system identifiers. + * Once a Dtd object is instantiated, an XML document can be validated by the + * XML::Document#validate method providing the XML::Dtd object as parameeter. + * The method will raise an exception if the document is + * not valid. + * + * Basic usage: + * + * # parse DTD + * dtd = XML::Dtd.new(< + * + * EOF + * + * # parse xml document to be validated + * instance = XML::Document.file('instance.xml') + * + * # validate + * instance.validate(dtd) + */ + +VALUE cXMLDtd; + +void rxml_dtd_free(xmlDtdPtr xdtd) +{ + if (xdtd->doc == NULL && xdtd->parent == NULL) + xmlFreeDtd(xdtd); +} + +void rxml_dtd_mark(xmlDtdPtr xdtd) +{ + if (xdtd && xdtd->doc) + { + VALUE doc = (VALUE)xdtd->doc->_private; + rb_gc_mark(doc); + } +} + +static VALUE rxml_dtd_alloc(VALUE klass) +{ + return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL); +} + +VALUE rxml_dtd_wrap(xmlDtdPtr xdtd) +{ + return Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd); +} + +/* + * call-seq: + * dtd.external_id -> "string" + * + * Obtain this dtd's external identifer (for a PUBLIC DTD). + */ +static VALUE rxml_dtd_external_id_get(VALUE self) +{ + xmlDtdPtr xdtd; + Data_Get_Struct(self, xmlDtd, xdtd); + + + if (xdtd->ExternalID == NULL) + return (Qnil); + else + return (rxml_new_cstr( xdtd->ExternalID, NULL)); +} + +/* + * call-seq: + * dtd.name -> "string" + * + * Obtain this dtd's name. + */ +static VALUE rxml_dtd_name_get(VALUE self) +{ + xmlDtdPtr xdtd; + Data_Get_Struct(self, xmlDtd, xdtd); + + + if (xdtd->name == NULL) + return (Qnil); + else + return (rxml_new_cstr( xdtd->name, NULL)); +} + + +/* + * call-seq: + * dtd.uri -> "string" + * + * Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD). + */ +static VALUE rxml_dtd_uri_get(VALUE self) +{ + xmlDtdPtr xdtd; + Data_Get_Struct(self, xmlDtd, xdtd); + + if (xdtd->SystemID == NULL) + return (Qnil); + else + return (rxml_new_cstr( xdtd->SystemID, NULL)); +} + +/* + * call-seq: + * node.type -> num + * + * Obtain this node's type identifier. + */ +static VALUE rxml_dtd_type(VALUE self) +{ + xmlDtdPtr xdtd; + Data_Get_Struct(self, xmlDtd, xdtd); + return (INT2NUM(xdtd->type)); +} + +/* + * call-seq: + * XML::Dtd.new(dtd_string) -> dtd + * XML::Dtd.new(external_id, system_id) -> dtd + * XML::Dtd.new(external_id, system_id, name, document, internal) -> dtd + * + * Create a new Dtd from the specified public and system identifiers: + * + * * The first usage creates a DTD from a string and requires 1 parameter. + * * The second usage loads and parses an external DTD and requires 2 parameters. + * * The third usage creates a new internal or external DTD and requires 2 parameters and 3 optional parameters. + * The DTD is then attached to the specified document if it is not nil. + * + * Parameters: + * + * dtd_string - A string that contains a complete DTD + * external_id - A string that specifies the DTD's external name. For example, "-//W3C//DTD XHTML 1.0 Transitional//EN" + * system_id - A string that specififies the DTD's system name. For example, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" + * name - A string that specifies the DTD's name. For example "xhtml1". + * document - A xml document. + * internal - Boolean value indicating whether this is an internal or external DTD. Optional. If not specified + * then external is assumed. + */ +static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self) +{ + xmlDtdPtr xdtd; + VALUE external, system; + + switch (argc) + { + case 3: + case 4: + case 5: + { + const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL; + xmlDocPtr xdoc = NULL; + + VALUE name, doc, internal; + rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal); + + Check_Type(external, T_STRING); + xpublic = (const xmlChar*) StringValuePtr(external); + + Check_Type(system, T_STRING); + xsystem = (const xmlChar*) StringValuePtr(system); + + if (name != Qnil) + { + Check_Type(name, T_STRING); + xname = (const xmlChar*)StringValuePtr(name); + } + + if (doc != Qnil) + { + if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse) + rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object"); + Data_Get_Struct(doc, xmlDoc, xdoc); + } + + if (internal == Qnil || internal == Qfalse) + xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem); + else + xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem); + + if (xdtd == NULL) + rxml_raise(xmlGetLastError()); + + /* The document will free the dtd so Ruby should not */ + RDATA(self)->dfree = NULL; + DATA_PTR(self) = xdtd; + + xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc); + } + break; + + case 2: + { + rb_scan_args(argc, argv, "20", &external, &system); + + Check_Type(external, T_STRING); + Check_Type(system, T_STRING); + + xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external), (xmlChar*) StringValuePtr(system)); + + if (xdtd == NULL) + rxml_raise(xmlGetLastError()); + + DATA_PTR(self) = xdtd; + + xmlSetTreeDoc((xmlNodePtr) xdtd, NULL); + break; + } + case 1: + { + VALUE dtd_string; + rb_scan_args(argc, argv, "10", &dtd_string); + Check_Type(dtd_string, T_STRING); + + /* Note that buffer is freed by xmlParserInputBufferPush*/ + xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; + xmlParserInputBufferPtr buffer = xmlAllocParserInputBuffer(enc); + xmlChar *new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string)); + xmlParserInputBufferPush(buffer, xmlStrlen(new_string), + (const char*) new_string); + + xdtd = xmlIOParseDTD(NULL, buffer, enc); + + if (xdtd == NULL) + rxml_raise(xmlGetLastError()); + + xmlFree(new_string); + + DATA_PTR(self) = xdtd; + break; + } + default: + rb_raise(rb_eArgError, "wrong number of arguments"); + } + + return self; +} + +void rxml_init_dtd(void) +{ + cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject); + rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc); + rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1); + rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0); + rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0); + rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0); + rb_define_method(cXMLDtd, "node_type", rxml_dtd_type, 0); + rb_define_alias(cXMLDtd, "system_id", "uri"); +} diff --git a/ext/libxml/ruby_xml_encoding.c b/ext/libxml/ruby_xml_encoding.c index 18dc7134..7a4704ae 100644 --- a/ext/libxml/ruby_xml_encoding.c +++ b/ext/libxml/ruby_xml_encoding.c @@ -1,250 +1,250 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#include -#include "ruby_libxml.h" - -/* - * Document-class: LibXML::XML::Encoding - * - * The encoding class exposes the encodings that libxml - * supports via constants. - * - * LibXML converts all data sources to UTF8 - * internally before processing them. By default, - * LibXML determines a data source's encoding - * using the algorithm described on its - * website[http://xmlsoft.org/encoding.html]. - * - * However, you may override a data source's encoding - * by using the encoding constants defined in this - * module. - * - * Example 1: - * - * io = File.open('some_file', 'rb') - * parser = XML::Parser.io(io, :encoding => XML::Encoding::ISO_8859_1) - * doc = parser.parse - * - * Example 2: - * - * parser = XML::HTMLParser.file("some_file", :encoding => XML::Encoding::ISO_8859_1) - * doc = parser.parse - * - * Example 3: - * - * document = XML::Document.new - * document.encoding = XML::Encoding::ISO_8859_1 - * doc << XML::Node.new - */ - -VALUE mXMLEncoding; - -/* - * call-seq: - * Encoding.from_s("UTF_8") -> XML::Encoding::UTF_8 - * - * Converts an encoding string to an encoding constant - * defined on the XML::Encoding class. - */ -static VALUE rxml_encoding_from_s(VALUE klass, VALUE encoding) -{ - xmlCharEncoding xencoding; - - if (encoding == Qnil) - return Qnil; - - xencoding = xmlParseCharEncoding(StringValuePtr(encoding)); - return INT2NUM(xencoding); -} - -/* - * call-seq: - * Encoding.to_s(XML::Encoding::UTF_8) -> "UTF-8" - * - * Converts an encoding constant defined on the XML::Encoding - * class to its text representation. - */ -static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding) -{ - const xmlChar* xencoding = (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding)); - - if (!xencoding) - return Qnil; - else - return rxml_new_cstr(xencoding, xencoding); -} - -/* - * Converts an xmlCharEncoding enum value into a Ruby Encoding object (available - * on Ruby 1.9.* and higher). - */ -rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding) -{ - const char* encodingName; - - switch (xmlEncoding) - { - case XML_CHAR_ENCODING_UTF8: - encodingName = "UTF-8"; - break; - case XML_CHAR_ENCODING_UTF16LE: - encodingName = "UTF-16LE"; - break; - case XML_CHAR_ENCODING_UTF16BE: - encodingName = "UTF-16BE"; - break; - case XML_CHAR_ENCODING_UCS4LE: - encodingName = "UCS-4LE"; - break; - case XML_CHAR_ENCODING_UCS4BE: - encodingName = "UCS-4BE"; - break; - case XML_CHAR_ENCODING_UCS2: - encodingName = "UCS-2"; - break; - case XML_CHAR_ENCODING_8859_1: - encodingName = "ISO8859-1"; - break; - case XML_CHAR_ENCODING_8859_2: - encodingName = "ISO8859-2"; - break; - case XML_CHAR_ENCODING_8859_3: - encodingName = "ISO8859-3"; - break; - case XML_CHAR_ENCODING_8859_4: - encodingName = "ISO8859-4"; - break; - case XML_CHAR_ENCODING_8859_5: - encodingName = "ISO8859-5"; - break; - case XML_CHAR_ENCODING_8859_6: - encodingName = "ISO8859-6"; - break; - case XML_CHAR_ENCODING_8859_7: - encodingName = "ISO8859-7"; - break; - case XML_CHAR_ENCODING_8859_8: - encodingName = "ISO8859-8"; - break; - case XML_CHAR_ENCODING_8859_9: - encodingName = "ISO8859-9"; - break; - case XML_CHAR_ENCODING_2022_JP: - encodingName = "ISO-2022-JP"; - break; - case XML_CHAR_ENCODING_SHIFT_JIS: - encodingName = "SHIFT-JIS"; - break; - case XML_CHAR_ENCODING_EUC_JP: - encodingName = "EUC-JP"; - break; - case XML_CHAR_ENCODING_ASCII: - encodingName = "US-ASCII"; - break; - default: - /* Covers XML_CHAR_ENCODING_ERROR, XML_CHAR_ENCODING_NONE, XML_CHAR_ENCODING_EBCDIC */ - encodingName = "ASCII-8BIT"; - break; - } - - return rb_enc_find(encodingName); -} - -/* - * call-seq: - * Input.encoding_to_rb_encoding(Input::ENCODING) -> Encoding - * - * Converts an encoding constant defined on the XML::Encoding - * class to a Ruby encoding object (available on Ruby 1.9.* and higher). - */ -VALUE rxml_encoding_to_rb_encoding(VALUE klass, VALUE encoding) -{ - xmlCharEncoding xmlEncoding = (xmlCharEncoding)NUM2INT(encoding); - rb_encoding* rbencoding = rxml_xml_encoding_to_rb_encoding(klass, xmlEncoding); - return rb_enc_from_encoding(rbencoding); -} - -rb_encoding* rxml_figure_encoding(const xmlChar* xencoding) -{ - rb_encoding* result; - if (xencoding) - { - xmlCharEncoding xmlEncoding = xmlParseCharEncoding((const char*)xencoding); - result = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlEncoding); - } - else - { - result = rb_utf8_encoding(); - } - return result; -} - -VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding) -{ - rb_encoding *rbencoding = rxml_figure_encoding(xencoding); - return rb_external_str_new_with_enc((const char*)xstr, (long)strlen((const char*)xstr), rbencoding); -} - -VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding) -{ - rb_encoding *rbencoding = rxml_figure_encoding(xencoding); - return rb_external_str_new_with_enc((const char*)xstr, length, rbencoding); -} - -void rxml_init_encoding(void) -{ - mXMLEncoding = rb_define_module_under(mXML, "Encoding"); - rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1); - rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1); - - rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 1); - - /* -1: No char encoding detected. */ - rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR)); - /* 0: No char encoding detected. */ - rb_define_const(mXMLEncoding, "NONE", INT2NUM(XML_CHAR_ENCODING_NONE)); - /* 1: UTF-8 */ - rb_define_const(mXMLEncoding, "UTF_8", INT2NUM(XML_CHAR_ENCODING_UTF8)); - /* 2: UTF-16 little endian. */ - rb_define_const(mXMLEncoding, "UTF_16LE", INT2NUM(XML_CHAR_ENCODING_UTF16LE)); - /* 3: UTF-16 big endian. */ - rb_define_const(mXMLEncoding, "UTF_16BE", INT2NUM(XML_CHAR_ENCODING_UTF16BE)); - /* 4: UCS-4 little endian. */ - rb_define_const(mXMLEncoding, "UCS_4LE", INT2NUM(XML_CHAR_ENCODING_UCS4LE)); - /* 5: UCS-4 big endian. */ - rb_define_const(mXMLEncoding, "UCS_4BE", INT2NUM(XML_CHAR_ENCODING_UCS4BE)); - /* 6: EBCDIC uh! */ - rb_define_const(mXMLEncoding, "EBCDIC", INT2NUM(XML_CHAR_ENCODING_EBCDIC)); - /* 7: UCS-4 unusual ordering. */ - rb_define_const(mXMLEncoding, "UCS_4_2143", INT2NUM(XML_CHAR_ENCODING_UCS4_2143)); - /* 8: UCS-4 unusual ordering. */ - rb_define_const(mXMLEncoding, "UCS_4_3412", INT2NUM(XML_CHAR_ENCODING_UCS4_3412)); - /* 9: UCS-2. */ - rb_define_const(mXMLEncoding, "UCS_2", INT2NUM(XML_CHAR_ENCODING_UCS2)); - /* 10: ISO-8859-1 ISO Latin 1. */ - rb_define_const(mXMLEncoding, "ISO_8859_1", INT2NUM(XML_CHAR_ENCODING_8859_1)); - /* 11: ISO-8859-2 ISO Latin 2. */ - rb_define_const(mXMLEncoding, "ISO_8859_2", INT2NUM(XML_CHAR_ENCODING_8859_2)); - /* 12: ISO-8859-3. */ - rb_define_const(mXMLEncoding, "ISO_8859_3", INT2NUM(XML_CHAR_ENCODING_8859_3)); - /* 13: ISO-8859-4. */ - rb_define_const(mXMLEncoding, "ISO_8859_4", INT2NUM(XML_CHAR_ENCODING_8859_4)); - /* 14: ISO-8859-5. */ - rb_define_const(mXMLEncoding, "ISO_8859_5", INT2NUM(XML_CHAR_ENCODING_8859_5)); - /* 15: ISO-8859-6. */ - rb_define_const(mXMLEncoding, "ISO_8859_6", INT2NUM(XML_CHAR_ENCODING_8859_6)); - /* 16: ISO-8859-7. */ - rb_define_const(mXMLEncoding, "ISO_8859_7", INT2NUM(XML_CHAR_ENCODING_8859_7)); - /* 17: ISO-8859-8. */ - rb_define_const(mXMLEncoding, "ISO_8859_8", INT2NUM(XML_CHAR_ENCODING_8859_8)); - /* 18: ISO-8859-9. */ - rb_define_const(mXMLEncoding, "ISO_8859_9", INT2NUM(XML_CHAR_ENCODING_8859_9)); - /* 19: ISO-2022-JP. */ - rb_define_const(mXMLEncoding, "ISO_2022_JP", INT2NUM(XML_CHAR_ENCODING_2022_JP)); - /* 20: Shift_JIS. */ - rb_define_const(mXMLEncoding, "SHIFT_JIS", INT2NUM(XML_CHAR_ENCODING_SHIFT_JIS)); - /* 21: EUC-JP. */ - rb_define_const(mXMLEncoding, "EUC_JP", INT2NUM(XML_CHAR_ENCODING_EUC_JP)); - /* 22: pure ASCII. */ - rb_define_const(mXMLEncoding, "ASCII", INT2NUM(XML_CHAR_ENCODING_ASCII)); -} +/* Please see the LICENSE file for copyright and distribution information */ + +#include +#include "ruby_libxml.h" + +/* + * Document-class: LibXML::XML::Encoding + * + * The encoding class exposes the encodings that libxml + * supports via constants. + * + * LibXML converts all data sources to UTF8 + * internally before processing them. By default, + * LibXML determines a data source's encoding + * using the algorithm described on its + * website[http://xmlsoft.org/encoding.html]. + * + * However, you may override a data source's encoding + * by using the encoding constants defined in this + * module. + * + * Example 1: + * + * io = File.open('some_file', 'rb') + * parser = XML::Parser.io(io, :encoding => XML::Encoding::ISO_8859_1) + * doc = parser.parse + * + * Example 2: + * + * parser = XML::HTMLParser.file("some_file", :encoding => XML::Encoding::ISO_8859_1) + * doc = parser.parse + * + * Example 3: + * + * document = XML::Document.new + * document.encoding = XML::Encoding::ISO_8859_1 + * doc << XML::Node.new + */ + +VALUE mXMLEncoding; + +/* + * call-seq: + * Encoding.from_s("UTF_8") -> XML::Encoding::UTF_8 + * + * Converts an encoding string to an encoding constant + * defined on the XML::Encoding class. + */ +static VALUE rxml_encoding_from_s(VALUE klass, VALUE encoding) +{ + xmlCharEncoding xencoding; + + if (encoding == Qnil) + return Qnil; + + xencoding = xmlParseCharEncoding(StringValuePtr(encoding)); + return INT2NUM(xencoding); +} + +/* + * call-seq: + * Encoding.to_s(XML::Encoding::UTF_8) -> "UTF-8" + * + * Converts an encoding constant defined on the XML::Encoding + * class to its text representation. + */ +static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding) +{ + const xmlChar* xencoding = (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding)); + + if (!xencoding) + return Qnil; + else + return rxml_new_cstr(xencoding, xencoding); +} + +/* + * Converts an xmlCharEncoding enum value into a Ruby Encoding object (available + * on Ruby 1.9.* and higher). + */ +rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding) +{ + const char* encodingName; + + switch (xmlEncoding) + { + case XML_CHAR_ENCODING_UTF8: + encodingName = "UTF-8"; + break; + case XML_CHAR_ENCODING_UTF16LE: + encodingName = "UTF-16LE"; + break; + case XML_CHAR_ENCODING_UTF16BE: + encodingName = "UTF-16BE"; + break; + case XML_CHAR_ENCODING_UCS4LE: + encodingName = "UCS-4LE"; + break; + case XML_CHAR_ENCODING_UCS4BE: + encodingName = "UCS-4BE"; + break; + case XML_CHAR_ENCODING_UCS2: + encodingName = "UCS-2"; + break; + case XML_CHAR_ENCODING_8859_1: + encodingName = "ISO8859-1"; + break; + case XML_CHAR_ENCODING_8859_2: + encodingName = "ISO8859-2"; + break; + case XML_CHAR_ENCODING_8859_3: + encodingName = "ISO8859-3"; + break; + case XML_CHAR_ENCODING_8859_4: + encodingName = "ISO8859-4"; + break; + case XML_CHAR_ENCODING_8859_5: + encodingName = "ISO8859-5"; + break; + case XML_CHAR_ENCODING_8859_6: + encodingName = "ISO8859-6"; + break; + case XML_CHAR_ENCODING_8859_7: + encodingName = "ISO8859-7"; + break; + case XML_CHAR_ENCODING_8859_8: + encodingName = "ISO8859-8"; + break; + case XML_CHAR_ENCODING_8859_9: + encodingName = "ISO8859-9"; + break; + case XML_CHAR_ENCODING_2022_JP: + encodingName = "ISO-2022-JP"; + break; + case XML_CHAR_ENCODING_SHIFT_JIS: + encodingName = "SHIFT-JIS"; + break; + case XML_CHAR_ENCODING_EUC_JP: + encodingName = "EUC-JP"; + break; + case XML_CHAR_ENCODING_ASCII: + encodingName = "US-ASCII"; + break; + default: + /* Covers XML_CHAR_ENCODING_ERROR, XML_CHAR_ENCODING_NONE, XML_CHAR_ENCODING_EBCDIC */ + encodingName = "ASCII-8BIT"; + break; + } + + return rb_enc_find(encodingName); +} + +/* + * call-seq: + * Input.encoding_to_rb_encoding(Input::ENCODING) -> Encoding + * + * Converts an encoding constant defined on the XML::Encoding + * class to a Ruby encoding object (available on Ruby 1.9.* and higher). + */ +VALUE rxml_encoding_to_rb_encoding(VALUE klass, VALUE encoding) +{ + xmlCharEncoding xmlEncoding = (xmlCharEncoding)NUM2INT(encoding); + rb_encoding* rbencoding = rxml_xml_encoding_to_rb_encoding(klass, xmlEncoding); + return rb_enc_from_encoding(rbencoding); +} + +rb_encoding* rxml_figure_encoding(const xmlChar* xencoding) +{ + rb_encoding* result; + if (xencoding) + { + xmlCharEncoding xmlEncoding = xmlParseCharEncoding((const char*)xencoding); + result = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlEncoding); + } + else + { + result = rb_utf8_encoding(); + } + return result; +} + +VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding) +{ + rb_encoding *rbencoding = rxml_figure_encoding(xencoding); + return rb_external_str_new_with_enc((const char*)xstr, (long)strlen((const char*)xstr), rbencoding); +} + +VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding) +{ + rb_encoding *rbencoding = rxml_figure_encoding(xencoding); + return rb_external_str_new_with_enc((const char*)xstr, length, rbencoding); +} + +void rxml_init_encoding(void) +{ + mXMLEncoding = rb_define_module_under(mXML, "Encoding"); + rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1); + rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1); + + rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 1); + + /* -1: No char encoding detected. */ + rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR)); + /* 0: No char encoding detected. */ + rb_define_const(mXMLEncoding, "NONE", INT2NUM(XML_CHAR_ENCODING_NONE)); + /* 1: UTF-8 */ + rb_define_const(mXMLEncoding, "UTF_8", INT2NUM(XML_CHAR_ENCODING_UTF8)); + /* 2: UTF-16 little endian. */ + rb_define_const(mXMLEncoding, "UTF_16LE", INT2NUM(XML_CHAR_ENCODING_UTF16LE)); + /* 3: UTF-16 big endian. */ + rb_define_const(mXMLEncoding, "UTF_16BE", INT2NUM(XML_CHAR_ENCODING_UTF16BE)); + /* 4: UCS-4 little endian. */ + rb_define_const(mXMLEncoding, "UCS_4LE", INT2NUM(XML_CHAR_ENCODING_UCS4LE)); + /* 5: UCS-4 big endian. */ + rb_define_const(mXMLEncoding, "UCS_4BE", INT2NUM(XML_CHAR_ENCODING_UCS4BE)); + /* 6: EBCDIC uh! */ + rb_define_const(mXMLEncoding, "EBCDIC", INT2NUM(XML_CHAR_ENCODING_EBCDIC)); + /* 7: UCS-4 unusual ordering. */ + rb_define_const(mXMLEncoding, "UCS_4_2143", INT2NUM(XML_CHAR_ENCODING_UCS4_2143)); + /* 8: UCS-4 unusual ordering. */ + rb_define_const(mXMLEncoding, "UCS_4_3412", INT2NUM(XML_CHAR_ENCODING_UCS4_3412)); + /* 9: UCS-2. */ + rb_define_const(mXMLEncoding, "UCS_2", INT2NUM(XML_CHAR_ENCODING_UCS2)); + /* 10: ISO-8859-1 ISO Latin 1. */ + rb_define_const(mXMLEncoding, "ISO_8859_1", INT2NUM(XML_CHAR_ENCODING_8859_1)); + /* 11: ISO-8859-2 ISO Latin 2. */ + rb_define_const(mXMLEncoding, "ISO_8859_2", INT2NUM(XML_CHAR_ENCODING_8859_2)); + /* 12: ISO-8859-3. */ + rb_define_const(mXMLEncoding, "ISO_8859_3", INT2NUM(XML_CHAR_ENCODING_8859_3)); + /* 13: ISO-8859-4. */ + rb_define_const(mXMLEncoding, "ISO_8859_4", INT2NUM(XML_CHAR_ENCODING_8859_4)); + /* 14: ISO-8859-5. */ + rb_define_const(mXMLEncoding, "ISO_8859_5", INT2NUM(XML_CHAR_ENCODING_8859_5)); + /* 15: ISO-8859-6. */ + rb_define_const(mXMLEncoding, "ISO_8859_6", INT2NUM(XML_CHAR_ENCODING_8859_6)); + /* 16: ISO-8859-7. */ + rb_define_const(mXMLEncoding, "ISO_8859_7", INT2NUM(XML_CHAR_ENCODING_8859_7)); + /* 17: ISO-8859-8. */ + rb_define_const(mXMLEncoding, "ISO_8859_8", INT2NUM(XML_CHAR_ENCODING_8859_8)); + /* 18: ISO-8859-9. */ + rb_define_const(mXMLEncoding, "ISO_8859_9", INT2NUM(XML_CHAR_ENCODING_8859_9)); + /* 19: ISO-2022-JP. */ + rb_define_const(mXMLEncoding, "ISO_2022_JP", INT2NUM(XML_CHAR_ENCODING_2022_JP)); + /* 20: Shift_JIS. */ + rb_define_const(mXMLEncoding, "SHIFT_JIS", INT2NUM(XML_CHAR_ENCODING_SHIFT_JIS)); + /* 21: EUC-JP. */ + rb_define_const(mXMLEncoding, "EUC_JP", INT2NUM(XML_CHAR_ENCODING_EUC_JP)); + /* 22: pure ASCII. */ + rb_define_const(mXMLEncoding, "ASCII", INT2NUM(XML_CHAR_ENCODING_ASCII)); +} diff --git a/ext/libxml/ruby_xml_error.c b/ext/libxml/ruby_xml_error.c index c6cd390a..7acee66b 100644 --- a/ext/libxml/ruby_xml_error.c +++ b/ext/libxml/ruby_xml_error.c @@ -1,1003 +1,1003 @@ -#include "ruby_libxml.h" - -#include - -VALUE eXMLError; -static ID CALL_METHOD; -static ID ERROR_HANDLER_ID; - -/* - * Document-class: LibXML::XML::Error - * - * The XML::Error class exposes libxml errors as - * standard Ruby exceptions. When appropriate, - * libxml-ruby will raise an exception - for example, - * when parsing a non-well formed xml document. - * - * By default, warnings, errors and fatal errors that - * libxml generates are printed to STDERR via the - * XML::Error::VERBOSE_HANDLER proc. - * - * To disable this output you can install the quiet handler: - * - * XML::Error.set_handler(&XML::Error::QUIET_HANDLER) - * - * Get the current handler: - * - * proc = XML::Error.get_handler - * - * Install your own handler: - * - * XML::Error.set_handler do |error| - * puts error.to_s - * end - * - * Or remove all handlers: - * - * XML::Error.reset_handler - */ - -/* - * call-seq: - * Error.get_error_handler - * - * Returns the proc that will be called when libxml generates - * warning, error or fatal error messages. - */ -static VALUE rxml_error_get_handler(VALUE self) -{ - VALUE block = rb_cvar_get(eXMLError, ERROR_HANDLER_ID); - return block; -} - -VALUE rxml_error_wrap(const xmlError *xerror) -{ - VALUE result = Qnil; - - if (xerror->message) - result = rb_exc_new2(eXMLError, xerror->message); - else - result = rb_class_new_instance(0, NULL, eXMLError); - - rb_iv_set(result, "@domain", INT2NUM(xerror->domain)); - rb_iv_set(result, "@code", INT2NUM(xerror->code)); - rb_iv_set(result, "@level", INT2NUM(xerror->level)); - - if (xerror->file) - rb_iv_set(result, "@file", rb_str_new2(xerror->file)); - - if (xerror->line) - rb_iv_set(result, "@line", INT2NUM(xerror->line)); - - if (xerror->str1) - rb_iv_set(result, "@str1", rb_str_new2(xerror->str1)); - - if (xerror->str2) - rb_iv_set(result, "@str2", rb_str_new2(xerror->str2)); - - if (xerror->str3) - rb_iv_set(result, "@str3", rb_str_new2(xerror->str3)); - - rb_iv_set(result, "@int1", INT2NUM(xerror->int1)); - rb_iv_set(result, "@int2", INT2NUM(xerror->int2)); - - if (xerror->node) - { - /* Returning the original node is too dangerous because its - parent document is never returned to Ruby. So return a - copy of the node, which does not belong to any document, - and can free itself when Ruby calls its free method. Note - we just copy the node, and don't bother with the overhead - of a recursive query. */ - xmlNodePtr xNode = xmlCopyNode((const xmlNodePtr)xerror->node, 2); - VALUE node = rxml_node_wrap(xNode); - rb_iv_set(result, "@node", node); - } - return result; -} - -/* Hook that receives xml error message */ -#if LIBXML_VERSION >= 21200 -static void structuredErrorFunc(void *userData, const xmlError *xerror) -#else -static void structuredErrorFunc(void *userData, xmlErrorPtr xerror) -#endif -{ - VALUE error = rxml_error_wrap(xerror); - - /* Wrap error up as Ruby object and send it off to ruby */ - VALUE block = rxml_error_get_handler(error); - - /* Now call global handler */ - if (block != Qnil) - { - rb_funcall(block, CALL_METHOD, 1, error); - } -} - -static void rxml_set_handler(VALUE self, VALUE block) -{ -#ifdef RB_CVAR_SET_4ARGS - rb_cvar_set(self, ERROR_HANDLER_ID, block, 0); -#else - rb_cvar_set(self, ERROR_HANDLER_ID, block); -#endif - - /* Intercept libxml error handlers */ - xmlSetStructuredErrorFunc(NULL, structuredErrorFunc); -} - -/* - * call-seq: - * Error.set_error_handler {|error| ... } - * - * Registers a block that will be called with an instance of - * XML::Error when libxml generates warning, error or fatal - * error messages. - */ -static VALUE rxml_error_set_handler(VALUE self) -{ - VALUE block; - - if (rb_block_given_p() == Qfalse) - rb_raise(rb_eRuntimeError, "No block given"); - - block = rb_block_proc(); - - /* Embed the block within the Error class to avoid it to be collected. - Previous handler will be overwritten if it exists. */ - rxml_set_handler(self, block); - - return self; -} - -/* - * call-seq: - * Error.reset_error_handler - * - * Removes the current error handler. */ -static VALUE rxml_error_reset_handler(VALUE self) -{ - rxml_set_handler(self, Qnil); - return self; -} - -void rxml_raise(const xmlError *xerror) -{ - if (xerror) - { - /* Wrap error up as Ruby object and send it off to ruby */ - VALUE error = rxml_error_wrap(xerror); - rb_exc_raise(error); - } -} - -void rxml_init_error(void) -{ - CALL_METHOD = rb_intern("call"); - ERROR_HANDLER_ID = rb_intern("@@__error_handler_callback__"); - - /* Error class */ - eXMLError = rb_define_class_under(mXML, "Error", rb_eStandardError); - rb_define_singleton_method(eXMLError, "get_handler", rxml_error_get_handler, 0); - rb_define_singleton_method(eXMLError, "set_handler", rxml_error_set_handler, 0); - rb_define_singleton_method(eXMLError, "reset_handler", rxml_error_reset_handler, 0); - - /* Ruby callback to receive errors - set it to nil by default. */ - rxml_set_handler(eXMLError, Qnil); - - /* Error attributes */ - rb_define_attr(eXMLError, "level", 1, 0); - rb_define_attr(eXMLError, "domain", 1, 0); - rb_define_attr(eXMLError, "code", 1, 0); - rb_define_attr(eXMLError, "file", 1, 0); - rb_define_attr(eXMLError, "line", 1, 0); - rb_define_attr(eXMLError, "str1", 1, 0); - rb_define_attr(eXMLError, "str2", 1, 0); - rb_define_attr(eXMLError, "str3", 1, 0); - rb_define_attr(eXMLError, "int1", 1, 0); - rb_define_attr(eXMLError, "int2", 1, 0); - rb_define_attr(eXMLError, "ctxt", 1, 0); - rb_define_attr(eXMLError, "node", 1, 0); - - /* xml error levels */ - rb_define_const(eXMLError, "NONE", INT2NUM(XML_ERR_NONE)); - rb_define_const(eXMLError, "WARNING", INT2NUM(XML_ERR_WARNING)); - rb_define_const(eXMLError, "ERROR", INT2NUM(XML_ERR_ERROR)); - rb_define_const(eXMLError, "FATAL", INT2NUM(XML_ERR_FATAL)); - - /* xml error domains */ - rb_define_const(eXMLError, "NO_ERROR", INT2NUM(XML_FROM_NONE)); - rb_define_const(eXMLError, "PARSER", INT2NUM(XML_FROM_PARSER)); - rb_define_const(eXMLError, "TREE", INT2NUM(XML_FROM_TREE)); - rb_define_const(eXMLError, "NAMESPACE", INT2NUM(XML_FROM_NAMESPACE)); - rb_define_const(eXMLError, "DTD", INT2NUM(XML_FROM_DTD)); - rb_define_const(eXMLError, "HTML", INT2NUM(XML_FROM_HTML)); - rb_define_const(eXMLError, "MEMORY", INT2NUM(XML_FROM_MEMORY)); - rb_define_const(eXMLError, "OUTPUT", INT2NUM(XML_FROM_OUTPUT)); - rb_define_const(eXMLError, "IO", INT2NUM(XML_FROM_IO)); - rb_define_const(eXMLError, "FTP", INT2NUM(XML_FROM_FTP)); - rb_define_const(eXMLError, "HTTP", INT2NUM(XML_FROM_HTTP)); - rb_define_const(eXMLError, "XINCLUDE", INT2NUM(XML_FROM_XINCLUDE)); - rb_define_const(eXMLError, "XPATH", INT2NUM(XML_FROM_XPATH)); - rb_define_const(eXMLError, "XPOINTER", INT2NUM(XML_FROM_XPOINTER)); - rb_define_const(eXMLError, "REGEXP", INT2NUM(XML_FROM_REGEXP)); - rb_define_const(eXMLError, "DATATYPE", INT2NUM(XML_FROM_DATATYPE)); - rb_define_const(eXMLError, "SCHEMASP", INT2NUM(XML_FROM_SCHEMASP)); - rb_define_const(eXMLError, "SCHEMASV", INT2NUM(XML_FROM_SCHEMASV)); - rb_define_const(eXMLError, "RELAXNGP", INT2NUM(XML_FROM_RELAXNGP)); - rb_define_const(eXMLError, "RELAXNGV", INT2NUM(XML_FROM_RELAXNGV)); - rb_define_const(eXMLError, "CATALOG", INT2NUM(XML_FROM_CATALOG)); - rb_define_const(eXMLError, "C14N", INT2NUM(XML_FROM_C14N)); - rb_define_const(eXMLError, "XSLT", INT2NUM(XML_FROM_XSLT)); - rb_define_const(eXMLError, "VALID", INT2NUM(XML_FROM_VALID)); - rb_define_const(eXMLError, "CHECK", INT2NUM(XML_FROM_CHECK)); - rb_define_const(eXMLError, "WRITER", INT2NUM(XML_FROM_WRITER)); -#if LIBXML_VERSION >= 20621 - rb_define_const(eXMLError, "MODULE", INT2NUM(XML_FROM_MODULE)); -#endif -#if LIBXML_VERSION >= 20632 - rb_define_const(eXMLError, "I18N", INT2NUM(XML_FROM_I18N)); - rb_define_const(eXMLError, "SCHEMATRONV", INT2NUM(XML_FROM_SCHEMATRONV)); -#endif - - /* errors */ - rb_define_const(eXMLError, "OK", INT2NUM(XML_ERR_OK)); - rb_define_const(eXMLError, "INTERNAL_ERROR", INT2NUM(XML_ERR_INTERNAL_ERROR)); - rb_define_const(eXMLError, "NO_MEMORY", INT2NUM(XML_ERR_NO_MEMORY)); - rb_define_const(eXMLError, "DOCUMENT_START", INT2NUM(XML_ERR_DOCUMENT_START)); - rb_define_const(eXMLError, "DOCUMENT_EMPTY", INT2NUM(XML_ERR_DOCUMENT_EMPTY)); - rb_define_const(eXMLError, "DOCUMENT_END", INT2NUM(XML_ERR_DOCUMENT_END)); - rb_define_const(eXMLError, "INVALID_HEX_CHARREF", INT2NUM(XML_ERR_INVALID_HEX_CHARREF)); - rb_define_const(eXMLError, "INVALID_DEC_CHARREF", INT2NUM(XML_ERR_INVALID_DEC_CHARREF)); - rb_define_const(eXMLError, "INVALID_CHARREF", INT2NUM(XML_ERR_INVALID_CHARREF)); - rb_define_const(eXMLError, "INVALID_CHAR", INT2NUM(XML_ERR_INVALID_CHAR)); - rb_define_const(eXMLError, "CHARREF_AT_EOF", INT2NUM(XML_ERR_CHARREF_AT_EOF)); - rb_define_const(eXMLError, "CHARREF_IN_PROLOG", INT2NUM(XML_ERR_CHARREF_IN_PROLOG)); - rb_define_const(eXMLError, "CHARREF_IN_EPILOG", INT2NUM(XML_ERR_CHARREF_IN_EPILOG)); - rb_define_const(eXMLError, "CHARREF_IN_DTD", INT2NUM(XML_ERR_CHARREF_IN_DTD)); - rb_define_const(eXMLError, "ENTITYREF_AT_EOF", INT2NUM(XML_ERR_ENTITYREF_AT_EOF)); - rb_define_const(eXMLError, "ENTITYREF_IN_PROLOG", INT2NUM(XML_ERR_ENTITYREF_IN_PROLOG)); - rb_define_const(eXMLError, "ENTITYREF_IN_EPILOG", INT2NUM(XML_ERR_ENTITYREF_IN_EPILOG)); - rb_define_const(eXMLError, "ENTITYREF_IN_DTD", INT2NUM(XML_ERR_ENTITYREF_IN_DTD)); - rb_define_const(eXMLError, "PEREF_AT_EOF", INT2NUM(XML_ERR_PEREF_AT_EOF)); - rb_define_const(eXMLError, "PEREF_IN_PROLOG", INT2NUM(XML_ERR_PEREF_IN_PROLOG)); - rb_define_const(eXMLError, "PEREF_IN_EPILOG",INT2NUM(XML_ERR_PEREF_IN_EPILOG)); - rb_define_const(eXMLError, "PEREF_IN_INT_SUBSET", INT2NUM(XML_ERR_PEREF_IN_INT_SUBSET)); - rb_define_const(eXMLError, "ENTITYREF_NO_NAME", INT2NUM(XML_ERR_ENTITYREF_NO_NAME)); - rb_define_const(eXMLError, "ENTITYREF_SEMICOL_MISSING", INT2NUM(XML_ERR_ENTITYREF_SEMICOL_MISSING)); - rb_define_const(eXMLError, "PEREF_NO_NAME", INT2NUM(XML_ERR_PEREF_NO_NAME)); - rb_define_const(eXMLError, "PEREF_SEMICOL_MISSING", INT2NUM(XML_ERR_PEREF_SEMICOL_MISSING)); - rb_define_const(eXMLError, "UNDECLARED_ENTITY", INT2NUM(XML_ERR_UNDECLARED_ENTITY)); - rb_define_const(eXMLError, "XML_WAR_UNDECLARED_ENTITY", INT2NUM(XML_WAR_UNDECLARED_ENTITY)); - rb_define_const(eXMLError, "UNPARSED_ENTITY", INT2NUM(XML_ERR_UNPARSED_ENTITY)); - rb_define_const(eXMLError, "ENTITY_IS_EXTERNAL", INT2NUM(XML_ERR_ENTITY_IS_EXTERNAL)); - rb_define_const(eXMLError, "ENTITY_IS_PARAMETER", INT2NUM(XML_ERR_ENTITY_IS_PARAMETER)); - rb_define_const(eXMLError, "UNKNOWN_ENCODING", INT2NUM(XML_ERR_UNKNOWN_ENCODING)); - rb_define_const(eXMLError, "UNSUPPORTED_ENCODING", INT2NUM(XML_ERR_UNSUPPORTED_ENCODING)); - rb_define_const(eXMLError, "STRING_NOT_STARTED", INT2NUM(XML_ERR_STRING_NOT_STARTED)); - rb_define_const(eXMLError, "STRING_NOT_CLOSED", INT2NUM(XML_ERR_STRING_NOT_CLOSED)); - rb_define_const(eXMLError, "NS_DECL_ERROR", INT2NUM(XML_ERR_NS_DECL_ERROR)); - rb_define_const(eXMLError, "ENTITY_NOT_STARTED", INT2NUM(XML_ERR_ENTITY_NOT_STARTED)); - rb_define_const(eXMLError, "ENTITY_NOT_FINISHED", INT2NUM(XML_ERR_ENTITY_NOT_FINISHED)); - rb_define_const(eXMLError, "LT_IN_ATTRIBUTE", INT2NUM(XML_ERR_LT_IN_ATTRIBUTE)); - rb_define_const(eXMLError, "ATTRIBUTE_NOT_STARTED", INT2NUM(XML_ERR_ATTRIBUTE_NOT_STARTED)); - rb_define_const(eXMLError, "ATTRIBUTE_NOT_FINISHED", INT2NUM(XML_ERR_ATTRIBUTE_NOT_FINISHED)); - rb_define_const(eXMLError, "ATTRIBUTE_WITHOUT_VALUE", INT2NUM(XML_ERR_ATTRIBUTE_WITHOUT_VALUE)); - rb_define_const(eXMLError, "ATTRIBUTE_REDEFINED", INT2NUM(XML_ERR_ATTRIBUTE_REDEFINED)); - rb_define_const(eXMLError, "LITERAL_NOT_STARTED", INT2NUM(XML_ERR_LITERAL_NOT_STARTED)); - rb_define_const(eXMLError, "LITERAL_NOT_FINISHED", INT2NUM(XML_ERR_LITERAL_NOT_FINISHED)); - rb_define_const(eXMLError, "COMMENT_NOT_FINISHED", INT2NUM(XML_ERR_COMMENT_NOT_FINISHED)); - rb_define_const(eXMLError, "PI_NOT_STARTED", INT2NUM(XML_ERR_PI_NOT_STARTED)); - rb_define_const(eXMLError, "PI_NOT_FINISHED", INT2NUM(XML_ERR_PI_NOT_FINISHED)); - rb_define_const(eXMLError, "NOTATION_NOT_STARTED", INT2NUM(XML_ERR_NOTATION_NOT_STARTED)); - rb_define_const(eXMLError, "NOTATION_NOT_FINISHED", INT2NUM(XML_ERR_NOTATION_NOT_FINISHED)); - rb_define_const(eXMLError, "ATTLIST_NOT_STARTED", INT2NUM(XML_ERR_ATTLIST_NOT_STARTED)); - rb_define_const(eXMLError, "ATTLIST_NOT_FINISHED", INT2NUM(XML_ERR_ATTLIST_NOT_FINISHED)); - rb_define_const(eXMLError, "MIXED_NOT_STARTED", INT2NUM(XML_ERR_MIXED_NOT_STARTED)); - rb_define_const(eXMLError, "MIXED_NOT_FINISHED", INT2NUM(XML_ERR_MIXED_NOT_FINISHED)); - rb_define_const(eXMLError, "ELEMCONTENT_NOT_STARTED", INT2NUM(XML_ERR_ELEMCONTENT_NOT_STARTED)); - rb_define_const(eXMLError, "ELEMCONTENT_NOT_FINISHED", INT2NUM(XML_ERR_ELEMCONTENT_NOT_FINISHED)); - rb_define_const(eXMLError, "XMLDECL_NOT_STARTED", INT2NUM(XML_ERR_XMLDECL_NOT_STARTED)); - rb_define_const(eXMLError, "XMLDECL_NOT_FINISHED", INT2NUM(XML_ERR_XMLDECL_NOT_FINISHED)); - rb_define_const(eXMLError, "CONDSEC_NOT_STARTED", INT2NUM(XML_ERR_CONDSEC_NOT_STARTED)); - rb_define_const(eXMLError, "CONDSEC_NOT_FINISHED", INT2NUM(XML_ERR_CONDSEC_NOT_FINISHED)); - rb_define_const(eXMLError, "EXT_SUBSET_NOT_FINISHED", INT2NUM(XML_ERR_EXT_SUBSET_NOT_FINISHED)); - rb_define_const(eXMLError, "DOCTYPE_NOT_FINISHED", INT2NUM(XML_ERR_DOCTYPE_NOT_FINISHED)); - rb_define_const(eXMLError, "MISPLACED_CDATA_END", INT2NUM(XML_ERR_MISPLACED_CDATA_END)); - rb_define_const(eXMLError, "CDATA_NOT_FINISHED", INT2NUM(XML_ERR_CDATA_NOT_FINISHED)); - rb_define_const(eXMLError, "RESERVED_XML_NAME", INT2NUM(XML_ERR_RESERVED_XML_NAME)); - rb_define_const(eXMLError, "SPACE_REQUIRED", INT2NUM(XML_ERR_SPACE_REQUIRED)); - rb_define_const(eXMLError, "SEPARATOR_REQUIRED", INT2NUM(XML_ERR_SEPARATOR_REQUIRED)); - rb_define_const(eXMLError, "NMTOKEN_REQUIRED", INT2NUM(XML_ERR_NMTOKEN_REQUIRED)); - rb_define_const(eXMLError, "NAME_REQUIRED", INT2NUM(XML_ERR_NAME_REQUIRED)); - rb_define_const(eXMLError, "PCDATA_REQUIRED", INT2NUM(XML_ERR_PCDATA_REQUIRED)); - rb_define_const(eXMLError, "URI_REQUIRED", INT2NUM(XML_ERR_URI_REQUIRED)); - rb_define_const(eXMLError, "PUBID_REQUIRED", INT2NUM(XML_ERR_PUBID_REQUIRED)); - rb_define_const(eXMLError, "LT_REQUIRED", INT2NUM(XML_ERR_LT_REQUIRED)); - rb_define_const(eXMLError, "GT_REQUIRED", INT2NUM(XML_ERR_GT_REQUIRED)); - rb_define_const(eXMLError, "LTSLASH_REQUIRED", INT2NUM(XML_ERR_LTSLASH_REQUIRED)); - rb_define_const(eXMLError, "EQUAL_REQUIRED", INT2NUM(XML_ERR_EQUAL_REQUIRED)); - rb_define_const(eXMLError, "TAG_NAME_MISMATCH", INT2NUM(XML_ERR_TAG_NAME_MISMATCH)); - rb_define_const(eXMLError, "TAG_NOT_FINISHED", INT2NUM(XML_ERR_TAG_NOT_FINISHED)); - rb_define_const(eXMLError, "STANDALONE_VALUE", INT2NUM(XML_ERR_STANDALONE_VALUE)); - rb_define_const(eXMLError, "ENCODING_NAME", INT2NUM(XML_ERR_ENCODING_NAME)); - rb_define_const(eXMLError, "HYPHEN_IN_COMMENT", INT2NUM(XML_ERR_HYPHEN_IN_COMMENT)); - rb_define_const(eXMLError, "INVALID_ENCODING", INT2NUM(XML_ERR_INVALID_ENCODING)); - rb_define_const(eXMLError, "EXT_ENTITY_STANDALONE", INT2NUM(XML_ERR_EXT_ENTITY_STANDALONE)); - rb_define_const(eXMLError, "CONDSEC_INVALID", INT2NUM(XML_ERR_CONDSEC_INVALID)); - rb_define_const(eXMLError, "VALUE_REQUIRED", INT2NUM(XML_ERR_VALUE_REQUIRED)); - rb_define_const(eXMLError, "NOT_WELL_BALANCED", INT2NUM(XML_ERR_NOT_WELL_BALANCED)); - rb_define_const(eXMLError, "EXTRA_CONTENT", INT2NUM(XML_ERR_EXTRA_CONTENT)); - rb_define_const(eXMLError, "ENTITY_CHAR_ERROR", INT2NUM(XML_ERR_ENTITY_CHAR_ERROR)); - rb_define_const(eXMLError, "ENTITY_PE_INTERNAL", INT2NUM(XML_ERR_ENTITY_PE_INTERNAL)); - rb_define_const(eXMLError, "ENTITY_LOOP", INT2NUM(XML_ERR_ENTITY_LOOP)); - rb_define_const(eXMLError, "ENTITY_BOUNDARY", INT2NUM(XML_ERR_ENTITY_BOUNDARY)); - rb_define_const(eXMLError, "INVALID_URI", INT2NUM(XML_ERR_INVALID_URI)); - rb_define_const(eXMLError, "URI_FRAGMENT", INT2NUM(XML_ERR_URI_FRAGMENT)); - rb_define_const(eXMLError, "XML_WAR_CATALOG_PI", INT2NUM(XML_WAR_CATALOG_PI)); - rb_define_const(eXMLError, "NO_DTD", INT2NUM(XML_ERR_NO_DTD)); - rb_define_const(eXMLError, "CONDSEC_INVALID_KEYWORD", INT2NUM(XML_ERR_CONDSEC_INVALID_KEYWORD)); - rb_define_const(eXMLError, "VERSION_MISSING", INT2NUM(XML_ERR_VERSION_MISSING)); - rb_define_const(eXMLError, "XML_WAR_UNKNOWN_VERSION", INT2NUM(XML_WAR_UNKNOWN_VERSION)); - rb_define_const(eXMLError, "XML_WAR_LANG_VALUE", INT2NUM(XML_WAR_LANG_VALUE)); - rb_define_const(eXMLError, "XML_WAR_NS_URI", INT2NUM(XML_WAR_NS_URI)); - rb_define_const(eXMLError, "XML_WAR_NS_URI_RELATIVE", INT2NUM(XML_WAR_NS_URI_RELATIVE)); - rb_define_const(eXMLError, "MISSING_ENCODING", INT2NUM(XML_ERR_MISSING_ENCODING)); -#if LIBXML_VERSION >= 20620 - rb_define_const(eXMLError, "XML_WAR_SPACE_VALUE", INT2NUM(XML_WAR_SPACE_VALUE)); - rb_define_const(eXMLError, "NOT_STANDALONE", INT2NUM(XML_ERR_NOT_STANDALONE)); - rb_define_const(eXMLError, "ENTITY_PROCESSING", INT2NUM(XML_ERR_ENTITY_PROCESSING)); - rb_define_const(eXMLError, "NOTATION_PROCESSING", INT2NUM(XML_ERR_NOTATION_PROCESSING)); - rb_define_const(eXMLError, "WAR_NS_COLUMN", INT2NUM(XML_WAR_NS_COLUMN)); - rb_define_const(eXMLError, "WAR_ENTITY_REDEFINED", INT2NUM(XML_WAR_ENTITY_REDEFINED)); -#endif - rb_define_const(eXMLError, "NS_ERR_XML_NAMESPACE", INT2NUM(XML_NS_ERR_XML_NAMESPACE)); - rb_define_const(eXMLError, "NS_ERR_UNDEFINED_NAMESPACE", INT2NUM(XML_NS_ERR_UNDEFINED_NAMESPACE)); - rb_define_const(eXMLError, "NS_ERR_QNAME", INT2NUM(XML_NS_ERR_QNAME)); - rb_define_const(eXMLError, "NS_ERR_ATTRIBUTE_REDEFINED", INT2NUM(XML_NS_ERR_ATTRIBUTE_REDEFINED)); -#if LIBXML_VERSION >= 20620 - rb_define_const(eXMLError, "NS_ERR_EMPTY", INT2NUM(XML_NS_ERR_EMPTY)); -#endif -#if LIBXML_VERSION >= 20700 - rb_define_const(eXMLError, "NS_ERR_COLON", INT2NUM(XML_NS_ERR_COLON)); -#endif - rb_define_const(eXMLError, "DTD_ATTRIBUTE_DEFAULT", INT2NUM(XML_DTD_ATTRIBUTE_DEFAULT)); - rb_define_const(eXMLError, "DTD_ATTRIBUTE_REDEFINED", INT2NUM(XML_DTD_ATTRIBUTE_REDEFINED)); - rb_define_const(eXMLError, "DTD_ATTRIBUTE_VALUE", INT2NUM(XML_DTD_ATTRIBUTE_VALUE)); - rb_define_const(eXMLError, "DTD_CONTENT_ERROR", INT2NUM(XML_DTD_CONTENT_ERROR)); - rb_define_const(eXMLError, "DTD_CONTENT_MODEL", INT2NUM(XML_DTD_CONTENT_MODEL)); - rb_define_const(eXMLError, "DTD_CONTENT_NOT_DETERMINIST", INT2NUM(XML_DTD_CONTENT_NOT_DETERMINIST)); - rb_define_const(eXMLError, "DTD_DIFFERENT_PREFIX", INT2NUM(XML_DTD_DIFFERENT_PREFIX)); - rb_define_const(eXMLError, "DTD_ELEM_DEFAULT_NAMESPACE", INT2NUM(XML_DTD_ELEM_DEFAULT_NAMESPACE)); - rb_define_const(eXMLError, "DTD_ELEM_NAMESPACE", INT2NUM(XML_DTD_ELEM_NAMESPACE)); - rb_define_const(eXMLError, "DTD_ELEM_REDEFINED", INT2NUM(XML_DTD_ELEM_REDEFINED)); - rb_define_const(eXMLError, "DTD_EMPTY_NOTATION", INT2NUM(XML_DTD_EMPTY_NOTATION)); - rb_define_const(eXMLError, "DTD_ENTITY_TYPE", INT2NUM(XML_DTD_ENTITY_TYPE)); - rb_define_const(eXMLError, "DTD_ID_FIXED", INT2NUM(XML_DTD_ID_FIXED)); - rb_define_const(eXMLError, "DTD_ID_REDEFINED", INT2NUM(XML_DTD_ID_REDEFINED)); - rb_define_const(eXMLError, "DTD_ID_SUBSET", INT2NUM(XML_DTD_ID_SUBSET)); - rb_define_const(eXMLError, "DTD_INVALID_CHILD", INT2NUM(XML_DTD_INVALID_CHILD)); - rb_define_const(eXMLError, "DTD_INVALID_DEFAULT", INT2NUM(XML_DTD_INVALID_DEFAULT)); - rb_define_const(eXMLError, "DTD_LOAD_ERROR", INT2NUM(XML_DTD_LOAD_ERROR)); - rb_define_const(eXMLError, "DTD_MISSING_ATTRIBUTE", INT2NUM(XML_DTD_MISSING_ATTRIBUTE)); - rb_define_const(eXMLError, "DTD_MIXED_CORRUPT", INT2NUM(XML_DTD_MIXED_CORRUPT)); - rb_define_const(eXMLError, "DTD_MULTIPLE_ID", INT2NUM(XML_DTD_MULTIPLE_ID)); - rb_define_const(eXMLError, "DTD_NO_DOC", INT2NUM(XML_DTD_NO_DOC)); - rb_define_const(eXMLError, "DTD_NO_DTD", INT2NUM(XML_DTD_NO_DTD)); - rb_define_const(eXMLError, "DTD_NO_ELEM_NAME", INT2NUM(XML_DTD_NO_ELEM_NAME)); - rb_define_const(eXMLError, "DTD_NO_PREFIX", INT2NUM(XML_DTD_NO_PREFIX)); - rb_define_const(eXMLError, "DTD_NO_ROOT", INT2NUM(XML_DTD_NO_ROOT)); - rb_define_const(eXMLError, "DTD_NOTATION_REDEFINED", INT2NUM(XML_DTD_NOTATION_REDEFINED)); - rb_define_const(eXMLError, "DTD_NOTATION_VALUE", INT2NUM(XML_DTD_NOTATION_VALUE)); - rb_define_const(eXMLError, "DTD_NOT_EMPTY", INT2NUM(XML_DTD_NOT_EMPTY)); - rb_define_const(eXMLError, "DTD_NOT_PCDATA", INT2NUM(XML_DTD_NOT_PCDATA)); - rb_define_const(eXMLError, "DTD_NOT_STANDALONE", INT2NUM(XML_DTD_NOT_STANDALONE)); - rb_define_const(eXMLError, "DTD_ROOT_NAME", INT2NUM(XML_DTD_ROOT_NAME)); - rb_define_const(eXMLError, "DTD_STANDALONE_WHITE_SPACE", INT2NUM(XML_DTD_STANDALONE_WHITE_SPACE)); - rb_define_const(eXMLError, "DTD_UNKNOWN_ATTRIBUTE", INT2NUM(XML_DTD_UNKNOWN_ATTRIBUTE)); - rb_define_const(eXMLError, "DTD_UNKNOWN_ELEM", INT2NUM(XML_DTD_UNKNOWN_ELEM)); - rb_define_const(eXMLError, "DTD_UNKNOWN_ENTITY", INT2NUM(XML_DTD_UNKNOWN_ENTITY)); - rb_define_const(eXMLError, "DTD_UNKNOWN_ID", INT2NUM(XML_DTD_UNKNOWN_ID)); - rb_define_const(eXMLError, "DTD_UNKNOWN_NOTATION", INT2NUM(XML_DTD_UNKNOWN_NOTATION)); - rb_define_const(eXMLError, "DTD_STANDALONE_DEFAULTED", INT2NUM(XML_DTD_STANDALONE_DEFAULTED)); - rb_define_const(eXMLError, "DTD_XMLID_VALUE", INT2NUM(XML_DTD_XMLID_VALUE)); - rb_define_const(eXMLError, "DTD_XMLID_TYPE", INT2NUM(XML_DTD_XMLID_TYPE)); - rb_define_const(eXMLError, "HTML_STRUCURE_ERROR", INT2NUM(XML_HTML_STRUCURE_ERROR)); - rb_define_const(eXMLError, "HTML_UNKNOWN_TAG", INT2NUM(XML_HTML_UNKNOWN_TAG)); - rb_define_const(eXMLError, "RNGP_ANYNAME_ATTR_ANCESTOR", INT2NUM(XML_RNGP_ANYNAME_ATTR_ANCESTOR)); - rb_define_const(eXMLError, "RNGP_ATTR_CONFLICT", INT2NUM(XML_RNGP_ATTR_CONFLICT)); - rb_define_const(eXMLError, "RNGP_ATTRIBUTE_CHILDREN", INT2NUM(XML_RNGP_ATTRIBUTE_CHILDREN)); - rb_define_const(eXMLError, "RNGP_ATTRIBUTE_CONTENT", INT2NUM(XML_RNGP_ATTRIBUTE_CONTENT)); - rb_define_const(eXMLError, "RNGP_ATTRIBUTE_EMPTY", INT2NUM(XML_RNGP_ATTRIBUTE_EMPTY)); - rb_define_const(eXMLError, "RNGP_ATTRIBUTE_NOOP", INT2NUM(XML_RNGP_ATTRIBUTE_NOOP)); - rb_define_const(eXMLError, "RNGP_CHOICE_CONTENT", INT2NUM(XML_RNGP_CHOICE_CONTENT)); - rb_define_const(eXMLError, "RNGP_CHOICE_EMPTY", INT2NUM(XML_RNGP_CHOICE_EMPTY)); - rb_define_const(eXMLError, "RNGP_CREATE_FAILURE", INT2NUM(XML_RNGP_CREATE_FAILURE)); - rb_define_const(eXMLError, "RNGP_DATA_CONTENT", INT2NUM(XML_RNGP_DATA_CONTENT)); - rb_define_const(eXMLError, "RNGP_DEF_CHOICE_AND_INTERLEAVE", INT2NUM(XML_RNGP_DEF_CHOICE_AND_INTERLEAVE)); - rb_define_const(eXMLError, "RNGP_DEFINE_CREATE_FAILED", INT2NUM(XML_RNGP_DEFINE_CREATE_FAILED)); - rb_define_const(eXMLError, "RNGP_DEFINE_EMPTY", INT2NUM(XML_RNGP_DEFINE_EMPTY)); - rb_define_const(eXMLError, "RNGP_DEFINE_MISSING", INT2NUM(XML_RNGP_DEFINE_MISSING)); - rb_define_const(eXMLError, "RNGP_DEFINE_NAME_MISSING", INT2NUM(XML_RNGP_DEFINE_NAME_MISSING)); - rb_define_const(eXMLError, "RNGP_ELEM_CONTENT_EMPTY", INT2NUM(XML_RNGP_ELEM_CONTENT_EMPTY)); - rb_define_const(eXMLError, "RNGP_ELEM_CONTENT_ERROR", INT2NUM(XML_RNGP_ELEM_CONTENT_ERROR)); - rb_define_const(eXMLError, "RNGP_ELEMENT_EMPTY", INT2NUM(XML_RNGP_ELEMENT_EMPTY)); - rb_define_const(eXMLError, "RNGP_ELEMENT_CONTENT", INT2NUM(XML_RNGP_ELEMENT_CONTENT)); - rb_define_const(eXMLError, "RNGP_ELEMENT_NAME", INT2NUM(XML_RNGP_ELEMENT_NAME)); - rb_define_const(eXMLError, "RNGP_ELEMENT_NO_CONTENT", INT2NUM(XML_RNGP_ELEMENT_NO_CONTENT)); - rb_define_const(eXMLError, "RNGP_ELEM_TEXT_CONFLICT", INT2NUM(XML_RNGP_ELEM_TEXT_CONFLICT)); - rb_define_const(eXMLError, "RNGP_EMPTY", INT2NUM(XML_RNGP_EMPTY)); - rb_define_const(eXMLError, "RNGP_EMPTY_CONSTRUCT", INT2NUM(XML_RNGP_EMPTY_CONSTRUCT)); - rb_define_const(eXMLError, "RNGP_EMPTY_CONTENT", INT2NUM(XML_RNGP_EMPTY_CONTENT)); - rb_define_const(eXMLError, "RNGP_EMPTY_NOT_EMPTY", INT2NUM(XML_RNGP_EMPTY_NOT_EMPTY)); - rb_define_const(eXMLError, "RNGP_ERROR_TYPE_LIB", INT2NUM(XML_RNGP_ERROR_TYPE_LIB)); - rb_define_const(eXMLError, "RNGP_EXCEPT_EMPTY", INT2NUM(XML_RNGP_EXCEPT_EMPTY)); - rb_define_const(eXMLError, "RNGP_EXCEPT_MISSING", INT2NUM(XML_RNGP_EXCEPT_MISSING)); - rb_define_const(eXMLError, "RNGP_EXCEPT_MULTIPLE", INT2NUM(XML_RNGP_EXCEPT_MULTIPLE)); - rb_define_const(eXMLError, "RNGP_EXCEPT_NO_CONTENT", INT2NUM(XML_RNGP_EXCEPT_NO_CONTENT)); - rb_define_const(eXMLError, "RNGP_EXTERNALREF_EMTPY", INT2NUM(XML_RNGP_EXTERNALREF_EMTPY)); - rb_define_const(eXMLError, "RNGP_EXTERNAL_REF_FAILURE", INT2NUM(XML_RNGP_EXTERNAL_REF_FAILURE)); - rb_define_const(eXMLError, "RNGP_EXTERNALREF_RECURSE", INT2NUM(XML_RNGP_EXTERNALREF_RECURSE)); - rb_define_const(eXMLError, "RNGP_FORBIDDEN_ATTRIBUTE", INT2NUM(XML_RNGP_FORBIDDEN_ATTRIBUTE)); - rb_define_const(eXMLError, "RNGP_FOREIGN_ELEMENT", INT2NUM(XML_RNGP_FOREIGN_ELEMENT)); - rb_define_const(eXMLError, "RNGP_GRAMMAR_CONTENT", INT2NUM(XML_RNGP_GRAMMAR_CONTENT)); - rb_define_const(eXMLError, "RNGP_GRAMMAR_EMPTY", INT2NUM(XML_RNGP_GRAMMAR_EMPTY)); - rb_define_const(eXMLError, "RNGP_GRAMMAR_MISSING", INT2NUM(XML_RNGP_GRAMMAR_MISSING)); - rb_define_const(eXMLError, "RNGP_GRAMMAR_NO_START", INT2NUM(XML_RNGP_GRAMMAR_NO_START)); - rb_define_const(eXMLError, "RNGP_GROUP_ATTR_CONFLICT", INT2NUM(XML_RNGP_GROUP_ATTR_CONFLICT)); - rb_define_const(eXMLError, "RNGP_HREF_ERROR", INT2NUM(XML_RNGP_HREF_ERROR)); - rb_define_const(eXMLError, "RNGP_INCLUDE_EMPTY", INT2NUM(XML_RNGP_INCLUDE_EMPTY)); - rb_define_const(eXMLError, "RNGP_INCLUDE_FAILURE", INT2NUM(XML_RNGP_INCLUDE_FAILURE)); - rb_define_const(eXMLError, "RNGP_INCLUDE_RECURSE", INT2NUM(XML_RNGP_INCLUDE_RECURSE)); - rb_define_const(eXMLError, "RNGP_INTERLEAVE_ADD", INT2NUM(XML_RNGP_INTERLEAVE_ADD)); - rb_define_const(eXMLError, "RNGP_INTERLEAVE_CREATE_FAILED", INT2NUM(XML_RNGP_INTERLEAVE_CREATE_FAILED)); - rb_define_const(eXMLError, "RNGP_INTERLEAVE_EMPTY", INT2NUM(XML_RNGP_INTERLEAVE_EMPTY)); - rb_define_const(eXMLError, "RNGP_INTERLEAVE_NO_CONTENT", INT2NUM(XML_RNGP_INTERLEAVE_NO_CONTENT)); - rb_define_const(eXMLError, "RNGP_INVALID_DEFINE_NAME", INT2NUM(XML_RNGP_INVALID_DEFINE_NAME)); - rb_define_const(eXMLError, "RNGP_INVALID_URI", INT2NUM(XML_RNGP_INVALID_URI)); - rb_define_const(eXMLError, "RNGP_INVALID_VALUE", INT2NUM(XML_RNGP_INVALID_VALUE)); - rb_define_const(eXMLError, "RNGP_MISSING_HREF", INT2NUM(XML_RNGP_MISSING_HREF)); - rb_define_const(eXMLError, "RNGP_NAME_MISSING", INT2NUM(XML_RNGP_NAME_MISSING)); - rb_define_const(eXMLError, "RNGP_NEED_COMBINE", INT2NUM(XML_RNGP_NEED_COMBINE)); - rb_define_const(eXMLError, "RNGP_NOTALLOWED_NOT_EMPTY", INT2NUM(XML_RNGP_NOTALLOWED_NOT_EMPTY)); - rb_define_const(eXMLError, "RNGP_NSNAME_ATTR_ANCESTOR", INT2NUM(XML_RNGP_NSNAME_ATTR_ANCESTOR)); - rb_define_const(eXMLError, "RNGP_NSNAME_NO_NS", INT2NUM(XML_RNGP_NSNAME_NO_NS)); - rb_define_const(eXMLError, "RNGP_PARAM_FORBIDDEN", INT2NUM(XML_RNGP_PARAM_FORBIDDEN)); - rb_define_const(eXMLError, "RNGP_PARAM_NAME_MISSING", INT2NUM(XML_RNGP_PARAM_NAME_MISSING)); - rb_define_const(eXMLError, "RNGP_PARENTREF_CREATE_FAILED", INT2NUM(XML_RNGP_PARENTREF_CREATE_FAILED)); - rb_define_const(eXMLError, "RNGP_PARENTREF_NAME_INVALID", INT2NUM(XML_RNGP_PARENTREF_NAME_INVALID)); - rb_define_const(eXMLError, "RNGP_PARENTREF_NO_NAME", INT2NUM(XML_RNGP_PARENTREF_NO_NAME)); - rb_define_const(eXMLError, "RNGP_PARENTREF_NO_PARENT", INT2NUM(XML_RNGP_PARENTREF_NO_PARENT)); - rb_define_const(eXMLError, "RNGP_PARENTREF_NOT_EMPTY", INT2NUM(XML_RNGP_PARENTREF_NOT_EMPTY)); - rb_define_const(eXMLError, "RNGP_PARSE_ERROR", INT2NUM(XML_RNGP_PARSE_ERROR)); - rb_define_const(eXMLError, "RNGP_PAT_ANYNAME_EXCEPT_ANYNAME", INT2NUM(XML_RNGP_PAT_ANYNAME_EXCEPT_ANYNAME)); - rb_define_const(eXMLError, "RNGP_PAT_ATTR_ATTR", INT2NUM(XML_RNGP_PAT_ATTR_ATTR)); - rb_define_const(eXMLError, "RNGP_PAT_ATTR_ELEM", INT2NUM(XML_RNGP_PAT_ATTR_ELEM)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_ATTR", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_ATTR)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_ELEM", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_ELEM)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_EMPTY", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_EMPTY)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_GROUP", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_GROUP)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_INTERLEAVE", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_LIST", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_LIST)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_ONEMORE", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_ONEMORE)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_REF", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_REF)); - rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_TEXT", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_TEXT)); - rb_define_const(eXMLError, "RNGP_PAT_LIST_ATTR", INT2NUM(XML_RNGP_PAT_LIST_ATTR)); - rb_define_const(eXMLError, "RNGP_PAT_LIST_ELEM", INT2NUM(XML_RNGP_PAT_LIST_ELEM)); - rb_define_const(eXMLError, "RNGP_PAT_LIST_INTERLEAVE", INT2NUM(XML_RNGP_PAT_LIST_INTERLEAVE)); - rb_define_const(eXMLError, "RNGP_PAT_LIST_LIST", INT2NUM(XML_RNGP_PAT_LIST_LIST)); - rb_define_const(eXMLError, "RNGP_PAT_LIST_REF", INT2NUM(XML_RNGP_PAT_LIST_REF)); - rb_define_const(eXMLError, "RNGP_PAT_LIST_TEXT", INT2NUM(XML_RNGP_PAT_LIST_TEXT)); - rb_define_const(eXMLError, "RNGP_PAT_NSNAME_EXCEPT_ANYNAME", INT2NUM(XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME)); - rb_define_const(eXMLError, "RNGP_PAT_NSNAME_EXCEPT_NSNAME", INT2NUM(XML_RNGP_PAT_NSNAME_EXCEPT_NSNAME)); - rb_define_const(eXMLError, "RNGP_PAT_ONEMORE_GROUP_ATTR", INT2NUM(XML_RNGP_PAT_ONEMORE_GROUP_ATTR)); - rb_define_const(eXMLError, "RNGP_PAT_ONEMORE_INTERLEAVE_ATTR", INT2NUM(XML_RNGP_PAT_ONEMORE_INTERLEAVE_ATTR)); - rb_define_const(eXMLError, "RNGP_PAT_START_ATTR", INT2NUM(XML_RNGP_PAT_START_ATTR)); - rb_define_const(eXMLError, "RNGP_PAT_START_DATA", INT2NUM(XML_RNGP_PAT_START_DATA)); - rb_define_const(eXMLError, "RNGP_PAT_START_EMPTY", INT2NUM(XML_RNGP_PAT_START_EMPTY)); - rb_define_const(eXMLError, "RNGP_PAT_START_GROUP", INT2NUM(XML_RNGP_PAT_START_GROUP)); - rb_define_const(eXMLError, "RNGP_PAT_START_INTERLEAVE", INT2NUM(XML_RNGP_PAT_START_INTERLEAVE)); - rb_define_const(eXMLError, "RNGP_PAT_START_LIST", INT2NUM(XML_RNGP_PAT_START_LIST)); - rb_define_const(eXMLError, "RNGP_PAT_START_ONEMORE", INT2NUM(XML_RNGP_PAT_START_ONEMORE)); - rb_define_const(eXMLError, "RNGP_PAT_START_TEXT", INT2NUM(XML_RNGP_PAT_START_TEXT)); - rb_define_const(eXMLError, "RNGP_PAT_START_VALUE", INT2NUM(XML_RNGP_PAT_START_VALUE)); - rb_define_const(eXMLError, "RNGP_PREFIX_UNDEFINED", INT2NUM(XML_RNGP_PREFIX_UNDEFINED)); - rb_define_const(eXMLError, "RNGP_REF_CREATE_FAILED", INT2NUM(XML_RNGP_REF_CREATE_FAILED)); - rb_define_const(eXMLError, "RNGP_REF_CYCLE", INT2NUM(XML_RNGP_REF_CYCLE)); - rb_define_const(eXMLError, "RNGP_REF_NAME_INVALID", INT2NUM(XML_RNGP_REF_NAME_INVALID)); - rb_define_const(eXMLError, "RNGP_REF_NO_DEF", INT2NUM(XML_RNGP_REF_NO_DEF)); - rb_define_const(eXMLError, "RNGP_REF_NO_NAME", INT2NUM(XML_RNGP_REF_NO_NAME)); - rb_define_const(eXMLError, "RNGP_REF_NOT_EMPTY", INT2NUM(XML_RNGP_REF_NOT_EMPTY)); - rb_define_const(eXMLError, "RNGP_START_CHOICE_AND_INTERLEAVE", INT2NUM(XML_RNGP_START_CHOICE_AND_INTERLEAVE)); - rb_define_const(eXMLError, "RNGP_START_CONTENT", INT2NUM(XML_RNGP_START_CONTENT)); - rb_define_const(eXMLError, "RNGP_START_EMPTY", INT2NUM(XML_RNGP_START_EMPTY)); - rb_define_const(eXMLError, "RNGP_START_MISSING", INT2NUM(XML_RNGP_START_MISSING)); - rb_define_const(eXMLError, "RNGP_TEXT_EXPECTED", INT2NUM(XML_RNGP_TEXT_EXPECTED)); - rb_define_const(eXMLError, "RNGP_TEXT_HAS_CHILD", INT2NUM(XML_RNGP_TEXT_HAS_CHILD)); - rb_define_const(eXMLError, "RNGP_TYPE_MISSING", INT2NUM(XML_RNGP_TYPE_MISSING)); - rb_define_const(eXMLError, "RNGP_TYPE_NOT_FOUND", INT2NUM(XML_RNGP_TYPE_NOT_FOUND)); - rb_define_const(eXMLError, "RNGP_TYPE_VALUE", INT2NUM(XML_RNGP_TYPE_VALUE)); - rb_define_const(eXMLError, "RNGP_UNKNOWN_ATTRIBUTE", INT2NUM(XML_RNGP_UNKNOWN_ATTRIBUTE)); - rb_define_const(eXMLError, "RNGP_UNKNOWN_COMBINE", INT2NUM(XML_RNGP_UNKNOWN_COMBINE)); - rb_define_const(eXMLError, "RNGP_UNKNOWN_CONSTRUCT", INT2NUM(XML_RNGP_UNKNOWN_CONSTRUCT)); - rb_define_const(eXMLError, "RNGP_UNKNOWN_TYPE_LIB", INT2NUM(XML_RNGP_UNKNOWN_TYPE_LIB)); - rb_define_const(eXMLError, "RNGP_URI_FRAGMENT", INT2NUM(XML_RNGP_URI_FRAGMENT)); - rb_define_const(eXMLError, "RNGP_URI_NOT_ABSOLUTE", INT2NUM(XML_RNGP_URI_NOT_ABSOLUTE)); - rb_define_const(eXMLError, "RNGP_VALUE_EMPTY", INT2NUM(XML_RNGP_VALUE_EMPTY)); - rb_define_const(eXMLError, "RNGP_VALUE_NO_CONTENT", INT2NUM(XML_RNGP_VALUE_NO_CONTENT)); - rb_define_const(eXMLError, "RNGP_XMLNS_NAME", INT2NUM(XML_RNGP_XMLNS_NAME)); - rb_define_const(eXMLError, "RNGP_XML_NS", INT2NUM(XML_RNGP_XML_NS)); - rb_define_const(eXMLError, "XPATH_EXPRESSION_OK", INT2NUM(XML_XPATH_EXPRESSION_OK)); - rb_define_const(eXMLError, "XPATH_NUMBER_ERROR", INT2NUM(XML_XPATH_NUMBER_ERROR)); - rb_define_const(eXMLError, "XPATH_UNFINISHED_LITERAL_ERROR", INT2NUM(XML_XPATH_UNFINISHED_LITERAL_ERROR)); - rb_define_const(eXMLError, "XPATH_START_LITERAL_ERROR", INT2NUM(XML_XPATH_START_LITERAL_ERROR)); - rb_define_const(eXMLError, "XPATH_VARIABLE_REF_ERROR", INT2NUM(XML_XPATH_VARIABLE_REF_ERROR)); - rb_define_const(eXMLError, "XPATH_UNDEF_VARIABLE_ERROR", INT2NUM(XML_XPATH_UNDEF_VARIABLE_ERROR)); - rb_define_const(eXMLError, "XPATH_INVALID_PREDICATE_ERROR", INT2NUM(XML_XPATH_INVALID_PREDICATE_ERROR)); - rb_define_const(eXMLError, "XPATH_EXPR_ERROR", INT2NUM(XML_XPATH_EXPR_ERROR)); - rb_define_const(eXMLError, "XPATH_UNCLOSED_ERROR", INT2NUM(XML_XPATH_UNCLOSED_ERROR)); - rb_define_const(eXMLError, "XPATH_UNKNOWN_FUNC_ERROR", INT2NUM(XML_XPATH_UNKNOWN_FUNC_ERROR)); - rb_define_const(eXMLError, "XPATH_INVALID_OPERAND", INT2NUM(XML_XPATH_INVALID_OPERAND)); - rb_define_const(eXMLError, "XPATH_INVALID_TYPE", INT2NUM(XML_XPATH_INVALID_TYPE)); - rb_define_const(eXMLError, "XPATH_INVALID_ARITY", INT2NUM(XML_XPATH_INVALID_ARITY)); - rb_define_const(eXMLError, "XPATH_INVALID_CTXT_SIZE", INT2NUM(XML_XPATH_INVALID_CTXT_SIZE)); - rb_define_const(eXMLError, "XPATH_INVALID_CTXT_POSITION", INT2NUM(XML_XPATH_INVALID_CTXT_POSITION)); - rb_define_const(eXMLError, "XPATH_MEMORY_ERROR", INT2NUM(XML_XPATH_MEMORY_ERROR)); - rb_define_const(eXMLError, "XPTR_SYNTAX_ERROR", INT2NUM(XML_XPTR_SYNTAX_ERROR)); - rb_define_const(eXMLError, "XPTR_RESOURCE_ERROR", INT2NUM(XML_XPTR_RESOURCE_ERROR)); - rb_define_const(eXMLError, "XPTR_SUB_RESOURCE_ERROR", INT2NUM(XML_XPTR_SUB_RESOURCE_ERROR)); - rb_define_const(eXMLError, "XPATH_UNDEF_PREFIX_ERROR", INT2NUM(XML_XPATH_UNDEF_PREFIX_ERROR)); - rb_define_const(eXMLError, "XPATH_ENCODING_ERROR", INT2NUM(XML_XPATH_ENCODING_ERROR)); - rb_define_const(eXMLError, "XPATH_INVALID_CHAR_ERROR", INT2NUM(XML_XPATH_INVALID_CHAR_ERROR)); - rb_define_const(eXMLError, "TREE_INVALID_HEX", INT2NUM(XML_TREE_INVALID_HEX)); - rb_define_const(eXMLError, "TREE_INVALID_DEC", INT2NUM(XML_TREE_INVALID_DEC)); - rb_define_const(eXMLError, "TREE_UNTERMINATED_ENTITY", INT2NUM(XML_TREE_UNTERMINATED_ENTITY)); -#if LIBXML_VERSION >= 20632 - rb_define_const(eXMLError, "TREE_NOT_UTF8", INT2NUM(XML_TREE_NOT_UTF8)); -#endif - rb_define_const(eXMLError, "SAVE_NOT_UTF8", INT2NUM(XML_SAVE_NOT_UTF8)); - rb_define_const(eXMLError, "SAVE_CHAR_INVALID", INT2NUM(XML_SAVE_CHAR_INVALID)); - rb_define_const(eXMLError, "SAVE_NO_DOCTYPE", INT2NUM(XML_SAVE_NO_DOCTYPE)); - rb_define_const(eXMLError, "SAVE_UNKNOWN_ENCODING", INT2NUM(XML_SAVE_UNKNOWN_ENCODING)); - rb_define_const(eXMLError, "REGEXP_COMPILE_ERROR", INT2NUM(XML_REGEXP_COMPILE_ERROR)); - rb_define_const(eXMLError, "IO_UNKNOWN", INT2NUM(XML_IO_UNKNOWN)); - rb_define_const(eXMLError, "IO_EACCES", INT2NUM(XML_IO_EACCES)); - rb_define_const(eXMLError, "IO_EAGAIN", INT2NUM(XML_IO_EAGAIN)); - rb_define_const(eXMLError, "IO_EBADF", INT2NUM(XML_IO_EBADF)); - rb_define_const(eXMLError, "IO_EBADMSG", INT2NUM(XML_IO_EBADMSG)); - rb_define_const(eXMLError, "IO_EBUSY", INT2NUM(XML_IO_EBUSY)); - rb_define_const(eXMLError, "IO_ECANCELED", INT2NUM(XML_IO_ECANCELED)); - rb_define_const(eXMLError, "IO_ECHILD", INT2NUM(XML_IO_ECHILD)); - rb_define_const(eXMLError, "IO_EDEADLK", INT2NUM(XML_IO_EDEADLK)); - rb_define_const(eXMLError, "IO_EDOM", INT2NUM(XML_IO_EDOM)); - rb_define_const(eXMLError, "IO_EEXIST", INT2NUM(XML_IO_EEXIST)); - rb_define_const(eXMLError, "IO_EFAULT", INT2NUM(XML_IO_EFAULT)); - rb_define_const(eXMLError, "IO_EFBIG", INT2NUM(XML_IO_EFBIG)); - rb_define_const(eXMLError, "IO_EINPROGRESS", INT2NUM(XML_IO_EINPROGRESS)); - rb_define_const(eXMLError, "IO_EINTR", INT2NUM(XML_IO_EINTR)); - rb_define_const(eXMLError, "IO_EINVAL", INT2NUM(XML_IO_EINVAL)); - rb_define_const(eXMLError, "IO_EIO", INT2NUM(XML_IO_EIO)); - rb_define_const(eXMLError, "IO_EISDIR", INT2NUM(XML_IO_EISDIR)); - rb_define_const(eXMLError, "IO_EMFILE", INT2NUM(XML_IO_EMFILE)); - rb_define_const(eXMLError, "IO_EMLINK", INT2NUM(XML_IO_EMLINK)); - rb_define_const(eXMLError, "IO_EMSGSIZE", INT2NUM(XML_IO_EMSGSIZE)); - rb_define_const(eXMLError, "IO_ENAMETOOLONG", INT2NUM(XML_IO_ENAMETOOLONG)); - rb_define_const(eXMLError, "IO_ENFILE", INT2NUM(XML_IO_ENFILE)); - rb_define_const(eXMLError, "IO_ENODEV", INT2NUM(XML_IO_ENODEV)); - rb_define_const(eXMLError, "IO_ENOENT", INT2NUM(XML_IO_ENOENT)); - rb_define_const(eXMLError, "IO_ENOEXEC", INT2NUM(XML_IO_ENOEXEC)); - rb_define_const(eXMLError, "IO_ENOLCK", INT2NUM(XML_IO_ENOLCK)); - rb_define_const(eXMLError, "IO_ENOMEM", INT2NUM(XML_IO_ENOMEM)); - rb_define_const(eXMLError, "IO_ENOSPC", INT2NUM(XML_IO_ENOSPC)); - rb_define_const(eXMLError, "IO_ENOSYS", INT2NUM(XML_IO_ENOSYS)); - rb_define_const(eXMLError, "IO_ENOTDIR", INT2NUM(XML_IO_ENOTDIR)); - rb_define_const(eXMLError, "IO_ENOTEMPTY", INT2NUM(XML_IO_ENOTEMPTY)); - rb_define_const(eXMLError, "IO_ENOTSUP", INT2NUM(XML_IO_ENOTSUP)); - rb_define_const(eXMLError, "IO_ENOTTY", INT2NUM(XML_IO_ENOTTY)); - rb_define_const(eXMLError, "IO_ENXIO", INT2NUM(XML_IO_ENXIO)); - rb_define_const(eXMLError, "IO_EPERM", INT2NUM(XML_IO_EPERM)); - rb_define_const(eXMLError, "IO_EPIPE", INT2NUM(XML_IO_EPIPE)); - rb_define_const(eXMLError, "IO_ERANGE", INT2NUM(XML_IO_ERANGE)); - rb_define_const(eXMLError, "IO_EROFS", INT2NUM(XML_IO_EROFS)); - rb_define_const(eXMLError, "IO_ESPIPE", INT2NUM(XML_IO_ESPIPE)); - rb_define_const(eXMLError, "IO_ESRCH", INT2NUM(XML_IO_ESRCH)); - rb_define_const(eXMLError, "IO_ETIMEDOUT", INT2NUM(XML_IO_ETIMEDOUT)); - rb_define_const(eXMLError, "IO_EXDEV", INT2NUM(XML_IO_EXDEV)); - rb_define_const(eXMLError, "IO_NETWORK_ATTEMPT", INT2NUM(XML_IO_NETWORK_ATTEMPT)); - rb_define_const(eXMLError, "IO_ENCODER", INT2NUM(XML_IO_ENCODER)); - rb_define_const(eXMLError, "IO_FLUSH", INT2NUM(XML_IO_FLUSH)); - rb_define_const(eXMLError, "IO_WRITE", INT2NUM(XML_IO_WRITE)); - rb_define_const(eXMLError, "IO_NO_INPUT", INT2NUM(XML_IO_NO_INPUT)); - rb_define_const(eXMLError, "IO_BUFFER_FULL", INT2NUM(XML_IO_BUFFER_FULL)); - rb_define_const(eXMLError, "IO_LOAD_ERROR", INT2NUM(XML_IO_LOAD_ERROR)); - rb_define_const(eXMLError, "IO_ENOTSOCK", INT2NUM(XML_IO_ENOTSOCK)); - rb_define_const(eXMLError, "IO_EISCONN", INT2NUM(XML_IO_EISCONN)); - rb_define_const(eXMLError, "IO_ECONNREFUSED", INT2NUM(XML_IO_ECONNREFUSED)); - rb_define_const(eXMLError, "IO_ENETUNREACH", INT2NUM(XML_IO_ENETUNREACH)); - rb_define_const(eXMLError, "IO_EADDRINUSE", INT2NUM(XML_IO_EADDRINUSE)); - rb_define_const(eXMLError, "IO_EALREADY", INT2NUM(XML_IO_EALREADY)); - rb_define_const(eXMLError, "IO_EAFNOSUPPORT", INT2NUM(XML_IO_EAFNOSUPPORT)); - rb_define_const(eXMLError, "XINCLUDE_RECURSION", INT2NUM(XML_XINCLUDE_RECURSION)); - rb_define_const(eXMLError, "XINCLUDE_PARSE_VALUE", INT2NUM(XML_XINCLUDE_PARSE_VALUE)); - rb_define_const(eXMLError, "XINCLUDE_ENTITY_DEF_MISMATCH", INT2NUM(XML_XINCLUDE_ENTITY_DEF_MISMATCH)); - rb_define_const(eXMLError, "XINCLUDE_NO_HREF", INT2NUM(XML_XINCLUDE_NO_HREF)); - rb_define_const(eXMLError, "XINCLUDE_NO_FALLBACK", INT2NUM(XML_XINCLUDE_NO_FALLBACK)); - rb_define_const(eXMLError, "XINCLUDE_HREF_URI", INT2NUM(XML_XINCLUDE_HREF_URI)); - rb_define_const(eXMLError, "XINCLUDE_TEXT_FRAGMENT", INT2NUM(XML_XINCLUDE_TEXT_FRAGMENT)); - rb_define_const(eXMLError, "XINCLUDE_TEXT_DOCUMENT", INT2NUM(XML_XINCLUDE_TEXT_DOCUMENT)); - rb_define_const(eXMLError, "XINCLUDE_INVALID_CHAR", INT2NUM(XML_XINCLUDE_INVALID_CHAR)); - rb_define_const(eXMLError, "XINCLUDE_BUILD_FAILED", INT2NUM(XML_XINCLUDE_BUILD_FAILED)); - rb_define_const(eXMLError, "XINCLUDE_UNKNOWN_ENCODING", INT2NUM(XML_XINCLUDE_UNKNOWN_ENCODING)); - rb_define_const(eXMLError, "XINCLUDE_MULTIPLE_ROOT", INT2NUM(XML_XINCLUDE_MULTIPLE_ROOT)); - rb_define_const(eXMLError, "XINCLUDE_XPTR_FAILED", INT2NUM(XML_XINCLUDE_XPTR_FAILED)); - rb_define_const(eXMLError, "XINCLUDE_XPTR_RESULT", INT2NUM(XML_XINCLUDE_XPTR_RESULT)); - rb_define_const(eXMLError, "XINCLUDE_INCLUDE_IN_INCLUDE", INT2NUM(XML_XINCLUDE_INCLUDE_IN_INCLUDE)); - rb_define_const(eXMLError, "XINCLUDE_FALLBACKS_IN_INCLUDE", INT2NUM(XML_XINCLUDE_FALLBACKS_IN_INCLUDE)); - rb_define_const(eXMLError, "XINCLUDE_FALLBACK_NOT_IN_INCLUDE", INT2NUM(XML_XINCLUDE_FALLBACK_NOT_IN_INCLUDE)); - rb_define_const(eXMLError, "XINCLUDE_DEPRECATED_NS", INT2NUM(XML_XINCLUDE_DEPRECATED_NS)); - rb_define_const(eXMLError, "XINCLUDE_FRAGMENT_ID", INT2NUM(XML_XINCLUDE_FRAGMENT_ID)); - rb_define_const(eXMLError, "CATALOG_MISSING_ATTR", INT2NUM(XML_CATALOG_MISSING_ATTR)); - rb_define_const(eXMLError, "CATALOG_ENTRY_BROKEN", INT2NUM(XML_CATALOG_ENTRY_BROKEN)); - rb_define_const(eXMLError, "CATALOG_PREFER_VALUE", INT2NUM(XML_CATALOG_PREFER_VALUE)); - rb_define_const(eXMLError, "CATALOG_NOT_CATALOG", INT2NUM(XML_CATALOG_NOT_CATALOG)); - rb_define_const(eXMLError, "CATALOG_RECURSION", INT2NUM(XML_CATALOG_RECURSION)); - rb_define_const(eXMLError, "SCHEMAP_PREFIX_UNDEFINED", INT2NUM(XML_SCHEMAP_PREFIX_UNDEFINED)); - rb_define_const(eXMLError, "SCHEMAP_ATTRFORMDEFAULT_VALUE", INT2NUM(XML_SCHEMAP_ATTRFORMDEFAULT_VALUE)); - rb_define_const(eXMLError, "SCHEMAP_ATTRGRP_NONAME_NOREF", INT2NUM(XML_SCHEMAP_ATTRGRP_NONAME_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_ATTR_NONAME_NOREF", INT2NUM(XML_SCHEMAP_ATTR_NONAME_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_COMPLEXTYPE_NONAME_NOREF", INT2NUM(XML_SCHEMAP_COMPLEXTYPE_NONAME_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_ELEMFORMDEFAULT_VALUE", INT2NUM(XML_SCHEMAP_ELEMFORMDEFAULT_VALUE)); - rb_define_const(eXMLError, "SCHEMAP_ELEM_NONAME_NOREF", INT2NUM(XML_SCHEMAP_ELEM_NONAME_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_EXTENSION_NO_BASE", INT2NUM(XML_SCHEMAP_EXTENSION_NO_BASE)); - rb_define_const(eXMLError, "SCHEMAP_FACET_NO_VALUE", INT2NUM(XML_SCHEMAP_FACET_NO_VALUE)); - rb_define_const(eXMLError, "SCHEMAP_FAILED_BUILD_IMPORT", INT2NUM(XML_SCHEMAP_FAILED_BUILD_IMPORT)); - rb_define_const(eXMLError, "SCHEMAP_GROUP_NONAME_NOREF", INT2NUM(XML_SCHEMAP_GROUP_NONAME_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_IMPORT_NAMESPACE_NOT_URI", INT2NUM(XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI)); - rb_define_const(eXMLError, "SCHEMAP_IMPORT_REDEFINE_NSNAME", INT2NUM(XML_SCHEMAP_IMPORT_REDEFINE_NSNAME)); - rb_define_const(eXMLError, "SCHEMAP_IMPORT_SCHEMA_NOT_URI", INT2NUM(XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_BOOLEAN", INT2NUM(XML_SCHEMAP_INVALID_BOOLEAN)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_ENUM", INT2NUM(XML_SCHEMAP_INVALID_ENUM)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_FACET", INT2NUM(XML_SCHEMAP_INVALID_FACET)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_FACET_VALUE", INT2NUM(XML_SCHEMAP_INVALID_FACET_VALUE)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_MAXOCCURS", INT2NUM(XML_SCHEMAP_INVALID_MAXOCCURS)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_MINOCCURS", INT2NUM(XML_SCHEMAP_INVALID_MINOCCURS)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_REF_AND_SUBTYPE", INT2NUM(XML_SCHEMAP_INVALID_REF_AND_SUBTYPE)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_WHITE_SPACE", INT2NUM(XML_SCHEMAP_INVALID_WHITE_SPACE)); - rb_define_const(eXMLError, "SCHEMAP_NOATTR_NOREF", INT2NUM(XML_SCHEMAP_NOATTR_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_NOTATION_NO_NAME", INT2NUM(XML_SCHEMAP_NOTATION_NO_NAME)); - rb_define_const(eXMLError, "SCHEMAP_NOTYPE_NOREF", INT2NUM(XML_SCHEMAP_NOTYPE_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_REF_AND_SUBTYPE", INT2NUM(XML_SCHEMAP_REF_AND_SUBTYPE)); - rb_define_const(eXMLError, "SCHEMAP_RESTRICTION_NONAME_NOREF", INT2NUM(XML_SCHEMAP_RESTRICTION_NONAME_NOREF)); - rb_define_const(eXMLError, "SCHEMAP_SIMPLETYPE_NONAME", INT2NUM(XML_SCHEMAP_SIMPLETYPE_NONAME)); - rb_define_const(eXMLError, "SCHEMAP_TYPE_AND_SUBTYPE", INT2NUM(XML_SCHEMAP_TYPE_AND_SUBTYPE)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ALL_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ALL_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ANYATTRIBUTE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ANYATTRIBUTE_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ATTR_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ATTR_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ATTRGRP_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ATTRGRP_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ATTRIBUTE_GROUP", INT2NUM(XML_SCHEMAP_UNKNOWN_ATTRIBUTE_GROUP)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_BASE_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_BASE_TYPE)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_CHOICE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_CHOICE_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_COMPLEXCONTENT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_COMPLEXCONTENT_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_COMPLEXTYPE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_COMPLEXTYPE_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ELEM_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ELEM_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_EXTENSION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_EXTENSION_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_FACET_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_FACET_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_FACET_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_FACET_TYPE)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_GROUP_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_GROUP_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_IMPORT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_IMPORT_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_LIST_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_LIST_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_NOTATION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_NOTATION_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_REF", INT2NUM(XML_SCHEMAP_UNKNOWN_REF)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_RESTRICTION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SCHEMAS_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SCHEMAS_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SEQUENCE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SIMPLETYPE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SIMPLETYPE_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_TYPE)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_UNION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_UNION_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_ELEM_DEFAULT_FIXED", INT2NUM(XML_SCHEMAP_ELEM_DEFAULT_FIXED)); - rb_define_const(eXMLError, "SCHEMAP_REGEXP_INVALID", INT2NUM(XML_SCHEMAP_REGEXP_INVALID)); - rb_define_const(eXMLError, "SCHEMAP_FAILED_LOAD", INT2NUM(XML_SCHEMAP_FAILED_LOAD)); - rb_define_const(eXMLError, "SCHEMAP_NOTHING_TO_PARSE", INT2NUM(XML_SCHEMAP_NOTHING_TO_PARSE)); - rb_define_const(eXMLError, "SCHEMAP_NOROOT", INT2NUM(XML_SCHEMAP_NOROOT)); - rb_define_const(eXMLError, "SCHEMAP_REDEFINED_GROUP", INT2NUM(XML_SCHEMAP_REDEFINED_GROUP)); - rb_define_const(eXMLError, "SCHEMAP_REDEFINED_TYPE", INT2NUM(XML_SCHEMAP_REDEFINED_TYPE)); - rb_define_const(eXMLError, "SCHEMAP_REDEFINED_ELEMENT", INT2NUM(XML_SCHEMAP_REDEFINED_ELEMENT)); - rb_define_const(eXMLError, "SCHEMAP_REDEFINED_ATTRGROUP", INT2NUM(XML_SCHEMAP_REDEFINED_ATTRGROUP)); - rb_define_const(eXMLError, "SCHEMAP_REDEFINED_ATTR", INT2NUM(XML_SCHEMAP_REDEFINED_ATTR)); - rb_define_const(eXMLError, "SCHEMAP_REDEFINED_NOTATION", INT2NUM(XML_SCHEMAP_REDEFINED_NOTATION)); - rb_define_const(eXMLError, "SCHEMAP_FAILED_PARSE", INT2NUM(XML_SCHEMAP_FAILED_PARSE)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_PREFIX", INT2NUM(XML_SCHEMAP_UNKNOWN_PREFIX)); - rb_define_const(eXMLError, "SCHEMAP_DEF_AND_PREFIX", INT2NUM(XML_SCHEMAP_DEF_AND_PREFIX)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_INCLUDE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_INCLUDE_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_INCLUDE_SCHEMA_NOT_URI", INT2NUM(XML_SCHEMAP_INCLUDE_SCHEMA_NOT_URI)); - rb_define_const(eXMLError, "SCHEMAP_INCLUDE_SCHEMA_NO_URI", INT2NUM(XML_SCHEMAP_INCLUDE_SCHEMA_NO_URI)); - rb_define_const(eXMLError, "SCHEMAP_NOT_SCHEMA", INT2NUM(XML_SCHEMAP_NOT_SCHEMA)); - rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_MEMBER_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_MEMBER_TYPE)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_USE", INT2NUM(XML_SCHEMAP_INVALID_ATTR_USE)); - rb_define_const(eXMLError, "SCHEMAP_RECURSIVE", INT2NUM(XML_SCHEMAP_RECURSIVE)); - rb_define_const(eXMLError, "SCHEMAP_SUPERNUMEROUS_LIST_ITEM_TYPE", INT2NUM(XML_SCHEMAP_SUPERNUMEROUS_LIST_ITEM_TYPE)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_COMBINATION", INT2NUM(XML_SCHEMAP_INVALID_ATTR_COMBINATION)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_INLINE_COMBINATION", INT2NUM(XML_SCHEMAP_INVALID_ATTR_INLINE_COMBINATION)); - rb_define_const(eXMLError, "SCHEMAP_MISSING_SIMPLETYPE_CHILD", INT2NUM(XML_SCHEMAP_MISSING_SIMPLETYPE_CHILD)); - rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_NAME", INT2NUM(XML_SCHEMAP_INVALID_ATTR_NAME)); - rb_define_const(eXMLError, "SCHEMAP_REF_AND_CONTENT", INT2NUM(XML_SCHEMAP_REF_AND_CONTENT)); - rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_1)); - rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_2)); - rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_3)); - rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_4", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_4)); - rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_5", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_5)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_1", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_2", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_3", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3)); - rb_define_const(eXMLError, "SCHEMAP_WILDCARD_INVALID_NS_MEMBER", INT2NUM(XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER)); - rb_define_const(eXMLError, "SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE", INT2NUM(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE)); - rb_define_const(eXMLError, "SCHEMAP_UNION_NOT_EXPRESSIBLE", INT2NUM(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_3_1", INT2NUM(XML_SCHEMAP_SRC_IMPORT_3_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_3_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_3_2)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_4_1", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_4_2", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_4_3", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3)); - rb_define_const(eXMLError, "SCHEMAP_COS_CT_EXTENDS_1_3", INT2NUM(XML_SCHEMAP_COS_CT_EXTENDS_1_3)); - rb_define_const(eXMLError, "SCHEMAV_NOROOT", INT2NUM(XML_SCHEMAV_NOROOT)); - rb_define_const(eXMLError, "SCHEMAV_UNDECLAREDELEM", INT2NUM(XML_SCHEMAV_UNDECLAREDELEM)); - rb_define_const(eXMLError, "SCHEMAV_NOTTOPLEVEL", INT2NUM(XML_SCHEMAV_NOTTOPLEVEL)); - rb_define_const(eXMLError, "SCHEMAV_MISSING", INT2NUM(XML_SCHEMAV_MISSING)); - rb_define_const(eXMLError, "SCHEMAV_WRONGELEM", INT2NUM(XML_SCHEMAV_WRONGELEM)); - rb_define_const(eXMLError, "SCHEMAV_NOTYPE", INT2NUM(XML_SCHEMAV_NOTYPE)); - rb_define_const(eXMLError, "SCHEMAV_NOROLLBACK", INT2NUM(XML_SCHEMAV_NOROLLBACK)); - rb_define_const(eXMLError, "SCHEMAV_ISABSTRACT", INT2NUM(XML_SCHEMAV_ISABSTRACT)); - rb_define_const(eXMLError, "SCHEMAV_NOTEMPTY", INT2NUM(XML_SCHEMAV_NOTEMPTY)); - rb_define_const(eXMLError, "SCHEMAV_ELEMCONT", INT2NUM(XML_SCHEMAV_ELEMCONT)); - rb_define_const(eXMLError, "SCHEMAV_HAVEDEFAULT", INT2NUM(XML_SCHEMAV_HAVEDEFAULT)); - rb_define_const(eXMLError, "SCHEMAV_NOTNILLABLE", INT2NUM(XML_SCHEMAV_NOTNILLABLE)); - rb_define_const(eXMLError, "SCHEMAV_EXTRACONTENT", INT2NUM(XML_SCHEMAV_EXTRACONTENT)); - rb_define_const(eXMLError, "SCHEMAV_INVALIDATTR", INT2NUM(XML_SCHEMAV_INVALIDATTR)); - rb_define_const(eXMLError, "SCHEMAV_INVALIDELEM", INT2NUM(XML_SCHEMAV_INVALIDELEM)); - rb_define_const(eXMLError, "SCHEMAV_NOTDETERMINIST", INT2NUM(XML_SCHEMAV_NOTDETERMINIST)); - rb_define_const(eXMLError, "SCHEMAV_CONSTRUCT", INT2NUM(XML_SCHEMAV_CONSTRUCT)); - rb_define_const(eXMLError, "SCHEMAV_INTERNAL", INT2NUM(XML_SCHEMAV_INTERNAL)); - rb_define_const(eXMLError, "SCHEMAV_NOTSIMPLE", INT2NUM(XML_SCHEMAV_NOTSIMPLE)); - rb_define_const(eXMLError, "SCHEMAV_ATTRUNKNOWN", INT2NUM(XML_SCHEMAV_ATTRUNKNOWN)); - rb_define_const(eXMLError, "SCHEMAV_ATTRINVALID", INT2NUM(XML_SCHEMAV_ATTRINVALID)); - rb_define_const(eXMLError, "SCHEMAV_VALUE", INT2NUM(XML_SCHEMAV_VALUE)); - rb_define_const(eXMLError, "SCHEMAV_FACET", INT2NUM(XML_SCHEMAV_FACET)); - rb_define_const(eXMLError, "SCHEMAV_CVC_DATATYPE_VALID_1_2_1", INT2NUM(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_DATATYPE_VALID_1_2_2", INT2NUM(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_DATATYPE_VALID_1_2_3", INT2NUM(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3)); - rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_3_1_1", INT2NUM(XML_SCHEMAV_CVC_TYPE_3_1_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_3_1_2", INT2NUM(XML_SCHEMAV_CVC_TYPE_3_1_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_FACET_VALID", INT2NUM(XML_SCHEMAV_CVC_FACET_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_LENGTH_VALID", INT2NUM(XML_SCHEMAV_CVC_LENGTH_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_MINLENGTH_VALID", INT2NUM(XML_SCHEMAV_CVC_MINLENGTH_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_MAXLENGTH_VALID", INT2NUM(XML_SCHEMAV_CVC_MAXLENGTH_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_MININCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MININCLUSIVE_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_MAXINCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MAXINCLUSIVE_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_MINEXCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MINEXCLUSIVE_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_MAXEXCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MAXEXCLUSIVE_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_TOTALDIGITS_VALID", INT2NUM(XML_SCHEMAV_CVC_TOTALDIGITS_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_FRACTIONDIGITS_VALID", INT2NUM(XML_SCHEMAV_CVC_FRACTIONDIGITS_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_PATTERN_VALID", INT2NUM(XML_SCHEMAV_CVC_PATTERN_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ENUMERATION_VALID", INT2NUM(XML_SCHEMAV_CVC_ENUMERATION_VALID)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_2", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_3", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_4", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_4)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_1", INT2NUM(XML_SCHEMAV_CVC_ELT_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_2", INT2NUM(XML_SCHEMAV_CVC_ELT_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_3_1", INT2NUM(XML_SCHEMAV_CVC_ELT_3_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_3_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_3_2_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_3_2_2", INT2NUM(XML_SCHEMAV_CVC_ELT_3_2_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_4_1", INT2NUM(XML_SCHEMAV_CVC_ELT_4_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_4_2", INT2NUM(XML_SCHEMAV_CVC_ELT_4_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_4_3", INT2NUM(XML_SCHEMAV_CVC_ELT_4_3)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_1_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_1_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_1_2", INT2NUM(XML_SCHEMAV_CVC_ELT_5_1_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_2_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_2_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_2_2_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_2_2_2", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_2_2_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_6", INT2NUM(XML_SCHEMAV_CVC_ELT_6)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_7",INT2NUM(XML_SCHEMAV_CVC_ELT_7)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_1", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_2", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_3", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_3)); - rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_4", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_4)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_3_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_3_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_3_2_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_3_2_2", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_4", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_4)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_5_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_5_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_5_2", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_5_2)); - rb_define_const(eXMLError, "SCHEMAV_ELEMENT_CONTENT", INT2NUM(XML_SCHEMAV_ELEMENT_CONTENT)); - rb_define_const(eXMLError, "SCHEMAV_DOCUMENT_ELEMENT_MISSING", INT2NUM(XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING)); - rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_AU", INT2NUM(XML_SCHEMAV_CVC_AU)); - rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_1", INT2NUM(XML_SCHEMAV_CVC_TYPE_1)); - rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_2", INT2NUM(XML_SCHEMAV_CVC_TYPE_2)); -#if LIBXML_VERSION >= 20618 - rb_define_const(eXMLError, "SCHEMAV_CVC_IDC", INT2NUM(XML_SCHEMAV_CVC_IDC)); - rb_define_const(eXMLError, "SCHEMAV_CVC_WILDCARD", INT2NUM(XML_SCHEMAV_CVC_WILDCARD)); -#endif -#if LIBXML_VERSION >= 20631 - rb_define_const(eXMLError, "SCHEMAV_MISC", INT2NUM(XML_SCHEMAV_MISC)); -#endif - rb_define_const(eXMLError, "XPTR_UNKNOWN_SCHEME", INT2NUM(XML_XPTR_UNKNOWN_SCHEME)); - rb_define_const(eXMLError, "XPTR_CHILDSEQ_START", INT2NUM(XML_XPTR_CHILDSEQ_START)); - rb_define_const(eXMLError, "XPTR_EVAL_FAILED", INT2NUM(XML_XPTR_EVAL_FAILED)); - rb_define_const(eXMLError, "XPTR_EXTRA_OBJECTS", INT2NUM(XML_XPTR_EXTRA_OBJECTS)); - rb_define_const(eXMLError, "C14N_CREATE_CTXT", INT2NUM(XML_C14N_CREATE_CTXT)); - rb_define_const(eXMLError, "C14N_REQUIRES_UTF8", INT2NUM(XML_C14N_REQUIRES_UTF8)); - rb_define_const(eXMLError, "C14N_CREATE_STACK", - INT2NUM(XML_C14N_CREATE_STACK)); - rb_define_const(eXMLError, "C14N_INVALID_NODE", - INT2NUM(XML_C14N_INVALID_NODE)); -#if LIBXML_VERSION >= 20619 - rb_define_const(eXMLError, "C14N_UNKNOW_NODE", INT2NUM(XML_C14N_UNKNOW_NODE)); - rb_define_const(eXMLError, "C14N_RELATIVE_NAMESPACE", INT2NUM(XML_C14N_RELATIVE_NAMESPACE)); -#endif - rb_define_const(eXMLError, "FTP_PASV_ANSWER", INT2NUM(XML_FTP_PASV_ANSWER)); - rb_define_const(eXMLError, "FTP_EPSV_ANSWER", INT2NUM(XML_FTP_EPSV_ANSWER)); - rb_define_const(eXMLError, "FTP_ACCNT", INT2NUM(XML_FTP_ACCNT)); -#if LIBXML_VERSION >= 20618 - rb_define_const(eXMLError, "FTP_URL_SYNTAX", INT2NUM(XML_FTP_URL_SYNTAX)); -#endif - rb_define_const(eXMLError, "HTTP_URL_SYNTAX", INT2NUM(XML_HTTP_URL_SYNTAX)); - rb_define_const(eXMLError, "HTTP_USE_IP", INT2NUM(XML_HTTP_USE_IP)); - rb_define_const(eXMLError, "HTTP_UNKNOWN_HOST", INT2NUM(XML_HTTP_UNKNOWN_HOST)); - rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_1", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_2", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_3", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_3)); - rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_4", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_4)); - rb_define_const(eXMLError, "SCHEMAP_SRC_RESOLVE", INT2NUM(XML_SCHEMAP_SRC_RESOLVE)); - rb_define_const(eXMLError, "SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE", INT2NUM(XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE)); - rb_define_const(eXMLError, "SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE", INT2NUM(XML_SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE)); - rb_define_const(eXMLError, "SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES", INT2NUM(XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES)); - rb_define_const(eXMLError, "SCHEMAP_ST_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_ST_PROPS_CORRECT_1)); - rb_define_const(eXMLError, "SCHEMAP_ST_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_ST_PROPS_CORRECT_2)); - rb_define_const(eXMLError, "SCHEMAP_ST_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_ST_PROPS_CORRECT_3)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_2)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_3_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_3_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_3_2)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_1_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_1_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_3", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_4", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_5", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_5)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_1_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_3", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_4", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_5", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_5)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_DERIVED_OK_2_1", INT2NUM(XML_SCHEMAP_COS_ST_DERIVED_OK_2_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_ST_DERIVED_OK_2_2", INT2NUM(XML_SCHEMAP_COS_ST_DERIVED_OK_2_2)); - rb_define_const(eXMLError, "SCHEMAP_S4S_ELEM_NOT_ALLOWED", INT2NUM(XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED)); - rb_define_const(eXMLError, "SCHEMAP_S4S_ELEM_MISSING", INT2NUM(XML_SCHEMAP_S4S_ELEM_MISSING)); - rb_define_const(eXMLError, "SCHEMAP_S4S_ATTR_NOT_ALLOWED", INT2NUM(XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED)); - rb_define_const(eXMLError, "SCHEMAP_S4S_ATTR_MISSING", INT2NUM(XML_SCHEMAP_S4S_ATTR_MISSING)); - rb_define_const(eXMLError, "SCHEMAP_S4S_ATTR_INVALID_VALUE", INT2NUM(XML_SCHEMAP_S4S_ATTR_INVALID_VALUE)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_1", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_2_1", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_2_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_2_2", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_2_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_3", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_3)); - rb_define_const(eXMLError, "SCHEMAP_P_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_P_PROPS_CORRECT_1)); - rb_define_const(eXMLError, "SCHEMAP_P_PROPS_CORRECT_2_1", INT2NUM(XML_SCHEMAP_P_PROPS_CORRECT_2_1)); - rb_define_const(eXMLError, "SCHEMAP_P_PROPS_CORRECT_2_2", INT2NUM(XML_SCHEMAP_P_PROPS_CORRECT_2_2)); - rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_2)); - rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_3)); - rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_4", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_4)); - rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_5", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_5)); - rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_6", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_6)); - rb_define_const(eXMLError, "SCHEMAP_SRC_INCLUDE", INT2NUM(XML_SCHEMAP_SRC_INCLUDE)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_1", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_2", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_3_1", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_3_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_3_2", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_3_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_4", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_4)); - rb_define_const(eXMLError, "SCHEMAP_NO_XMLNS", INT2NUM(XML_SCHEMAP_NO_XMLNS)); - rb_define_const(eXMLError, "SCHEMAP_NO_XSI", INT2NUM(XML_SCHEMAP_NO_XSI)); - rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_1", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_2_1", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_2_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_2_2_1", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_2_2_1)); - rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_2_2_2", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_2_2_2)); - rb_define_const(eXMLError, "SCHEMAP_CVC_SIMPLE_TYPE", INT2NUM(XML_SCHEMAP_CVC_SIMPLE_TYPE)); - rb_define_const(eXMLError, "SCHEMAP_COS_CT_EXTENDS_1_1", INT2NUM(XML_SCHEMAP_COS_CT_EXTENDS_1_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_1_1", INT2NUM(XML_SCHEMAP_SRC_IMPORT_1_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_1_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_1_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_2_1", INT2NUM(XML_SCHEMAP_SRC_IMPORT_2_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_2_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_2_2)); - rb_define_const(eXMLError, "SCHEMAP_INTERNAL", INT2NUM(XML_SCHEMAP_INTERNAL)); - rb_define_const(eXMLError, "SCHEMAP_NOT_DETERMINISTIC", INT2NUM(XML_SCHEMAP_NOT_DETERMINISTIC)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_GROUP_1", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_1)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_GROUP_2", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_GROUP_3", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3)); - rb_define_const(eXMLError, "SCHEMAP_MG_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_MG_PROPS_CORRECT_1)); - rb_define_const(eXMLError, "SCHEMAP_MG_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_MG_PROPS_CORRECT_2)); - rb_define_const(eXMLError, "SCHEMAP_SRC_CT_1", INT2NUM(XML_SCHEMAP_SRC_CT_1)); - rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3)); - rb_define_const(eXMLError, "SCHEMAP_AU_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_AU_PROPS_CORRECT_2)); - rb_define_const(eXMLError, "SCHEMAP_A_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_A_PROPS_CORRECT_2)); -#if LIBXML_VERSION >= 20620 - rb_define_const(eXMLError, "SCHEMAP_C_PROPS_CORRECT", INT2NUM(XML_SCHEMAP_C_PROPS_CORRECT)); -#endif -#if LIBXML_VERSION >= 20621 - rb_define_const(eXMLError, "SCHEMAP_SRC_REDEFINE", INT2NUM(XML_SCHEMAP_SRC_REDEFINE)); - rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT", INT2NUM(XML_SCHEMAP_SRC_IMPORT)); - rb_define_const(eXMLError, "SCHEMAP_WARN_SKIP_SCHEMA", INT2NUM(XML_SCHEMAP_WARN_SKIP_SCHEMA)); - rb_define_const(eXMLError, "SCHEMAP_WARN_UNLOCATED_SCHEMA", INT2NUM(XML_SCHEMAP_WARN_UNLOCATED_SCHEMA)); - rb_define_const(eXMLError, "SCHEMAP_WARN_ATTR_REDECL_PROH", INT2NUM(XML_SCHEMAP_WARN_ATTR_REDECL_PROH)); - rb_define_const(eXMLError, "SCHEMAP_WARN_ATTR_POINTLESS_PROH", INT2NUM(XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH)); -#endif -#if LIBXML_VERSION >= 20623 - rb_define_const(eXMLError, "SCHEMAP_AG_PROPS_CORRECT", INT2NUM(XML_SCHEMAP_AG_PROPS_CORRECT)); - rb_define_const(eXMLError, "SCHEMAP_COS_CT_EXTENDS_1_2", INT2NUM(XML_SCHEMAP_COS_CT_EXTENDS_1_2)); - rb_define_const(eXMLError, "SCHEMAP_AU_PROPS_CORRECT", INT2NUM(XML_SCHEMAP_AU_PROPS_CORRECT)); - rb_define_const(eXMLError, "SCHEMAP_A_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_A_PROPS_CORRECT_3)); - rb_define_const(eXMLError, "SCHEMAP_COS_ALL_LIMITED", INT2NUM(XML_SCHEMAP_COS_ALL_LIMITED)); -#endif -#if LIBXML_VERSION >= 20632 - rb_define_const(eXMLError, "SCHEMATRONV_ASSERT", INT2NUM(XML_SCHEMATRONV_ASSERT)); - rb_define_const(eXMLError, "SCHEMATRONV_REPORT", INT2NUM(XML_SCHEMATRONV_REPORT)); -#endif -#if LIBXML_VERSION >= 20618 - rb_define_const(eXMLError, "MODULE_OPEN", INT2NUM(XML_MODULE_OPEN)); - rb_define_const(eXMLError, "MODULE_CLOSE", INT2NUM(XML_MODULE_CLOSE)); -#endif - rb_define_const(eXMLError, "CHECK_FOUND_ELEMENT", INT2NUM(XML_CHECK_FOUND_ELEMENT)); - rb_define_const(eXMLError, "CHECK_FOUND_ATTRIBUTE", INT2NUM(XML_CHECK_FOUND_ATTRIBUTE)); - rb_define_const(eXMLError, "CHECK_FOUND_TEXT", INT2NUM(XML_CHECK_FOUND_TEXT)); - rb_define_const(eXMLError, "CHECK_FOUND_CDATA",INT2NUM(XML_CHECK_FOUND_CDATA)); - rb_define_const(eXMLError, "CHECK_FOUND_ENTITYREF", INT2NUM(XML_CHECK_FOUND_ENTITYREF)); - rb_define_const(eXMLError, "CHECK_FOUND_ENTITY", INT2NUM(XML_CHECK_FOUND_ENTITY)); - rb_define_const(eXMLError, "CHECK_FOUND_PI", INT2NUM(XML_CHECK_FOUND_PI)); - rb_define_const(eXMLError, "CHECK_FOUND_COMMENT", INT2NUM(XML_CHECK_FOUND_COMMENT)); - rb_define_const(eXMLError, "CHECK_FOUND_DOCTYPE", INT2NUM(XML_CHECK_FOUND_DOCTYPE)); - rb_define_const(eXMLError, "CHECK_FOUND_FRAGMENT", INT2NUM(XML_CHECK_FOUND_FRAGMENT)); - rb_define_const(eXMLError, "CHECK_FOUND_NOTATION", INT2NUM(XML_CHECK_FOUND_NOTATION)); - rb_define_const(eXMLError, "CHECK_UNKNOWN_NODE", INT2NUM(XML_CHECK_UNKNOWN_NODE)); - rb_define_const(eXMLError, "CHECK_ENTITY_TYPE", INT2NUM(XML_CHECK_ENTITY_TYPE)); - rb_define_const(eXMLError, "CHECK_NO_PARENT", INT2NUM(XML_CHECK_NO_PARENT)); - rb_define_const(eXMLError, "CHECK_NO_DOC", INT2NUM(XML_CHECK_NO_DOC)); - rb_define_const(eXMLError, "CHECK_NO_NAME", INT2NUM(XML_CHECK_NO_NAME)); - rb_define_const(eXMLError, "CHECK_NO_ELEM", INT2NUM(XML_CHECK_NO_ELEM)); - rb_define_const(eXMLError, "CHECK_WRONG_DOC", INT2NUM(XML_CHECK_WRONG_DOC)); - rb_define_const(eXMLError, "CHECK_NO_PREV", INT2NUM(XML_CHECK_NO_PREV)); - rb_define_const(eXMLError, "CHECK_WRONG_PREV", INT2NUM(XML_CHECK_WRONG_PREV)); - rb_define_const(eXMLError, "CHECK_NO_NEXT", INT2NUM(XML_CHECK_NO_NEXT)); - rb_define_const(eXMLError, "CHECK_WRONG_NEXT", INT2NUM(XML_CHECK_WRONG_NEXT)); - rb_define_const(eXMLError, "CHECK_NOT_DTD", INT2NUM(XML_CHECK_NOT_DTD)); - rb_define_const(eXMLError, "CHECK_NOT_ATTR", INT2NUM(XML_CHECK_NOT_ATTR)); - rb_define_const(eXMLError, "CHECK_NOT_ATTR_DECL", INT2NUM(XML_CHECK_NOT_ATTR_DECL)); - rb_define_const(eXMLError, "CHECK_NOT_ELEM_DECL", INT2NUM(XML_CHECK_NOT_ELEM_DECL)); - rb_define_const(eXMLError, "CHECK_NOT_ENTITY_DECL", INT2NUM(XML_CHECK_NOT_ENTITY_DECL)); - rb_define_const(eXMLError, "CHECK_NOT_NS_DECL", INT2NUM(XML_CHECK_NOT_NS_DECL)); - rb_define_const(eXMLError, "CHECK_NO_HREF", INT2NUM(XML_CHECK_NO_HREF)); - rb_define_const(eXMLError, "CHECK_WRONG_PARENT", INT2NUM(XML_CHECK_WRONG_PARENT)); - rb_define_const(eXMLError, "CHECK_NS_SCOPE", INT2NUM(XML_CHECK_NS_SCOPE)); - rb_define_const(eXMLError, "CHECK_NS_ANCESTOR", INT2NUM(XML_CHECK_NS_ANCESTOR)); - rb_define_const(eXMLError, "CHECK_NOT_UTF8", INT2NUM(XML_CHECK_NOT_UTF8)); - rb_define_const(eXMLError, "CHECK_NO_DICT", INT2NUM(XML_CHECK_NO_DICT)); - rb_define_const(eXMLError, "CHECK_NOT_NCNAME", INT2NUM(XML_CHECK_NOT_NCNAME)); - rb_define_const(eXMLError, "CHECK_OUTSIDE_DICT", INT2NUM(XML_CHECK_OUTSIDE_DICT)); - rb_define_const(eXMLError, "CHECK_WRONG_NAME", INT2NUM(XML_CHECK_WRONG_NAME)); -#if LIBXML_VERSION >= 20621 - rb_define_const(eXMLError, "CHECK_NAME_NOT_NULL", INT2NUM(XML_CHECK_NAME_NOT_NULL)); - rb_define_const(eXMLError, "I18N_NO_NAME", INT2NUM(XML_I18N_NO_NAME)); - rb_define_const(eXMLError, "I18N_NO_HANDLER", INT2NUM(XML_I18N_NO_HANDLER)); - rb_define_const(eXMLError, "I18N_EXCESS_HANDLER", INT2NUM(XML_I18N_EXCESS_HANDLER)); - rb_define_const(eXMLError, "I18N_CONV_FAILED", INT2NUM(XML_I18N_CONV_FAILED)); - rb_define_const(eXMLError, "I18N_NO_OUTPUT", INT2NUM(XML_I18N_NO_OUTPUT)); -#endif -} +#include "ruby_libxml.h" + +#include + +VALUE eXMLError; +static ID CALL_METHOD; +static ID ERROR_HANDLER_ID; + +/* + * Document-class: LibXML::XML::Error + * + * The XML::Error class exposes libxml errors as + * standard Ruby exceptions. When appropriate, + * libxml-ruby will raise an exception - for example, + * when parsing a non-well formed xml document. + * + * By default, warnings, errors and fatal errors that + * libxml generates are printed to STDERR via the + * XML::Error::VERBOSE_HANDLER proc. + * + * To disable this output you can install the quiet handler: + * + * XML::Error.set_handler(&XML::Error::QUIET_HANDLER) + * + * Get the current handler: + * + * proc = XML::Error.get_handler + * + * Install your own handler: + * + * XML::Error.set_handler do |error| + * puts error.to_s + * end + * + * Or remove all handlers: + * + * XML::Error.reset_handler + */ + +/* + * call-seq: + * Error.get_error_handler + * + * Returns the proc that will be called when libxml generates + * warning, error or fatal error messages. + */ +static VALUE rxml_error_get_handler(VALUE self) +{ + VALUE block = rb_cvar_get(eXMLError, ERROR_HANDLER_ID); + return block; +} + +VALUE rxml_error_wrap(const xmlError *xerror) +{ + VALUE result = Qnil; + + if (xerror->message) + result = rb_exc_new2(eXMLError, xerror->message); + else + result = rb_class_new_instance(0, NULL, eXMLError); + + rb_iv_set(result, "@domain", INT2NUM(xerror->domain)); + rb_iv_set(result, "@code", INT2NUM(xerror->code)); + rb_iv_set(result, "@level", INT2NUM(xerror->level)); + + if (xerror->file) + rb_iv_set(result, "@file", rb_str_new2(xerror->file)); + + if (xerror->line) + rb_iv_set(result, "@line", INT2NUM(xerror->line)); + + if (xerror->str1) + rb_iv_set(result, "@str1", rb_str_new2(xerror->str1)); + + if (xerror->str2) + rb_iv_set(result, "@str2", rb_str_new2(xerror->str2)); + + if (xerror->str3) + rb_iv_set(result, "@str3", rb_str_new2(xerror->str3)); + + rb_iv_set(result, "@int1", INT2NUM(xerror->int1)); + rb_iv_set(result, "@int2", INT2NUM(xerror->int2)); + + if (xerror->node) + { + /* Returning the original node is too dangerous because its + parent document is never returned to Ruby. So return a + copy of the node, which does not belong to any document, + and can free itself when Ruby calls its free method. Note + we just copy the node, and don't bother with the overhead + of a recursive query. */ + xmlNodePtr xNode = xmlCopyNode((const xmlNodePtr)xerror->node, 2); + VALUE node = rxml_node_wrap(xNode); + rb_iv_set(result, "@node", node); + } + return result; +} + +/* Hook that receives xml error message */ +#if LIBXML_VERSION >= 21200 +static void structuredErrorFunc(void *userData, const xmlError *xerror) +#else +static void structuredErrorFunc(void *userData, xmlErrorPtr xerror) +#endif +{ + VALUE error = rxml_error_wrap(xerror); + + /* Wrap error up as Ruby object and send it off to ruby */ + VALUE block = rxml_error_get_handler(error); + + /* Now call global handler */ + if (block != Qnil) + { + rb_funcall(block, CALL_METHOD, 1, error); + } +} + +static void rxml_set_handler(VALUE self, VALUE block) +{ +#ifdef RB_CVAR_SET_4ARGS + rb_cvar_set(self, ERROR_HANDLER_ID, block, 0); +#else + rb_cvar_set(self, ERROR_HANDLER_ID, block); +#endif + + /* Intercept libxml error handlers */ + xmlSetStructuredErrorFunc(NULL, structuredErrorFunc); +} + +/* + * call-seq: + * Error.set_error_handler {|error| ... } + * + * Registers a block that will be called with an instance of + * XML::Error when libxml generates warning, error or fatal + * error messages. + */ +static VALUE rxml_error_set_handler(VALUE self) +{ + VALUE block; + + if (rb_block_given_p() == Qfalse) + rb_raise(rb_eRuntimeError, "No block given"); + + block = rb_block_proc(); + + /* Embed the block within the Error class to avoid it to be collected. + Previous handler will be overwritten if it exists. */ + rxml_set_handler(self, block); + + return self; +} + +/* + * call-seq: + * Error.reset_error_handler + * + * Removes the current error handler. */ +static VALUE rxml_error_reset_handler(VALUE self) +{ + rxml_set_handler(self, Qnil); + return self; +} + +void rxml_raise(const xmlError *xerror) +{ + if (xerror) + { + /* Wrap error up as Ruby object and send it off to ruby */ + VALUE error = rxml_error_wrap(xerror); + rb_exc_raise(error); + } +} + +void rxml_init_error(void) +{ + CALL_METHOD = rb_intern("call"); + ERROR_HANDLER_ID = rb_intern("@@__error_handler_callback__"); + + /* Error class */ + eXMLError = rb_define_class_under(mXML, "Error", rb_eStandardError); + rb_define_singleton_method(eXMLError, "get_handler", rxml_error_get_handler, 0); + rb_define_singleton_method(eXMLError, "set_handler", rxml_error_set_handler, 0); + rb_define_singleton_method(eXMLError, "reset_handler", rxml_error_reset_handler, 0); + + /* Ruby callback to receive errors - set it to nil by default. */ + rxml_set_handler(eXMLError, Qnil); + + /* Error attributes */ + rb_define_attr(eXMLError, "level", 1, 0); + rb_define_attr(eXMLError, "domain", 1, 0); + rb_define_attr(eXMLError, "code", 1, 0); + rb_define_attr(eXMLError, "file", 1, 0); + rb_define_attr(eXMLError, "line", 1, 0); + rb_define_attr(eXMLError, "str1", 1, 0); + rb_define_attr(eXMLError, "str2", 1, 0); + rb_define_attr(eXMLError, "str3", 1, 0); + rb_define_attr(eXMLError, "int1", 1, 0); + rb_define_attr(eXMLError, "int2", 1, 0); + rb_define_attr(eXMLError, "ctxt", 1, 0); + rb_define_attr(eXMLError, "node", 1, 0); + + /* xml error levels */ + rb_define_const(eXMLError, "NONE", INT2NUM(XML_ERR_NONE)); + rb_define_const(eXMLError, "WARNING", INT2NUM(XML_ERR_WARNING)); + rb_define_const(eXMLError, "ERROR", INT2NUM(XML_ERR_ERROR)); + rb_define_const(eXMLError, "FATAL", INT2NUM(XML_ERR_FATAL)); + + /* xml error domains */ + rb_define_const(eXMLError, "NO_ERROR", INT2NUM(XML_FROM_NONE)); + rb_define_const(eXMLError, "PARSER", INT2NUM(XML_FROM_PARSER)); + rb_define_const(eXMLError, "TREE", INT2NUM(XML_FROM_TREE)); + rb_define_const(eXMLError, "NAMESPACE", INT2NUM(XML_FROM_NAMESPACE)); + rb_define_const(eXMLError, "DTD", INT2NUM(XML_FROM_DTD)); + rb_define_const(eXMLError, "HTML", INT2NUM(XML_FROM_HTML)); + rb_define_const(eXMLError, "MEMORY", INT2NUM(XML_FROM_MEMORY)); + rb_define_const(eXMLError, "OUTPUT", INT2NUM(XML_FROM_OUTPUT)); + rb_define_const(eXMLError, "IO", INT2NUM(XML_FROM_IO)); + rb_define_const(eXMLError, "FTP", INT2NUM(XML_FROM_FTP)); + rb_define_const(eXMLError, "HTTP", INT2NUM(XML_FROM_HTTP)); + rb_define_const(eXMLError, "XINCLUDE", INT2NUM(XML_FROM_XINCLUDE)); + rb_define_const(eXMLError, "XPATH", INT2NUM(XML_FROM_XPATH)); + rb_define_const(eXMLError, "XPOINTER", INT2NUM(XML_FROM_XPOINTER)); + rb_define_const(eXMLError, "REGEXP", INT2NUM(XML_FROM_REGEXP)); + rb_define_const(eXMLError, "DATATYPE", INT2NUM(XML_FROM_DATATYPE)); + rb_define_const(eXMLError, "SCHEMASP", INT2NUM(XML_FROM_SCHEMASP)); + rb_define_const(eXMLError, "SCHEMASV", INT2NUM(XML_FROM_SCHEMASV)); + rb_define_const(eXMLError, "RELAXNGP", INT2NUM(XML_FROM_RELAXNGP)); + rb_define_const(eXMLError, "RELAXNGV", INT2NUM(XML_FROM_RELAXNGV)); + rb_define_const(eXMLError, "CATALOG", INT2NUM(XML_FROM_CATALOG)); + rb_define_const(eXMLError, "C14N", INT2NUM(XML_FROM_C14N)); + rb_define_const(eXMLError, "XSLT", INT2NUM(XML_FROM_XSLT)); + rb_define_const(eXMLError, "VALID", INT2NUM(XML_FROM_VALID)); + rb_define_const(eXMLError, "CHECK", INT2NUM(XML_FROM_CHECK)); + rb_define_const(eXMLError, "WRITER", INT2NUM(XML_FROM_WRITER)); +#if LIBXML_VERSION >= 20621 + rb_define_const(eXMLError, "MODULE", INT2NUM(XML_FROM_MODULE)); +#endif +#if LIBXML_VERSION >= 20632 + rb_define_const(eXMLError, "I18N", INT2NUM(XML_FROM_I18N)); + rb_define_const(eXMLError, "SCHEMATRONV", INT2NUM(XML_FROM_SCHEMATRONV)); +#endif + + /* errors */ + rb_define_const(eXMLError, "OK", INT2NUM(XML_ERR_OK)); + rb_define_const(eXMLError, "INTERNAL_ERROR", INT2NUM(XML_ERR_INTERNAL_ERROR)); + rb_define_const(eXMLError, "NO_MEMORY", INT2NUM(XML_ERR_NO_MEMORY)); + rb_define_const(eXMLError, "DOCUMENT_START", INT2NUM(XML_ERR_DOCUMENT_START)); + rb_define_const(eXMLError, "DOCUMENT_EMPTY", INT2NUM(XML_ERR_DOCUMENT_EMPTY)); + rb_define_const(eXMLError, "DOCUMENT_END", INT2NUM(XML_ERR_DOCUMENT_END)); + rb_define_const(eXMLError, "INVALID_HEX_CHARREF", INT2NUM(XML_ERR_INVALID_HEX_CHARREF)); + rb_define_const(eXMLError, "INVALID_DEC_CHARREF", INT2NUM(XML_ERR_INVALID_DEC_CHARREF)); + rb_define_const(eXMLError, "INVALID_CHARREF", INT2NUM(XML_ERR_INVALID_CHARREF)); + rb_define_const(eXMLError, "INVALID_CHAR", INT2NUM(XML_ERR_INVALID_CHAR)); + rb_define_const(eXMLError, "CHARREF_AT_EOF", INT2NUM(XML_ERR_CHARREF_AT_EOF)); + rb_define_const(eXMLError, "CHARREF_IN_PROLOG", INT2NUM(XML_ERR_CHARREF_IN_PROLOG)); + rb_define_const(eXMLError, "CHARREF_IN_EPILOG", INT2NUM(XML_ERR_CHARREF_IN_EPILOG)); + rb_define_const(eXMLError, "CHARREF_IN_DTD", INT2NUM(XML_ERR_CHARREF_IN_DTD)); + rb_define_const(eXMLError, "ENTITYREF_AT_EOF", INT2NUM(XML_ERR_ENTITYREF_AT_EOF)); + rb_define_const(eXMLError, "ENTITYREF_IN_PROLOG", INT2NUM(XML_ERR_ENTITYREF_IN_PROLOG)); + rb_define_const(eXMLError, "ENTITYREF_IN_EPILOG", INT2NUM(XML_ERR_ENTITYREF_IN_EPILOG)); + rb_define_const(eXMLError, "ENTITYREF_IN_DTD", INT2NUM(XML_ERR_ENTITYREF_IN_DTD)); + rb_define_const(eXMLError, "PEREF_AT_EOF", INT2NUM(XML_ERR_PEREF_AT_EOF)); + rb_define_const(eXMLError, "PEREF_IN_PROLOG", INT2NUM(XML_ERR_PEREF_IN_PROLOG)); + rb_define_const(eXMLError, "PEREF_IN_EPILOG",INT2NUM(XML_ERR_PEREF_IN_EPILOG)); + rb_define_const(eXMLError, "PEREF_IN_INT_SUBSET", INT2NUM(XML_ERR_PEREF_IN_INT_SUBSET)); + rb_define_const(eXMLError, "ENTITYREF_NO_NAME", INT2NUM(XML_ERR_ENTITYREF_NO_NAME)); + rb_define_const(eXMLError, "ENTITYREF_SEMICOL_MISSING", INT2NUM(XML_ERR_ENTITYREF_SEMICOL_MISSING)); + rb_define_const(eXMLError, "PEREF_NO_NAME", INT2NUM(XML_ERR_PEREF_NO_NAME)); + rb_define_const(eXMLError, "PEREF_SEMICOL_MISSING", INT2NUM(XML_ERR_PEREF_SEMICOL_MISSING)); + rb_define_const(eXMLError, "UNDECLARED_ENTITY", INT2NUM(XML_ERR_UNDECLARED_ENTITY)); + rb_define_const(eXMLError, "XML_WAR_UNDECLARED_ENTITY", INT2NUM(XML_WAR_UNDECLARED_ENTITY)); + rb_define_const(eXMLError, "UNPARSED_ENTITY", INT2NUM(XML_ERR_UNPARSED_ENTITY)); + rb_define_const(eXMLError, "ENTITY_IS_EXTERNAL", INT2NUM(XML_ERR_ENTITY_IS_EXTERNAL)); + rb_define_const(eXMLError, "ENTITY_IS_PARAMETER", INT2NUM(XML_ERR_ENTITY_IS_PARAMETER)); + rb_define_const(eXMLError, "UNKNOWN_ENCODING", INT2NUM(XML_ERR_UNKNOWN_ENCODING)); + rb_define_const(eXMLError, "UNSUPPORTED_ENCODING", INT2NUM(XML_ERR_UNSUPPORTED_ENCODING)); + rb_define_const(eXMLError, "STRING_NOT_STARTED", INT2NUM(XML_ERR_STRING_NOT_STARTED)); + rb_define_const(eXMLError, "STRING_NOT_CLOSED", INT2NUM(XML_ERR_STRING_NOT_CLOSED)); + rb_define_const(eXMLError, "NS_DECL_ERROR", INT2NUM(XML_ERR_NS_DECL_ERROR)); + rb_define_const(eXMLError, "ENTITY_NOT_STARTED", INT2NUM(XML_ERR_ENTITY_NOT_STARTED)); + rb_define_const(eXMLError, "ENTITY_NOT_FINISHED", INT2NUM(XML_ERR_ENTITY_NOT_FINISHED)); + rb_define_const(eXMLError, "LT_IN_ATTRIBUTE", INT2NUM(XML_ERR_LT_IN_ATTRIBUTE)); + rb_define_const(eXMLError, "ATTRIBUTE_NOT_STARTED", INT2NUM(XML_ERR_ATTRIBUTE_NOT_STARTED)); + rb_define_const(eXMLError, "ATTRIBUTE_NOT_FINISHED", INT2NUM(XML_ERR_ATTRIBUTE_NOT_FINISHED)); + rb_define_const(eXMLError, "ATTRIBUTE_WITHOUT_VALUE", INT2NUM(XML_ERR_ATTRIBUTE_WITHOUT_VALUE)); + rb_define_const(eXMLError, "ATTRIBUTE_REDEFINED", INT2NUM(XML_ERR_ATTRIBUTE_REDEFINED)); + rb_define_const(eXMLError, "LITERAL_NOT_STARTED", INT2NUM(XML_ERR_LITERAL_NOT_STARTED)); + rb_define_const(eXMLError, "LITERAL_NOT_FINISHED", INT2NUM(XML_ERR_LITERAL_NOT_FINISHED)); + rb_define_const(eXMLError, "COMMENT_NOT_FINISHED", INT2NUM(XML_ERR_COMMENT_NOT_FINISHED)); + rb_define_const(eXMLError, "PI_NOT_STARTED", INT2NUM(XML_ERR_PI_NOT_STARTED)); + rb_define_const(eXMLError, "PI_NOT_FINISHED", INT2NUM(XML_ERR_PI_NOT_FINISHED)); + rb_define_const(eXMLError, "NOTATION_NOT_STARTED", INT2NUM(XML_ERR_NOTATION_NOT_STARTED)); + rb_define_const(eXMLError, "NOTATION_NOT_FINISHED", INT2NUM(XML_ERR_NOTATION_NOT_FINISHED)); + rb_define_const(eXMLError, "ATTLIST_NOT_STARTED", INT2NUM(XML_ERR_ATTLIST_NOT_STARTED)); + rb_define_const(eXMLError, "ATTLIST_NOT_FINISHED", INT2NUM(XML_ERR_ATTLIST_NOT_FINISHED)); + rb_define_const(eXMLError, "MIXED_NOT_STARTED", INT2NUM(XML_ERR_MIXED_NOT_STARTED)); + rb_define_const(eXMLError, "MIXED_NOT_FINISHED", INT2NUM(XML_ERR_MIXED_NOT_FINISHED)); + rb_define_const(eXMLError, "ELEMCONTENT_NOT_STARTED", INT2NUM(XML_ERR_ELEMCONTENT_NOT_STARTED)); + rb_define_const(eXMLError, "ELEMCONTENT_NOT_FINISHED", INT2NUM(XML_ERR_ELEMCONTENT_NOT_FINISHED)); + rb_define_const(eXMLError, "XMLDECL_NOT_STARTED", INT2NUM(XML_ERR_XMLDECL_NOT_STARTED)); + rb_define_const(eXMLError, "XMLDECL_NOT_FINISHED", INT2NUM(XML_ERR_XMLDECL_NOT_FINISHED)); + rb_define_const(eXMLError, "CONDSEC_NOT_STARTED", INT2NUM(XML_ERR_CONDSEC_NOT_STARTED)); + rb_define_const(eXMLError, "CONDSEC_NOT_FINISHED", INT2NUM(XML_ERR_CONDSEC_NOT_FINISHED)); + rb_define_const(eXMLError, "EXT_SUBSET_NOT_FINISHED", INT2NUM(XML_ERR_EXT_SUBSET_NOT_FINISHED)); + rb_define_const(eXMLError, "DOCTYPE_NOT_FINISHED", INT2NUM(XML_ERR_DOCTYPE_NOT_FINISHED)); + rb_define_const(eXMLError, "MISPLACED_CDATA_END", INT2NUM(XML_ERR_MISPLACED_CDATA_END)); + rb_define_const(eXMLError, "CDATA_NOT_FINISHED", INT2NUM(XML_ERR_CDATA_NOT_FINISHED)); + rb_define_const(eXMLError, "RESERVED_XML_NAME", INT2NUM(XML_ERR_RESERVED_XML_NAME)); + rb_define_const(eXMLError, "SPACE_REQUIRED", INT2NUM(XML_ERR_SPACE_REQUIRED)); + rb_define_const(eXMLError, "SEPARATOR_REQUIRED", INT2NUM(XML_ERR_SEPARATOR_REQUIRED)); + rb_define_const(eXMLError, "NMTOKEN_REQUIRED", INT2NUM(XML_ERR_NMTOKEN_REQUIRED)); + rb_define_const(eXMLError, "NAME_REQUIRED", INT2NUM(XML_ERR_NAME_REQUIRED)); + rb_define_const(eXMLError, "PCDATA_REQUIRED", INT2NUM(XML_ERR_PCDATA_REQUIRED)); + rb_define_const(eXMLError, "URI_REQUIRED", INT2NUM(XML_ERR_URI_REQUIRED)); + rb_define_const(eXMLError, "PUBID_REQUIRED", INT2NUM(XML_ERR_PUBID_REQUIRED)); + rb_define_const(eXMLError, "LT_REQUIRED", INT2NUM(XML_ERR_LT_REQUIRED)); + rb_define_const(eXMLError, "GT_REQUIRED", INT2NUM(XML_ERR_GT_REQUIRED)); + rb_define_const(eXMLError, "LTSLASH_REQUIRED", INT2NUM(XML_ERR_LTSLASH_REQUIRED)); + rb_define_const(eXMLError, "EQUAL_REQUIRED", INT2NUM(XML_ERR_EQUAL_REQUIRED)); + rb_define_const(eXMLError, "TAG_NAME_MISMATCH", INT2NUM(XML_ERR_TAG_NAME_MISMATCH)); + rb_define_const(eXMLError, "TAG_NOT_FINISHED", INT2NUM(XML_ERR_TAG_NOT_FINISHED)); + rb_define_const(eXMLError, "STANDALONE_VALUE", INT2NUM(XML_ERR_STANDALONE_VALUE)); + rb_define_const(eXMLError, "ENCODING_NAME", INT2NUM(XML_ERR_ENCODING_NAME)); + rb_define_const(eXMLError, "HYPHEN_IN_COMMENT", INT2NUM(XML_ERR_HYPHEN_IN_COMMENT)); + rb_define_const(eXMLError, "INVALID_ENCODING", INT2NUM(XML_ERR_INVALID_ENCODING)); + rb_define_const(eXMLError, "EXT_ENTITY_STANDALONE", INT2NUM(XML_ERR_EXT_ENTITY_STANDALONE)); + rb_define_const(eXMLError, "CONDSEC_INVALID", INT2NUM(XML_ERR_CONDSEC_INVALID)); + rb_define_const(eXMLError, "VALUE_REQUIRED", INT2NUM(XML_ERR_VALUE_REQUIRED)); + rb_define_const(eXMLError, "NOT_WELL_BALANCED", INT2NUM(XML_ERR_NOT_WELL_BALANCED)); + rb_define_const(eXMLError, "EXTRA_CONTENT", INT2NUM(XML_ERR_EXTRA_CONTENT)); + rb_define_const(eXMLError, "ENTITY_CHAR_ERROR", INT2NUM(XML_ERR_ENTITY_CHAR_ERROR)); + rb_define_const(eXMLError, "ENTITY_PE_INTERNAL", INT2NUM(XML_ERR_ENTITY_PE_INTERNAL)); + rb_define_const(eXMLError, "ENTITY_LOOP", INT2NUM(XML_ERR_ENTITY_LOOP)); + rb_define_const(eXMLError, "ENTITY_BOUNDARY", INT2NUM(XML_ERR_ENTITY_BOUNDARY)); + rb_define_const(eXMLError, "INVALID_URI", INT2NUM(XML_ERR_INVALID_URI)); + rb_define_const(eXMLError, "URI_FRAGMENT", INT2NUM(XML_ERR_URI_FRAGMENT)); + rb_define_const(eXMLError, "XML_WAR_CATALOG_PI", INT2NUM(XML_WAR_CATALOG_PI)); + rb_define_const(eXMLError, "NO_DTD", INT2NUM(XML_ERR_NO_DTD)); + rb_define_const(eXMLError, "CONDSEC_INVALID_KEYWORD", INT2NUM(XML_ERR_CONDSEC_INVALID_KEYWORD)); + rb_define_const(eXMLError, "VERSION_MISSING", INT2NUM(XML_ERR_VERSION_MISSING)); + rb_define_const(eXMLError, "XML_WAR_UNKNOWN_VERSION", INT2NUM(XML_WAR_UNKNOWN_VERSION)); + rb_define_const(eXMLError, "XML_WAR_LANG_VALUE", INT2NUM(XML_WAR_LANG_VALUE)); + rb_define_const(eXMLError, "XML_WAR_NS_URI", INT2NUM(XML_WAR_NS_URI)); + rb_define_const(eXMLError, "XML_WAR_NS_URI_RELATIVE", INT2NUM(XML_WAR_NS_URI_RELATIVE)); + rb_define_const(eXMLError, "MISSING_ENCODING", INT2NUM(XML_ERR_MISSING_ENCODING)); +#if LIBXML_VERSION >= 20620 + rb_define_const(eXMLError, "XML_WAR_SPACE_VALUE", INT2NUM(XML_WAR_SPACE_VALUE)); + rb_define_const(eXMLError, "NOT_STANDALONE", INT2NUM(XML_ERR_NOT_STANDALONE)); + rb_define_const(eXMLError, "ENTITY_PROCESSING", INT2NUM(XML_ERR_ENTITY_PROCESSING)); + rb_define_const(eXMLError, "NOTATION_PROCESSING", INT2NUM(XML_ERR_NOTATION_PROCESSING)); + rb_define_const(eXMLError, "WAR_NS_COLUMN", INT2NUM(XML_WAR_NS_COLUMN)); + rb_define_const(eXMLError, "WAR_ENTITY_REDEFINED", INT2NUM(XML_WAR_ENTITY_REDEFINED)); +#endif + rb_define_const(eXMLError, "NS_ERR_XML_NAMESPACE", INT2NUM(XML_NS_ERR_XML_NAMESPACE)); + rb_define_const(eXMLError, "NS_ERR_UNDEFINED_NAMESPACE", INT2NUM(XML_NS_ERR_UNDEFINED_NAMESPACE)); + rb_define_const(eXMLError, "NS_ERR_QNAME", INT2NUM(XML_NS_ERR_QNAME)); + rb_define_const(eXMLError, "NS_ERR_ATTRIBUTE_REDEFINED", INT2NUM(XML_NS_ERR_ATTRIBUTE_REDEFINED)); +#if LIBXML_VERSION >= 20620 + rb_define_const(eXMLError, "NS_ERR_EMPTY", INT2NUM(XML_NS_ERR_EMPTY)); +#endif +#if LIBXML_VERSION >= 20700 + rb_define_const(eXMLError, "NS_ERR_COLON", INT2NUM(XML_NS_ERR_COLON)); +#endif + rb_define_const(eXMLError, "DTD_ATTRIBUTE_DEFAULT", INT2NUM(XML_DTD_ATTRIBUTE_DEFAULT)); + rb_define_const(eXMLError, "DTD_ATTRIBUTE_REDEFINED", INT2NUM(XML_DTD_ATTRIBUTE_REDEFINED)); + rb_define_const(eXMLError, "DTD_ATTRIBUTE_VALUE", INT2NUM(XML_DTD_ATTRIBUTE_VALUE)); + rb_define_const(eXMLError, "DTD_CONTENT_ERROR", INT2NUM(XML_DTD_CONTENT_ERROR)); + rb_define_const(eXMLError, "DTD_CONTENT_MODEL", INT2NUM(XML_DTD_CONTENT_MODEL)); + rb_define_const(eXMLError, "DTD_CONTENT_NOT_DETERMINIST", INT2NUM(XML_DTD_CONTENT_NOT_DETERMINIST)); + rb_define_const(eXMLError, "DTD_DIFFERENT_PREFIX", INT2NUM(XML_DTD_DIFFERENT_PREFIX)); + rb_define_const(eXMLError, "DTD_ELEM_DEFAULT_NAMESPACE", INT2NUM(XML_DTD_ELEM_DEFAULT_NAMESPACE)); + rb_define_const(eXMLError, "DTD_ELEM_NAMESPACE", INT2NUM(XML_DTD_ELEM_NAMESPACE)); + rb_define_const(eXMLError, "DTD_ELEM_REDEFINED", INT2NUM(XML_DTD_ELEM_REDEFINED)); + rb_define_const(eXMLError, "DTD_EMPTY_NOTATION", INT2NUM(XML_DTD_EMPTY_NOTATION)); + rb_define_const(eXMLError, "DTD_ENTITY_TYPE", INT2NUM(XML_DTD_ENTITY_TYPE)); + rb_define_const(eXMLError, "DTD_ID_FIXED", INT2NUM(XML_DTD_ID_FIXED)); + rb_define_const(eXMLError, "DTD_ID_REDEFINED", INT2NUM(XML_DTD_ID_REDEFINED)); + rb_define_const(eXMLError, "DTD_ID_SUBSET", INT2NUM(XML_DTD_ID_SUBSET)); + rb_define_const(eXMLError, "DTD_INVALID_CHILD", INT2NUM(XML_DTD_INVALID_CHILD)); + rb_define_const(eXMLError, "DTD_INVALID_DEFAULT", INT2NUM(XML_DTD_INVALID_DEFAULT)); + rb_define_const(eXMLError, "DTD_LOAD_ERROR", INT2NUM(XML_DTD_LOAD_ERROR)); + rb_define_const(eXMLError, "DTD_MISSING_ATTRIBUTE", INT2NUM(XML_DTD_MISSING_ATTRIBUTE)); + rb_define_const(eXMLError, "DTD_MIXED_CORRUPT", INT2NUM(XML_DTD_MIXED_CORRUPT)); + rb_define_const(eXMLError, "DTD_MULTIPLE_ID", INT2NUM(XML_DTD_MULTIPLE_ID)); + rb_define_const(eXMLError, "DTD_NO_DOC", INT2NUM(XML_DTD_NO_DOC)); + rb_define_const(eXMLError, "DTD_NO_DTD", INT2NUM(XML_DTD_NO_DTD)); + rb_define_const(eXMLError, "DTD_NO_ELEM_NAME", INT2NUM(XML_DTD_NO_ELEM_NAME)); + rb_define_const(eXMLError, "DTD_NO_PREFIX", INT2NUM(XML_DTD_NO_PREFIX)); + rb_define_const(eXMLError, "DTD_NO_ROOT", INT2NUM(XML_DTD_NO_ROOT)); + rb_define_const(eXMLError, "DTD_NOTATION_REDEFINED", INT2NUM(XML_DTD_NOTATION_REDEFINED)); + rb_define_const(eXMLError, "DTD_NOTATION_VALUE", INT2NUM(XML_DTD_NOTATION_VALUE)); + rb_define_const(eXMLError, "DTD_NOT_EMPTY", INT2NUM(XML_DTD_NOT_EMPTY)); + rb_define_const(eXMLError, "DTD_NOT_PCDATA", INT2NUM(XML_DTD_NOT_PCDATA)); + rb_define_const(eXMLError, "DTD_NOT_STANDALONE", INT2NUM(XML_DTD_NOT_STANDALONE)); + rb_define_const(eXMLError, "DTD_ROOT_NAME", INT2NUM(XML_DTD_ROOT_NAME)); + rb_define_const(eXMLError, "DTD_STANDALONE_WHITE_SPACE", INT2NUM(XML_DTD_STANDALONE_WHITE_SPACE)); + rb_define_const(eXMLError, "DTD_UNKNOWN_ATTRIBUTE", INT2NUM(XML_DTD_UNKNOWN_ATTRIBUTE)); + rb_define_const(eXMLError, "DTD_UNKNOWN_ELEM", INT2NUM(XML_DTD_UNKNOWN_ELEM)); + rb_define_const(eXMLError, "DTD_UNKNOWN_ENTITY", INT2NUM(XML_DTD_UNKNOWN_ENTITY)); + rb_define_const(eXMLError, "DTD_UNKNOWN_ID", INT2NUM(XML_DTD_UNKNOWN_ID)); + rb_define_const(eXMLError, "DTD_UNKNOWN_NOTATION", INT2NUM(XML_DTD_UNKNOWN_NOTATION)); + rb_define_const(eXMLError, "DTD_STANDALONE_DEFAULTED", INT2NUM(XML_DTD_STANDALONE_DEFAULTED)); + rb_define_const(eXMLError, "DTD_XMLID_VALUE", INT2NUM(XML_DTD_XMLID_VALUE)); + rb_define_const(eXMLError, "DTD_XMLID_TYPE", INT2NUM(XML_DTD_XMLID_TYPE)); + rb_define_const(eXMLError, "HTML_STRUCURE_ERROR", INT2NUM(XML_HTML_STRUCURE_ERROR)); + rb_define_const(eXMLError, "HTML_UNKNOWN_TAG", INT2NUM(XML_HTML_UNKNOWN_TAG)); + rb_define_const(eXMLError, "RNGP_ANYNAME_ATTR_ANCESTOR", INT2NUM(XML_RNGP_ANYNAME_ATTR_ANCESTOR)); + rb_define_const(eXMLError, "RNGP_ATTR_CONFLICT", INT2NUM(XML_RNGP_ATTR_CONFLICT)); + rb_define_const(eXMLError, "RNGP_ATTRIBUTE_CHILDREN", INT2NUM(XML_RNGP_ATTRIBUTE_CHILDREN)); + rb_define_const(eXMLError, "RNGP_ATTRIBUTE_CONTENT", INT2NUM(XML_RNGP_ATTRIBUTE_CONTENT)); + rb_define_const(eXMLError, "RNGP_ATTRIBUTE_EMPTY", INT2NUM(XML_RNGP_ATTRIBUTE_EMPTY)); + rb_define_const(eXMLError, "RNGP_ATTRIBUTE_NOOP", INT2NUM(XML_RNGP_ATTRIBUTE_NOOP)); + rb_define_const(eXMLError, "RNGP_CHOICE_CONTENT", INT2NUM(XML_RNGP_CHOICE_CONTENT)); + rb_define_const(eXMLError, "RNGP_CHOICE_EMPTY", INT2NUM(XML_RNGP_CHOICE_EMPTY)); + rb_define_const(eXMLError, "RNGP_CREATE_FAILURE", INT2NUM(XML_RNGP_CREATE_FAILURE)); + rb_define_const(eXMLError, "RNGP_DATA_CONTENT", INT2NUM(XML_RNGP_DATA_CONTENT)); + rb_define_const(eXMLError, "RNGP_DEF_CHOICE_AND_INTERLEAVE", INT2NUM(XML_RNGP_DEF_CHOICE_AND_INTERLEAVE)); + rb_define_const(eXMLError, "RNGP_DEFINE_CREATE_FAILED", INT2NUM(XML_RNGP_DEFINE_CREATE_FAILED)); + rb_define_const(eXMLError, "RNGP_DEFINE_EMPTY", INT2NUM(XML_RNGP_DEFINE_EMPTY)); + rb_define_const(eXMLError, "RNGP_DEFINE_MISSING", INT2NUM(XML_RNGP_DEFINE_MISSING)); + rb_define_const(eXMLError, "RNGP_DEFINE_NAME_MISSING", INT2NUM(XML_RNGP_DEFINE_NAME_MISSING)); + rb_define_const(eXMLError, "RNGP_ELEM_CONTENT_EMPTY", INT2NUM(XML_RNGP_ELEM_CONTENT_EMPTY)); + rb_define_const(eXMLError, "RNGP_ELEM_CONTENT_ERROR", INT2NUM(XML_RNGP_ELEM_CONTENT_ERROR)); + rb_define_const(eXMLError, "RNGP_ELEMENT_EMPTY", INT2NUM(XML_RNGP_ELEMENT_EMPTY)); + rb_define_const(eXMLError, "RNGP_ELEMENT_CONTENT", INT2NUM(XML_RNGP_ELEMENT_CONTENT)); + rb_define_const(eXMLError, "RNGP_ELEMENT_NAME", INT2NUM(XML_RNGP_ELEMENT_NAME)); + rb_define_const(eXMLError, "RNGP_ELEMENT_NO_CONTENT", INT2NUM(XML_RNGP_ELEMENT_NO_CONTENT)); + rb_define_const(eXMLError, "RNGP_ELEM_TEXT_CONFLICT", INT2NUM(XML_RNGP_ELEM_TEXT_CONFLICT)); + rb_define_const(eXMLError, "RNGP_EMPTY", INT2NUM(XML_RNGP_EMPTY)); + rb_define_const(eXMLError, "RNGP_EMPTY_CONSTRUCT", INT2NUM(XML_RNGP_EMPTY_CONSTRUCT)); + rb_define_const(eXMLError, "RNGP_EMPTY_CONTENT", INT2NUM(XML_RNGP_EMPTY_CONTENT)); + rb_define_const(eXMLError, "RNGP_EMPTY_NOT_EMPTY", INT2NUM(XML_RNGP_EMPTY_NOT_EMPTY)); + rb_define_const(eXMLError, "RNGP_ERROR_TYPE_LIB", INT2NUM(XML_RNGP_ERROR_TYPE_LIB)); + rb_define_const(eXMLError, "RNGP_EXCEPT_EMPTY", INT2NUM(XML_RNGP_EXCEPT_EMPTY)); + rb_define_const(eXMLError, "RNGP_EXCEPT_MISSING", INT2NUM(XML_RNGP_EXCEPT_MISSING)); + rb_define_const(eXMLError, "RNGP_EXCEPT_MULTIPLE", INT2NUM(XML_RNGP_EXCEPT_MULTIPLE)); + rb_define_const(eXMLError, "RNGP_EXCEPT_NO_CONTENT", INT2NUM(XML_RNGP_EXCEPT_NO_CONTENT)); + rb_define_const(eXMLError, "RNGP_EXTERNALREF_EMTPY", INT2NUM(XML_RNGP_EXTERNALREF_EMTPY)); + rb_define_const(eXMLError, "RNGP_EXTERNAL_REF_FAILURE", INT2NUM(XML_RNGP_EXTERNAL_REF_FAILURE)); + rb_define_const(eXMLError, "RNGP_EXTERNALREF_RECURSE", INT2NUM(XML_RNGP_EXTERNALREF_RECURSE)); + rb_define_const(eXMLError, "RNGP_FORBIDDEN_ATTRIBUTE", INT2NUM(XML_RNGP_FORBIDDEN_ATTRIBUTE)); + rb_define_const(eXMLError, "RNGP_FOREIGN_ELEMENT", INT2NUM(XML_RNGP_FOREIGN_ELEMENT)); + rb_define_const(eXMLError, "RNGP_GRAMMAR_CONTENT", INT2NUM(XML_RNGP_GRAMMAR_CONTENT)); + rb_define_const(eXMLError, "RNGP_GRAMMAR_EMPTY", INT2NUM(XML_RNGP_GRAMMAR_EMPTY)); + rb_define_const(eXMLError, "RNGP_GRAMMAR_MISSING", INT2NUM(XML_RNGP_GRAMMAR_MISSING)); + rb_define_const(eXMLError, "RNGP_GRAMMAR_NO_START", INT2NUM(XML_RNGP_GRAMMAR_NO_START)); + rb_define_const(eXMLError, "RNGP_GROUP_ATTR_CONFLICT", INT2NUM(XML_RNGP_GROUP_ATTR_CONFLICT)); + rb_define_const(eXMLError, "RNGP_HREF_ERROR", INT2NUM(XML_RNGP_HREF_ERROR)); + rb_define_const(eXMLError, "RNGP_INCLUDE_EMPTY", INT2NUM(XML_RNGP_INCLUDE_EMPTY)); + rb_define_const(eXMLError, "RNGP_INCLUDE_FAILURE", INT2NUM(XML_RNGP_INCLUDE_FAILURE)); + rb_define_const(eXMLError, "RNGP_INCLUDE_RECURSE", INT2NUM(XML_RNGP_INCLUDE_RECURSE)); + rb_define_const(eXMLError, "RNGP_INTERLEAVE_ADD", INT2NUM(XML_RNGP_INTERLEAVE_ADD)); + rb_define_const(eXMLError, "RNGP_INTERLEAVE_CREATE_FAILED", INT2NUM(XML_RNGP_INTERLEAVE_CREATE_FAILED)); + rb_define_const(eXMLError, "RNGP_INTERLEAVE_EMPTY", INT2NUM(XML_RNGP_INTERLEAVE_EMPTY)); + rb_define_const(eXMLError, "RNGP_INTERLEAVE_NO_CONTENT", INT2NUM(XML_RNGP_INTERLEAVE_NO_CONTENT)); + rb_define_const(eXMLError, "RNGP_INVALID_DEFINE_NAME", INT2NUM(XML_RNGP_INVALID_DEFINE_NAME)); + rb_define_const(eXMLError, "RNGP_INVALID_URI", INT2NUM(XML_RNGP_INVALID_URI)); + rb_define_const(eXMLError, "RNGP_INVALID_VALUE", INT2NUM(XML_RNGP_INVALID_VALUE)); + rb_define_const(eXMLError, "RNGP_MISSING_HREF", INT2NUM(XML_RNGP_MISSING_HREF)); + rb_define_const(eXMLError, "RNGP_NAME_MISSING", INT2NUM(XML_RNGP_NAME_MISSING)); + rb_define_const(eXMLError, "RNGP_NEED_COMBINE", INT2NUM(XML_RNGP_NEED_COMBINE)); + rb_define_const(eXMLError, "RNGP_NOTALLOWED_NOT_EMPTY", INT2NUM(XML_RNGP_NOTALLOWED_NOT_EMPTY)); + rb_define_const(eXMLError, "RNGP_NSNAME_ATTR_ANCESTOR", INT2NUM(XML_RNGP_NSNAME_ATTR_ANCESTOR)); + rb_define_const(eXMLError, "RNGP_NSNAME_NO_NS", INT2NUM(XML_RNGP_NSNAME_NO_NS)); + rb_define_const(eXMLError, "RNGP_PARAM_FORBIDDEN", INT2NUM(XML_RNGP_PARAM_FORBIDDEN)); + rb_define_const(eXMLError, "RNGP_PARAM_NAME_MISSING", INT2NUM(XML_RNGP_PARAM_NAME_MISSING)); + rb_define_const(eXMLError, "RNGP_PARENTREF_CREATE_FAILED", INT2NUM(XML_RNGP_PARENTREF_CREATE_FAILED)); + rb_define_const(eXMLError, "RNGP_PARENTREF_NAME_INVALID", INT2NUM(XML_RNGP_PARENTREF_NAME_INVALID)); + rb_define_const(eXMLError, "RNGP_PARENTREF_NO_NAME", INT2NUM(XML_RNGP_PARENTREF_NO_NAME)); + rb_define_const(eXMLError, "RNGP_PARENTREF_NO_PARENT", INT2NUM(XML_RNGP_PARENTREF_NO_PARENT)); + rb_define_const(eXMLError, "RNGP_PARENTREF_NOT_EMPTY", INT2NUM(XML_RNGP_PARENTREF_NOT_EMPTY)); + rb_define_const(eXMLError, "RNGP_PARSE_ERROR", INT2NUM(XML_RNGP_PARSE_ERROR)); + rb_define_const(eXMLError, "RNGP_PAT_ANYNAME_EXCEPT_ANYNAME", INT2NUM(XML_RNGP_PAT_ANYNAME_EXCEPT_ANYNAME)); + rb_define_const(eXMLError, "RNGP_PAT_ATTR_ATTR", INT2NUM(XML_RNGP_PAT_ATTR_ATTR)); + rb_define_const(eXMLError, "RNGP_PAT_ATTR_ELEM", INT2NUM(XML_RNGP_PAT_ATTR_ELEM)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_ATTR", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_ATTR)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_ELEM", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_ELEM)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_EMPTY", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_EMPTY)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_GROUP", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_GROUP)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_INTERLEAVE", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_LIST", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_LIST)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_ONEMORE", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_ONEMORE)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_REF", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_REF)); + rb_define_const(eXMLError, "RNGP_PAT_DATA_EXCEPT_TEXT", INT2NUM(XML_RNGP_PAT_DATA_EXCEPT_TEXT)); + rb_define_const(eXMLError, "RNGP_PAT_LIST_ATTR", INT2NUM(XML_RNGP_PAT_LIST_ATTR)); + rb_define_const(eXMLError, "RNGP_PAT_LIST_ELEM", INT2NUM(XML_RNGP_PAT_LIST_ELEM)); + rb_define_const(eXMLError, "RNGP_PAT_LIST_INTERLEAVE", INT2NUM(XML_RNGP_PAT_LIST_INTERLEAVE)); + rb_define_const(eXMLError, "RNGP_PAT_LIST_LIST", INT2NUM(XML_RNGP_PAT_LIST_LIST)); + rb_define_const(eXMLError, "RNGP_PAT_LIST_REF", INT2NUM(XML_RNGP_PAT_LIST_REF)); + rb_define_const(eXMLError, "RNGP_PAT_LIST_TEXT", INT2NUM(XML_RNGP_PAT_LIST_TEXT)); + rb_define_const(eXMLError, "RNGP_PAT_NSNAME_EXCEPT_ANYNAME", INT2NUM(XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME)); + rb_define_const(eXMLError, "RNGP_PAT_NSNAME_EXCEPT_NSNAME", INT2NUM(XML_RNGP_PAT_NSNAME_EXCEPT_NSNAME)); + rb_define_const(eXMLError, "RNGP_PAT_ONEMORE_GROUP_ATTR", INT2NUM(XML_RNGP_PAT_ONEMORE_GROUP_ATTR)); + rb_define_const(eXMLError, "RNGP_PAT_ONEMORE_INTERLEAVE_ATTR", INT2NUM(XML_RNGP_PAT_ONEMORE_INTERLEAVE_ATTR)); + rb_define_const(eXMLError, "RNGP_PAT_START_ATTR", INT2NUM(XML_RNGP_PAT_START_ATTR)); + rb_define_const(eXMLError, "RNGP_PAT_START_DATA", INT2NUM(XML_RNGP_PAT_START_DATA)); + rb_define_const(eXMLError, "RNGP_PAT_START_EMPTY", INT2NUM(XML_RNGP_PAT_START_EMPTY)); + rb_define_const(eXMLError, "RNGP_PAT_START_GROUP", INT2NUM(XML_RNGP_PAT_START_GROUP)); + rb_define_const(eXMLError, "RNGP_PAT_START_INTERLEAVE", INT2NUM(XML_RNGP_PAT_START_INTERLEAVE)); + rb_define_const(eXMLError, "RNGP_PAT_START_LIST", INT2NUM(XML_RNGP_PAT_START_LIST)); + rb_define_const(eXMLError, "RNGP_PAT_START_ONEMORE", INT2NUM(XML_RNGP_PAT_START_ONEMORE)); + rb_define_const(eXMLError, "RNGP_PAT_START_TEXT", INT2NUM(XML_RNGP_PAT_START_TEXT)); + rb_define_const(eXMLError, "RNGP_PAT_START_VALUE", INT2NUM(XML_RNGP_PAT_START_VALUE)); + rb_define_const(eXMLError, "RNGP_PREFIX_UNDEFINED", INT2NUM(XML_RNGP_PREFIX_UNDEFINED)); + rb_define_const(eXMLError, "RNGP_REF_CREATE_FAILED", INT2NUM(XML_RNGP_REF_CREATE_FAILED)); + rb_define_const(eXMLError, "RNGP_REF_CYCLE", INT2NUM(XML_RNGP_REF_CYCLE)); + rb_define_const(eXMLError, "RNGP_REF_NAME_INVALID", INT2NUM(XML_RNGP_REF_NAME_INVALID)); + rb_define_const(eXMLError, "RNGP_REF_NO_DEF", INT2NUM(XML_RNGP_REF_NO_DEF)); + rb_define_const(eXMLError, "RNGP_REF_NO_NAME", INT2NUM(XML_RNGP_REF_NO_NAME)); + rb_define_const(eXMLError, "RNGP_REF_NOT_EMPTY", INT2NUM(XML_RNGP_REF_NOT_EMPTY)); + rb_define_const(eXMLError, "RNGP_START_CHOICE_AND_INTERLEAVE", INT2NUM(XML_RNGP_START_CHOICE_AND_INTERLEAVE)); + rb_define_const(eXMLError, "RNGP_START_CONTENT", INT2NUM(XML_RNGP_START_CONTENT)); + rb_define_const(eXMLError, "RNGP_START_EMPTY", INT2NUM(XML_RNGP_START_EMPTY)); + rb_define_const(eXMLError, "RNGP_START_MISSING", INT2NUM(XML_RNGP_START_MISSING)); + rb_define_const(eXMLError, "RNGP_TEXT_EXPECTED", INT2NUM(XML_RNGP_TEXT_EXPECTED)); + rb_define_const(eXMLError, "RNGP_TEXT_HAS_CHILD", INT2NUM(XML_RNGP_TEXT_HAS_CHILD)); + rb_define_const(eXMLError, "RNGP_TYPE_MISSING", INT2NUM(XML_RNGP_TYPE_MISSING)); + rb_define_const(eXMLError, "RNGP_TYPE_NOT_FOUND", INT2NUM(XML_RNGP_TYPE_NOT_FOUND)); + rb_define_const(eXMLError, "RNGP_TYPE_VALUE", INT2NUM(XML_RNGP_TYPE_VALUE)); + rb_define_const(eXMLError, "RNGP_UNKNOWN_ATTRIBUTE", INT2NUM(XML_RNGP_UNKNOWN_ATTRIBUTE)); + rb_define_const(eXMLError, "RNGP_UNKNOWN_COMBINE", INT2NUM(XML_RNGP_UNKNOWN_COMBINE)); + rb_define_const(eXMLError, "RNGP_UNKNOWN_CONSTRUCT", INT2NUM(XML_RNGP_UNKNOWN_CONSTRUCT)); + rb_define_const(eXMLError, "RNGP_UNKNOWN_TYPE_LIB", INT2NUM(XML_RNGP_UNKNOWN_TYPE_LIB)); + rb_define_const(eXMLError, "RNGP_URI_FRAGMENT", INT2NUM(XML_RNGP_URI_FRAGMENT)); + rb_define_const(eXMLError, "RNGP_URI_NOT_ABSOLUTE", INT2NUM(XML_RNGP_URI_NOT_ABSOLUTE)); + rb_define_const(eXMLError, "RNGP_VALUE_EMPTY", INT2NUM(XML_RNGP_VALUE_EMPTY)); + rb_define_const(eXMLError, "RNGP_VALUE_NO_CONTENT", INT2NUM(XML_RNGP_VALUE_NO_CONTENT)); + rb_define_const(eXMLError, "RNGP_XMLNS_NAME", INT2NUM(XML_RNGP_XMLNS_NAME)); + rb_define_const(eXMLError, "RNGP_XML_NS", INT2NUM(XML_RNGP_XML_NS)); + rb_define_const(eXMLError, "XPATH_EXPRESSION_OK", INT2NUM(XML_XPATH_EXPRESSION_OK)); + rb_define_const(eXMLError, "XPATH_NUMBER_ERROR", INT2NUM(XML_XPATH_NUMBER_ERROR)); + rb_define_const(eXMLError, "XPATH_UNFINISHED_LITERAL_ERROR", INT2NUM(XML_XPATH_UNFINISHED_LITERAL_ERROR)); + rb_define_const(eXMLError, "XPATH_START_LITERAL_ERROR", INT2NUM(XML_XPATH_START_LITERAL_ERROR)); + rb_define_const(eXMLError, "XPATH_VARIABLE_REF_ERROR", INT2NUM(XML_XPATH_VARIABLE_REF_ERROR)); + rb_define_const(eXMLError, "XPATH_UNDEF_VARIABLE_ERROR", INT2NUM(XML_XPATH_UNDEF_VARIABLE_ERROR)); + rb_define_const(eXMLError, "XPATH_INVALID_PREDICATE_ERROR", INT2NUM(XML_XPATH_INVALID_PREDICATE_ERROR)); + rb_define_const(eXMLError, "XPATH_EXPR_ERROR", INT2NUM(XML_XPATH_EXPR_ERROR)); + rb_define_const(eXMLError, "XPATH_UNCLOSED_ERROR", INT2NUM(XML_XPATH_UNCLOSED_ERROR)); + rb_define_const(eXMLError, "XPATH_UNKNOWN_FUNC_ERROR", INT2NUM(XML_XPATH_UNKNOWN_FUNC_ERROR)); + rb_define_const(eXMLError, "XPATH_INVALID_OPERAND", INT2NUM(XML_XPATH_INVALID_OPERAND)); + rb_define_const(eXMLError, "XPATH_INVALID_TYPE", INT2NUM(XML_XPATH_INVALID_TYPE)); + rb_define_const(eXMLError, "XPATH_INVALID_ARITY", INT2NUM(XML_XPATH_INVALID_ARITY)); + rb_define_const(eXMLError, "XPATH_INVALID_CTXT_SIZE", INT2NUM(XML_XPATH_INVALID_CTXT_SIZE)); + rb_define_const(eXMLError, "XPATH_INVALID_CTXT_POSITION", INT2NUM(XML_XPATH_INVALID_CTXT_POSITION)); + rb_define_const(eXMLError, "XPATH_MEMORY_ERROR", INT2NUM(XML_XPATH_MEMORY_ERROR)); + rb_define_const(eXMLError, "XPTR_SYNTAX_ERROR", INT2NUM(XML_XPTR_SYNTAX_ERROR)); + rb_define_const(eXMLError, "XPTR_RESOURCE_ERROR", INT2NUM(XML_XPTR_RESOURCE_ERROR)); + rb_define_const(eXMLError, "XPTR_SUB_RESOURCE_ERROR", INT2NUM(XML_XPTR_SUB_RESOURCE_ERROR)); + rb_define_const(eXMLError, "XPATH_UNDEF_PREFIX_ERROR", INT2NUM(XML_XPATH_UNDEF_PREFIX_ERROR)); + rb_define_const(eXMLError, "XPATH_ENCODING_ERROR", INT2NUM(XML_XPATH_ENCODING_ERROR)); + rb_define_const(eXMLError, "XPATH_INVALID_CHAR_ERROR", INT2NUM(XML_XPATH_INVALID_CHAR_ERROR)); + rb_define_const(eXMLError, "TREE_INVALID_HEX", INT2NUM(XML_TREE_INVALID_HEX)); + rb_define_const(eXMLError, "TREE_INVALID_DEC", INT2NUM(XML_TREE_INVALID_DEC)); + rb_define_const(eXMLError, "TREE_UNTERMINATED_ENTITY", INT2NUM(XML_TREE_UNTERMINATED_ENTITY)); +#if LIBXML_VERSION >= 20632 + rb_define_const(eXMLError, "TREE_NOT_UTF8", INT2NUM(XML_TREE_NOT_UTF8)); +#endif + rb_define_const(eXMLError, "SAVE_NOT_UTF8", INT2NUM(XML_SAVE_NOT_UTF8)); + rb_define_const(eXMLError, "SAVE_CHAR_INVALID", INT2NUM(XML_SAVE_CHAR_INVALID)); + rb_define_const(eXMLError, "SAVE_NO_DOCTYPE", INT2NUM(XML_SAVE_NO_DOCTYPE)); + rb_define_const(eXMLError, "SAVE_UNKNOWN_ENCODING", INT2NUM(XML_SAVE_UNKNOWN_ENCODING)); + rb_define_const(eXMLError, "REGEXP_COMPILE_ERROR", INT2NUM(XML_REGEXP_COMPILE_ERROR)); + rb_define_const(eXMLError, "IO_UNKNOWN", INT2NUM(XML_IO_UNKNOWN)); + rb_define_const(eXMLError, "IO_EACCES", INT2NUM(XML_IO_EACCES)); + rb_define_const(eXMLError, "IO_EAGAIN", INT2NUM(XML_IO_EAGAIN)); + rb_define_const(eXMLError, "IO_EBADF", INT2NUM(XML_IO_EBADF)); + rb_define_const(eXMLError, "IO_EBADMSG", INT2NUM(XML_IO_EBADMSG)); + rb_define_const(eXMLError, "IO_EBUSY", INT2NUM(XML_IO_EBUSY)); + rb_define_const(eXMLError, "IO_ECANCELED", INT2NUM(XML_IO_ECANCELED)); + rb_define_const(eXMLError, "IO_ECHILD", INT2NUM(XML_IO_ECHILD)); + rb_define_const(eXMLError, "IO_EDEADLK", INT2NUM(XML_IO_EDEADLK)); + rb_define_const(eXMLError, "IO_EDOM", INT2NUM(XML_IO_EDOM)); + rb_define_const(eXMLError, "IO_EEXIST", INT2NUM(XML_IO_EEXIST)); + rb_define_const(eXMLError, "IO_EFAULT", INT2NUM(XML_IO_EFAULT)); + rb_define_const(eXMLError, "IO_EFBIG", INT2NUM(XML_IO_EFBIG)); + rb_define_const(eXMLError, "IO_EINPROGRESS", INT2NUM(XML_IO_EINPROGRESS)); + rb_define_const(eXMLError, "IO_EINTR", INT2NUM(XML_IO_EINTR)); + rb_define_const(eXMLError, "IO_EINVAL", INT2NUM(XML_IO_EINVAL)); + rb_define_const(eXMLError, "IO_EIO", INT2NUM(XML_IO_EIO)); + rb_define_const(eXMLError, "IO_EISDIR", INT2NUM(XML_IO_EISDIR)); + rb_define_const(eXMLError, "IO_EMFILE", INT2NUM(XML_IO_EMFILE)); + rb_define_const(eXMLError, "IO_EMLINK", INT2NUM(XML_IO_EMLINK)); + rb_define_const(eXMLError, "IO_EMSGSIZE", INT2NUM(XML_IO_EMSGSIZE)); + rb_define_const(eXMLError, "IO_ENAMETOOLONG", INT2NUM(XML_IO_ENAMETOOLONG)); + rb_define_const(eXMLError, "IO_ENFILE", INT2NUM(XML_IO_ENFILE)); + rb_define_const(eXMLError, "IO_ENODEV", INT2NUM(XML_IO_ENODEV)); + rb_define_const(eXMLError, "IO_ENOENT", INT2NUM(XML_IO_ENOENT)); + rb_define_const(eXMLError, "IO_ENOEXEC", INT2NUM(XML_IO_ENOEXEC)); + rb_define_const(eXMLError, "IO_ENOLCK", INT2NUM(XML_IO_ENOLCK)); + rb_define_const(eXMLError, "IO_ENOMEM", INT2NUM(XML_IO_ENOMEM)); + rb_define_const(eXMLError, "IO_ENOSPC", INT2NUM(XML_IO_ENOSPC)); + rb_define_const(eXMLError, "IO_ENOSYS", INT2NUM(XML_IO_ENOSYS)); + rb_define_const(eXMLError, "IO_ENOTDIR", INT2NUM(XML_IO_ENOTDIR)); + rb_define_const(eXMLError, "IO_ENOTEMPTY", INT2NUM(XML_IO_ENOTEMPTY)); + rb_define_const(eXMLError, "IO_ENOTSUP", INT2NUM(XML_IO_ENOTSUP)); + rb_define_const(eXMLError, "IO_ENOTTY", INT2NUM(XML_IO_ENOTTY)); + rb_define_const(eXMLError, "IO_ENXIO", INT2NUM(XML_IO_ENXIO)); + rb_define_const(eXMLError, "IO_EPERM", INT2NUM(XML_IO_EPERM)); + rb_define_const(eXMLError, "IO_EPIPE", INT2NUM(XML_IO_EPIPE)); + rb_define_const(eXMLError, "IO_ERANGE", INT2NUM(XML_IO_ERANGE)); + rb_define_const(eXMLError, "IO_EROFS", INT2NUM(XML_IO_EROFS)); + rb_define_const(eXMLError, "IO_ESPIPE", INT2NUM(XML_IO_ESPIPE)); + rb_define_const(eXMLError, "IO_ESRCH", INT2NUM(XML_IO_ESRCH)); + rb_define_const(eXMLError, "IO_ETIMEDOUT", INT2NUM(XML_IO_ETIMEDOUT)); + rb_define_const(eXMLError, "IO_EXDEV", INT2NUM(XML_IO_EXDEV)); + rb_define_const(eXMLError, "IO_NETWORK_ATTEMPT", INT2NUM(XML_IO_NETWORK_ATTEMPT)); + rb_define_const(eXMLError, "IO_ENCODER", INT2NUM(XML_IO_ENCODER)); + rb_define_const(eXMLError, "IO_FLUSH", INT2NUM(XML_IO_FLUSH)); + rb_define_const(eXMLError, "IO_WRITE", INT2NUM(XML_IO_WRITE)); + rb_define_const(eXMLError, "IO_NO_INPUT", INT2NUM(XML_IO_NO_INPUT)); + rb_define_const(eXMLError, "IO_BUFFER_FULL", INT2NUM(XML_IO_BUFFER_FULL)); + rb_define_const(eXMLError, "IO_LOAD_ERROR", INT2NUM(XML_IO_LOAD_ERROR)); + rb_define_const(eXMLError, "IO_ENOTSOCK", INT2NUM(XML_IO_ENOTSOCK)); + rb_define_const(eXMLError, "IO_EISCONN", INT2NUM(XML_IO_EISCONN)); + rb_define_const(eXMLError, "IO_ECONNREFUSED", INT2NUM(XML_IO_ECONNREFUSED)); + rb_define_const(eXMLError, "IO_ENETUNREACH", INT2NUM(XML_IO_ENETUNREACH)); + rb_define_const(eXMLError, "IO_EADDRINUSE", INT2NUM(XML_IO_EADDRINUSE)); + rb_define_const(eXMLError, "IO_EALREADY", INT2NUM(XML_IO_EALREADY)); + rb_define_const(eXMLError, "IO_EAFNOSUPPORT", INT2NUM(XML_IO_EAFNOSUPPORT)); + rb_define_const(eXMLError, "XINCLUDE_RECURSION", INT2NUM(XML_XINCLUDE_RECURSION)); + rb_define_const(eXMLError, "XINCLUDE_PARSE_VALUE", INT2NUM(XML_XINCLUDE_PARSE_VALUE)); + rb_define_const(eXMLError, "XINCLUDE_ENTITY_DEF_MISMATCH", INT2NUM(XML_XINCLUDE_ENTITY_DEF_MISMATCH)); + rb_define_const(eXMLError, "XINCLUDE_NO_HREF", INT2NUM(XML_XINCLUDE_NO_HREF)); + rb_define_const(eXMLError, "XINCLUDE_NO_FALLBACK", INT2NUM(XML_XINCLUDE_NO_FALLBACK)); + rb_define_const(eXMLError, "XINCLUDE_HREF_URI", INT2NUM(XML_XINCLUDE_HREF_URI)); + rb_define_const(eXMLError, "XINCLUDE_TEXT_FRAGMENT", INT2NUM(XML_XINCLUDE_TEXT_FRAGMENT)); + rb_define_const(eXMLError, "XINCLUDE_TEXT_DOCUMENT", INT2NUM(XML_XINCLUDE_TEXT_DOCUMENT)); + rb_define_const(eXMLError, "XINCLUDE_INVALID_CHAR", INT2NUM(XML_XINCLUDE_INVALID_CHAR)); + rb_define_const(eXMLError, "XINCLUDE_BUILD_FAILED", INT2NUM(XML_XINCLUDE_BUILD_FAILED)); + rb_define_const(eXMLError, "XINCLUDE_UNKNOWN_ENCODING", INT2NUM(XML_XINCLUDE_UNKNOWN_ENCODING)); + rb_define_const(eXMLError, "XINCLUDE_MULTIPLE_ROOT", INT2NUM(XML_XINCLUDE_MULTIPLE_ROOT)); + rb_define_const(eXMLError, "XINCLUDE_XPTR_FAILED", INT2NUM(XML_XINCLUDE_XPTR_FAILED)); + rb_define_const(eXMLError, "XINCLUDE_XPTR_RESULT", INT2NUM(XML_XINCLUDE_XPTR_RESULT)); + rb_define_const(eXMLError, "XINCLUDE_INCLUDE_IN_INCLUDE", INT2NUM(XML_XINCLUDE_INCLUDE_IN_INCLUDE)); + rb_define_const(eXMLError, "XINCLUDE_FALLBACKS_IN_INCLUDE", INT2NUM(XML_XINCLUDE_FALLBACKS_IN_INCLUDE)); + rb_define_const(eXMLError, "XINCLUDE_FALLBACK_NOT_IN_INCLUDE", INT2NUM(XML_XINCLUDE_FALLBACK_NOT_IN_INCLUDE)); + rb_define_const(eXMLError, "XINCLUDE_DEPRECATED_NS", INT2NUM(XML_XINCLUDE_DEPRECATED_NS)); + rb_define_const(eXMLError, "XINCLUDE_FRAGMENT_ID", INT2NUM(XML_XINCLUDE_FRAGMENT_ID)); + rb_define_const(eXMLError, "CATALOG_MISSING_ATTR", INT2NUM(XML_CATALOG_MISSING_ATTR)); + rb_define_const(eXMLError, "CATALOG_ENTRY_BROKEN", INT2NUM(XML_CATALOG_ENTRY_BROKEN)); + rb_define_const(eXMLError, "CATALOG_PREFER_VALUE", INT2NUM(XML_CATALOG_PREFER_VALUE)); + rb_define_const(eXMLError, "CATALOG_NOT_CATALOG", INT2NUM(XML_CATALOG_NOT_CATALOG)); + rb_define_const(eXMLError, "CATALOG_RECURSION", INT2NUM(XML_CATALOG_RECURSION)); + rb_define_const(eXMLError, "SCHEMAP_PREFIX_UNDEFINED", INT2NUM(XML_SCHEMAP_PREFIX_UNDEFINED)); + rb_define_const(eXMLError, "SCHEMAP_ATTRFORMDEFAULT_VALUE", INT2NUM(XML_SCHEMAP_ATTRFORMDEFAULT_VALUE)); + rb_define_const(eXMLError, "SCHEMAP_ATTRGRP_NONAME_NOREF", INT2NUM(XML_SCHEMAP_ATTRGRP_NONAME_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_ATTR_NONAME_NOREF", INT2NUM(XML_SCHEMAP_ATTR_NONAME_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_COMPLEXTYPE_NONAME_NOREF", INT2NUM(XML_SCHEMAP_COMPLEXTYPE_NONAME_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_ELEMFORMDEFAULT_VALUE", INT2NUM(XML_SCHEMAP_ELEMFORMDEFAULT_VALUE)); + rb_define_const(eXMLError, "SCHEMAP_ELEM_NONAME_NOREF", INT2NUM(XML_SCHEMAP_ELEM_NONAME_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_EXTENSION_NO_BASE", INT2NUM(XML_SCHEMAP_EXTENSION_NO_BASE)); + rb_define_const(eXMLError, "SCHEMAP_FACET_NO_VALUE", INT2NUM(XML_SCHEMAP_FACET_NO_VALUE)); + rb_define_const(eXMLError, "SCHEMAP_FAILED_BUILD_IMPORT", INT2NUM(XML_SCHEMAP_FAILED_BUILD_IMPORT)); + rb_define_const(eXMLError, "SCHEMAP_GROUP_NONAME_NOREF", INT2NUM(XML_SCHEMAP_GROUP_NONAME_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_IMPORT_NAMESPACE_NOT_URI", INT2NUM(XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI)); + rb_define_const(eXMLError, "SCHEMAP_IMPORT_REDEFINE_NSNAME", INT2NUM(XML_SCHEMAP_IMPORT_REDEFINE_NSNAME)); + rb_define_const(eXMLError, "SCHEMAP_IMPORT_SCHEMA_NOT_URI", INT2NUM(XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_BOOLEAN", INT2NUM(XML_SCHEMAP_INVALID_BOOLEAN)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_ENUM", INT2NUM(XML_SCHEMAP_INVALID_ENUM)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_FACET", INT2NUM(XML_SCHEMAP_INVALID_FACET)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_FACET_VALUE", INT2NUM(XML_SCHEMAP_INVALID_FACET_VALUE)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_MAXOCCURS", INT2NUM(XML_SCHEMAP_INVALID_MAXOCCURS)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_MINOCCURS", INT2NUM(XML_SCHEMAP_INVALID_MINOCCURS)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_REF_AND_SUBTYPE", INT2NUM(XML_SCHEMAP_INVALID_REF_AND_SUBTYPE)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_WHITE_SPACE", INT2NUM(XML_SCHEMAP_INVALID_WHITE_SPACE)); + rb_define_const(eXMLError, "SCHEMAP_NOATTR_NOREF", INT2NUM(XML_SCHEMAP_NOATTR_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_NOTATION_NO_NAME", INT2NUM(XML_SCHEMAP_NOTATION_NO_NAME)); + rb_define_const(eXMLError, "SCHEMAP_NOTYPE_NOREF", INT2NUM(XML_SCHEMAP_NOTYPE_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_REF_AND_SUBTYPE", INT2NUM(XML_SCHEMAP_REF_AND_SUBTYPE)); + rb_define_const(eXMLError, "SCHEMAP_RESTRICTION_NONAME_NOREF", INT2NUM(XML_SCHEMAP_RESTRICTION_NONAME_NOREF)); + rb_define_const(eXMLError, "SCHEMAP_SIMPLETYPE_NONAME", INT2NUM(XML_SCHEMAP_SIMPLETYPE_NONAME)); + rb_define_const(eXMLError, "SCHEMAP_TYPE_AND_SUBTYPE", INT2NUM(XML_SCHEMAP_TYPE_AND_SUBTYPE)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ALL_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ALL_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ANYATTRIBUTE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ANYATTRIBUTE_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ATTR_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ATTR_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ATTRGRP_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ATTRGRP_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ATTRIBUTE_GROUP", INT2NUM(XML_SCHEMAP_UNKNOWN_ATTRIBUTE_GROUP)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_BASE_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_BASE_TYPE)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_CHOICE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_CHOICE_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_COMPLEXCONTENT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_COMPLEXCONTENT_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_COMPLEXTYPE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_COMPLEXTYPE_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_ELEM_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_ELEM_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_EXTENSION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_EXTENSION_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_FACET_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_FACET_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_FACET_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_FACET_TYPE)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_GROUP_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_GROUP_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_IMPORT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_IMPORT_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_LIST_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_LIST_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_NOTATION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_NOTATION_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_REF", INT2NUM(XML_SCHEMAP_UNKNOWN_REF)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_RESTRICTION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SCHEMAS_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SCHEMAS_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SEQUENCE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_SIMPLETYPE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_SIMPLETYPE_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_TYPE)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_UNION_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_UNION_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_ELEM_DEFAULT_FIXED", INT2NUM(XML_SCHEMAP_ELEM_DEFAULT_FIXED)); + rb_define_const(eXMLError, "SCHEMAP_REGEXP_INVALID", INT2NUM(XML_SCHEMAP_REGEXP_INVALID)); + rb_define_const(eXMLError, "SCHEMAP_FAILED_LOAD", INT2NUM(XML_SCHEMAP_FAILED_LOAD)); + rb_define_const(eXMLError, "SCHEMAP_NOTHING_TO_PARSE", INT2NUM(XML_SCHEMAP_NOTHING_TO_PARSE)); + rb_define_const(eXMLError, "SCHEMAP_NOROOT", INT2NUM(XML_SCHEMAP_NOROOT)); + rb_define_const(eXMLError, "SCHEMAP_REDEFINED_GROUP", INT2NUM(XML_SCHEMAP_REDEFINED_GROUP)); + rb_define_const(eXMLError, "SCHEMAP_REDEFINED_TYPE", INT2NUM(XML_SCHEMAP_REDEFINED_TYPE)); + rb_define_const(eXMLError, "SCHEMAP_REDEFINED_ELEMENT", INT2NUM(XML_SCHEMAP_REDEFINED_ELEMENT)); + rb_define_const(eXMLError, "SCHEMAP_REDEFINED_ATTRGROUP", INT2NUM(XML_SCHEMAP_REDEFINED_ATTRGROUP)); + rb_define_const(eXMLError, "SCHEMAP_REDEFINED_ATTR", INT2NUM(XML_SCHEMAP_REDEFINED_ATTR)); + rb_define_const(eXMLError, "SCHEMAP_REDEFINED_NOTATION", INT2NUM(XML_SCHEMAP_REDEFINED_NOTATION)); + rb_define_const(eXMLError, "SCHEMAP_FAILED_PARSE", INT2NUM(XML_SCHEMAP_FAILED_PARSE)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_PREFIX", INT2NUM(XML_SCHEMAP_UNKNOWN_PREFIX)); + rb_define_const(eXMLError, "SCHEMAP_DEF_AND_PREFIX", INT2NUM(XML_SCHEMAP_DEF_AND_PREFIX)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_INCLUDE_CHILD", INT2NUM(XML_SCHEMAP_UNKNOWN_INCLUDE_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_INCLUDE_SCHEMA_NOT_URI", INT2NUM(XML_SCHEMAP_INCLUDE_SCHEMA_NOT_URI)); + rb_define_const(eXMLError, "SCHEMAP_INCLUDE_SCHEMA_NO_URI", INT2NUM(XML_SCHEMAP_INCLUDE_SCHEMA_NO_URI)); + rb_define_const(eXMLError, "SCHEMAP_NOT_SCHEMA", INT2NUM(XML_SCHEMAP_NOT_SCHEMA)); + rb_define_const(eXMLError, "SCHEMAP_UNKNOWN_MEMBER_TYPE", INT2NUM(XML_SCHEMAP_UNKNOWN_MEMBER_TYPE)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_USE", INT2NUM(XML_SCHEMAP_INVALID_ATTR_USE)); + rb_define_const(eXMLError, "SCHEMAP_RECURSIVE", INT2NUM(XML_SCHEMAP_RECURSIVE)); + rb_define_const(eXMLError, "SCHEMAP_SUPERNUMEROUS_LIST_ITEM_TYPE", INT2NUM(XML_SCHEMAP_SUPERNUMEROUS_LIST_ITEM_TYPE)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_COMBINATION", INT2NUM(XML_SCHEMAP_INVALID_ATTR_COMBINATION)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_INLINE_COMBINATION", INT2NUM(XML_SCHEMAP_INVALID_ATTR_INLINE_COMBINATION)); + rb_define_const(eXMLError, "SCHEMAP_MISSING_SIMPLETYPE_CHILD", INT2NUM(XML_SCHEMAP_MISSING_SIMPLETYPE_CHILD)); + rb_define_const(eXMLError, "SCHEMAP_INVALID_ATTR_NAME", INT2NUM(XML_SCHEMAP_INVALID_ATTR_NAME)); + rb_define_const(eXMLError, "SCHEMAP_REF_AND_CONTENT", INT2NUM(XML_SCHEMAP_REF_AND_CONTENT)); + rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_1)); + rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_2)); + rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_3)); + rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_4", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_4)); + rb_define_const(eXMLError, "SCHEMAP_CT_PROPS_CORRECT_5", INT2NUM(XML_SCHEMAP_CT_PROPS_CORRECT_5)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_1", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_2", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_3", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3)); + rb_define_const(eXMLError, "SCHEMAP_WILDCARD_INVALID_NS_MEMBER", INT2NUM(XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER)); + rb_define_const(eXMLError, "SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE", INT2NUM(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE)); + rb_define_const(eXMLError, "SCHEMAP_UNION_NOT_EXPRESSIBLE", INT2NUM(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_3_1", INT2NUM(XML_SCHEMAP_SRC_IMPORT_3_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_3_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_3_2)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_4_1", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_4_2", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_4_3", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3)); + rb_define_const(eXMLError, "SCHEMAP_COS_CT_EXTENDS_1_3", INT2NUM(XML_SCHEMAP_COS_CT_EXTENDS_1_3)); + rb_define_const(eXMLError, "SCHEMAV_NOROOT", INT2NUM(XML_SCHEMAV_NOROOT)); + rb_define_const(eXMLError, "SCHEMAV_UNDECLAREDELEM", INT2NUM(XML_SCHEMAV_UNDECLAREDELEM)); + rb_define_const(eXMLError, "SCHEMAV_NOTTOPLEVEL", INT2NUM(XML_SCHEMAV_NOTTOPLEVEL)); + rb_define_const(eXMLError, "SCHEMAV_MISSING", INT2NUM(XML_SCHEMAV_MISSING)); + rb_define_const(eXMLError, "SCHEMAV_WRONGELEM", INT2NUM(XML_SCHEMAV_WRONGELEM)); + rb_define_const(eXMLError, "SCHEMAV_NOTYPE", INT2NUM(XML_SCHEMAV_NOTYPE)); + rb_define_const(eXMLError, "SCHEMAV_NOROLLBACK", INT2NUM(XML_SCHEMAV_NOROLLBACK)); + rb_define_const(eXMLError, "SCHEMAV_ISABSTRACT", INT2NUM(XML_SCHEMAV_ISABSTRACT)); + rb_define_const(eXMLError, "SCHEMAV_NOTEMPTY", INT2NUM(XML_SCHEMAV_NOTEMPTY)); + rb_define_const(eXMLError, "SCHEMAV_ELEMCONT", INT2NUM(XML_SCHEMAV_ELEMCONT)); + rb_define_const(eXMLError, "SCHEMAV_HAVEDEFAULT", INT2NUM(XML_SCHEMAV_HAVEDEFAULT)); + rb_define_const(eXMLError, "SCHEMAV_NOTNILLABLE", INT2NUM(XML_SCHEMAV_NOTNILLABLE)); + rb_define_const(eXMLError, "SCHEMAV_EXTRACONTENT", INT2NUM(XML_SCHEMAV_EXTRACONTENT)); + rb_define_const(eXMLError, "SCHEMAV_INVALIDATTR", INT2NUM(XML_SCHEMAV_INVALIDATTR)); + rb_define_const(eXMLError, "SCHEMAV_INVALIDELEM", INT2NUM(XML_SCHEMAV_INVALIDELEM)); + rb_define_const(eXMLError, "SCHEMAV_NOTDETERMINIST", INT2NUM(XML_SCHEMAV_NOTDETERMINIST)); + rb_define_const(eXMLError, "SCHEMAV_CONSTRUCT", INT2NUM(XML_SCHEMAV_CONSTRUCT)); + rb_define_const(eXMLError, "SCHEMAV_INTERNAL", INT2NUM(XML_SCHEMAV_INTERNAL)); + rb_define_const(eXMLError, "SCHEMAV_NOTSIMPLE", INT2NUM(XML_SCHEMAV_NOTSIMPLE)); + rb_define_const(eXMLError, "SCHEMAV_ATTRUNKNOWN", INT2NUM(XML_SCHEMAV_ATTRUNKNOWN)); + rb_define_const(eXMLError, "SCHEMAV_ATTRINVALID", INT2NUM(XML_SCHEMAV_ATTRINVALID)); + rb_define_const(eXMLError, "SCHEMAV_VALUE", INT2NUM(XML_SCHEMAV_VALUE)); + rb_define_const(eXMLError, "SCHEMAV_FACET", INT2NUM(XML_SCHEMAV_FACET)); + rb_define_const(eXMLError, "SCHEMAV_CVC_DATATYPE_VALID_1_2_1", INT2NUM(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_DATATYPE_VALID_1_2_2", INT2NUM(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_DATATYPE_VALID_1_2_3", INT2NUM(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3)); + rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_3_1_1", INT2NUM(XML_SCHEMAV_CVC_TYPE_3_1_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_3_1_2", INT2NUM(XML_SCHEMAV_CVC_TYPE_3_1_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_FACET_VALID", INT2NUM(XML_SCHEMAV_CVC_FACET_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_LENGTH_VALID", INT2NUM(XML_SCHEMAV_CVC_LENGTH_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_MINLENGTH_VALID", INT2NUM(XML_SCHEMAV_CVC_MINLENGTH_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_MAXLENGTH_VALID", INT2NUM(XML_SCHEMAV_CVC_MAXLENGTH_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_MININCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MININCLUSIVE_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_MAXINCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MAXINCLUSIVE_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_MINEXCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MINEXCLUSIVE_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_MAXEXCLUSIVE_VALID", INT2NUM(XML_SCHEMAV_CVC_MAXEXCLUSIVE_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_TOTALDIGITS_VALID", INT2NUM(XML_SCHEMAV_CVC_TOTALDIGITS_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_FRACTIONDIGITS_VALID", INT2NUM(XML_SCHEMAV_CVC_FRACTIONDIGITS_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_PATTERN_VALID", INT2NUM(XML_SCHEMAV_CVC_PATTERN_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ENUMERATION_VALID", INT2NUM(XML_SCHEMAV_CVC_ENUMERATION_VALID)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_2", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_3", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_2_4", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_4)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_1", INT2NUM(XML_SCHEMAV_CVC_ELT_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_2", INT2NUM(XML_SCHEMAV_CVC_ELT_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_3_1", INT2NUM(XML_SCHEMAV_CVC_ELT_3_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_3_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_3_2_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_3_2_2", INT2NUM(XML_SCHEMAV_CVC_ELT_3_2_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_4_1", INT2NUM(XML_SCHEMAV_CVC_ELT_4_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_4_2", INT2NUM(XML_SCHEMAV_CVC_ELT_4_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_4_3", INT2NUM(XML_SCHEMAV_CVC_ELT_4_3)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_1_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_1_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_1_2", INT2NUM(XML_SCHEMAV_CVC_ELT_5_1_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_2_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_2_2_1", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_2_2_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_5_2_2_2_2", INT2NUM(XML_SCHEMAV_CVC_ELT_5_2_2_2_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_6", INT2NUM(XML_SCHEMAV_CVC_ELT_6)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ELT_7",INT2NUM(XML_SCHEMAV_CVC_ELT_7)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_1", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_2", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_3", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_3)); + rb_define_const(eXMLError, "SCHEMAV_CVC_ATTRIBUTE_4", INT2NUM(XML_SCHEMAV_CVC_ATTRIBUTE_4)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_3_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_3_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_3_2_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_3_2_2", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_4", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_4)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_5_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_5_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_5_2", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_5_2)); + rb_define_const(eXMLError, "SCHEMAV_ELEMENT_CONTENT", INT2NUM(XML_SCHEMAV_ELEMENT_CONTENT)); + rb_define_const(eXMLError, "SCHEMAV_DOCUMENT_ELEMENT_MISSING", INT2NUM(XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING)); + rb_define_const(eXMLError, "SCHEMAV_CVC_COMPLEX_TYPE_1", INT2NUM(XML_SCHEMAV_CVC_COMPLEX_TYPE_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_AU", INT2NUM(XML_SCHEMAV_CVC_AU)); + rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_1", INT2NUM(XML_SCHEMAV_CVC_TYPE_1)); + rb_define_const(eXMLError, "SCHEMAV_CVC_TYPE_2", INT2NUM(XML_SCHEMAV_CVC_TYPE_2)); +#if LIBXML_VERSION >= 20618 + rb_define_const(eXMLError, "SCHEMAV_CVC_IDC", INT2NUM(XML_SCHEMAV_CVC_IDC)); + rb_define_const(eXMLError, "SCHEMAV_CVC_WILDCARD", INT2NUM(XML_SCHEMAV_CVC_WILDCARD)); +#endif +#if LIBXML_VERSION >= 20631 + rb_define_const(eXMLError, "SCHEMAV_MISC", INT2NUM(XML_SCHEMAV_MISC)); +#endif + rb_define_const(eXMLError, "XPTR_UNKNOWN_SCHEME", INT2NUM(XML_XPTR_UNKNOWN_SCHEME)); + rb_define_const(eXMLError, "XPTR_CHILDSEQ_START", INT2NUM(XML_XPTR_CHILDSEQ_START)); + rb_define_const(eXMLError, "XPTR_EVAL_FAILED", INT2NUM(XML_XPTR_EVAL_FAILED)); + rb_define_const(eXMLError, "XPTR_EXTRA_OBJECTS", INT2NUM(XML_XPTR_EXTRA_OBJECTS)); + rb_define_const(eXMLError, "C14N_CREATE_CTXT", INT2NUM(XML_C14N_CREATE_CTXT)); + rb_define_const(eXMLError, "C14N_REQUIRES_UTF8", INT2NUM(XML_C14N_REQUIRES_UTF8)); + rb_define_const(eXMLError, "C14N_CREATE_STACK", + INT2NUM(XML_C14N_CREATE_STACK)); + rb_define_const(eXMLError, "C14N_INVALID_NODE", + INT2NUM(XML_C14N_INVALID_NODE)); +#if LIBXML_VERSION >= 20619 + rb_define_const(eXMLError, "C14N_UNKNOW_NODE", INT2NUM(XML_C14N_UNKNOW_NODE)); + rb_define_const(eXMLError, "C14N_RELATIVE_NAMESPACE", INT2NUM(XML_C14N_RELATIVE_NAMESPACE)); +#endif + rb_define_const(eXMLError, "FTP_PASV_ANSWER", INT2NUM(XML_FTP_PASV_ANSWER)); + rb_define_const(eXMLError, "FTP_EPSV_ANSWER", INT2NUM(XML_FTP_EPSV_ANSWER)); + rb_define_const(eXMLError, "FTP_ACCNT", INT2NUM(XML_FTP_ACCNT)); +#if LIBXML_VERSION >= 20618 + rb_define_const(eXMLError, "FTP_URL_SYNTAX", INT2NUM(XML_FTP_URL_SYNTAX)); +#endif + rb_define_const(eXMLError, "HTTP_URL_SYNTAX", INT2NUM(XML_HTTP_URL_SYNTAX)); + rb_define_const(eXMLError, "HTTP_USE_IP", INT2NUM(XML_HTTP_USE_IP)); + rb_define_const(eXMLError, "HTTP_UNKNOWN_HOST", INT2NUM(XML_HTTP_UNKNOWN_HOST)); + rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_1", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_2", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_3", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_3)); + rb_define_const(eXMLError, "SCHEMAP_SRC_SIMPLE_TYPE_4", INT2NUM(XML_SCHEMAP_SRC_SIMPLE_TYPE_4)); + rb_define_const(eXMLError, "SCHEMAP_SRC_RESOLVE", INT2NUM(XML_SCHEMAP_SRC_RESOLVE)); + rb_define_const(eXMLError, "SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE", INT2NUM(XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE)); + rb_define_const(eXMLError, "SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE", INT2NUM(XML_SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE)); + rb_define_const(eXMLError, "SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES", INT2NUM(XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES)); + rb_define_const(eXMLError, "SCHEMAP_ST_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_ST_PROPS_CORRECT_1)); + rb_define_const(eXMLError, "SCHEMAP_ST_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_ST_PROPS_CORRECT_2)); + rb_define_const(eXMLError, "SCHEMAP_ST_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_ST_PROPS_CORRECT_3)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_2)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_3_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_1_3_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_1_3_2)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_1_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_1_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_3", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_4", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_2_3_2_5", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_5)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_1_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_2", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_1", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_3", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_4", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_RESTRICTS_3_3_2_5", INT2NUM(XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_5)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_DERIVED_OK_2_1", INT2NUM(XML_SCHEMAP_COS_ST_DERIVED_OK_2_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_ST_DERIVED_OK_2_2", INT2NUM(XML_SCHEMAP_COS_ST_DERIVED_OK_2_2)); + rb_define_const(eXMLError, "SCHEMAP_S4S_ELEM_NOT_ALLOWED", INT2NUM(XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED)); + rb_define_const(eXMLError, "SCHEMAP_S4S_ELEM_MISSING", INT2NUM(XML_SCHEMAP_S4S_ELEM_MISSING)); + rb_define_const(eXMLError, "SCHEMAP_S4S_ATTR_NOT_ALLOWED", INT2NUM(XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED)); + rb_define_const(eXMLError, "SCHEMAP_S4S_ATTR_MISSING", INT2NUM(XML_SCHEMAP_S4S_ATTR_MISSING)); + rb_define_const(eXMLError, "SCHEMAP_S4S_ATTR_INVALID_VALUE", INT2NUM(XML_SCHEMAP_S4S_ATTR_INVALID_VALUE)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_1", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_2_1", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_2_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_2_2", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_2_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ELEMENT_3", INT2NUM(XML_SCHEMAP_SRC_ELEMENT_3)); + rb_define_const(eXMLError, "SCHEMAP_P_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_P_PROPS_CORRECT_1)); + rb_define_const(eXMLError, "SCHEMAP_P_PROPS_CORRECT_2_1", INT2NUM(XML_SCHEMAP_P_PROPS_CORRECT_2_1)); + rb_define_const(eXMLError, "SCHEMAP_P_PROPS_CORRECT_2_2", INT2NUM(XML_SCHEMAP_P_PROPS_CORRECT_2_2)); + rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_2)); + rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_3)); + rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_4", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_4)); + rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_5", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_5)); + rb_define_const(eXMLError, "SCHEMAP_E_PROPS_CORRECT_6", INT2NUM(XML_SCHEMAP_E_PROPS_CORRECT_6)); + rb_define_const(eXMLError, "SCHEMAP_SRC_INCLUDE", INT2NUM(XML_SCHEMAP_SRC_INCLUDE)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_1", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_2", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_3_1", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_3_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_3_2", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_3_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_4", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_4)); + rb_define_const(eXMLError, "SCHEMAP_NO_XMLNS", INT2NUM(XML_SCHEMAP_NO_XMLNS)); + rb_define_const(eXMLError, "SCHEMAP_NO_XSI", INT2NUM(XML_SCHEMAP_NO_XSI)); + rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_1", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_2_1", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_2_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_2_2_1", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_2_2_1)); + rb_define_const(eXMLError, "SCHEMAP_COS_VALID_DEFAULT_2_2_2", INT2NUM(XML_SCHEMAP_COS_VALID_DEFAULT_2_2_2)); + rb_define_const(eXMLError, "SCHEMAP_CVC_SIMPLE_TYPE", INT2NUM(XML_SCHEMAP_CVC_SIMPLE_TYPE)); + rb_define_const(eXMLError, "SCHEMAP_COS_CT_EXTENDS_1_1", INT2NUM(XML_SCHEMAP_COS_CT_EXTENDS_1_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_1_1", INT2NUM(XML_SCHEMAP_SRC_IMPORT_1_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_1_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_1_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_2_1", INT2NUM(XML_SCHEMAP_SRC_IMPORT_2_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT_2_2", INT2NUM(XML_SCHEMAP_SRC_IMPORT_2_2)); + rb_define_const(eXMLError, "SCHEMAP_INTERNAL", INT2NUM(XML_SCHEMAP_INTERNAL)); + rb_define_const(eXMLError, "SCHEMAP_NOT_DETERMINISTIC", INT2NUM(XML_SCHEMAP_NOT_DETERMINISTIC)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_GROUP_1", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_1)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_GROUP_2", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_ATTRIBUTE_GROUP_3", INT2NUM(XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3)); + rb_define_const(eXMLError, "SCHEMAP_MG_PROPS_CORRECT_1", INT2NUM(XML_SCHEMAP_MG_PROPS_CORRECT_1)); + rb_define_const(eXMLError, "SCHEMAP_MG_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_MG_PROPS_CORRECT_2)); + rb_define_const(eXMLError, "SCHEMAP_SRC_CT_1", INT2NUM(XML_SCHEMAP_SRC_CT_1)); + rb_define_const(eXMLError, "SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3", INT2NUM(XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3)); + rb_define_const(eXMLError, "SCHEMAP_AU_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_AU_PROPS_CORRECT_2)); + rb_define_const(eXMLError, "SCHEMAP_A_PROPS_CORRECT_2", INT2NUM(XML_SCHEMAP_A_PROPS_CORRECT_2)); +#if LIBXML_VERSION >= 20620 + rb_define_const(eXMLError, "SCHEMAP_C_PROPS_CORRECT", INT2NUM(XML_SCHEMAP_C_PROPS_CORRECT)); +#endif +#if LIBXML_VERSION >= 20621 + rb_define_const(eXMLError, "SCHEMAP_SRC_REDEFINE", INT2NUM(XML_SCHEMAP_SRC_REDEFINE)); + rb_define_const(eXMLError, "SCHEMAP_SRC_IMPORT", INT2NUM(XML_SCHEMAP_SRC_IMPORT)); + rb_define_const(eXMLError, "SCHEMAP_WARN_SKIP_SCHEMA", INT2NUM(XML_SCHEMAP_WARN_SKIP_SCHEMA)); + rb_define_const(eXMLError, "SCHEMAP_WARN_UNLOCATED_SCHEMA", INT2NUM(XML_SCHEMAP_WARN_UNLOCATED_SCHEMA)); + rb_define_const(eXMLError, "SCHEMAP_WARN_ATTR_REDECL_PROH", INT2NUM(XML_SCHEMAP_WARN_ATTR_REDECL_PROH)); + rb_define_const(eXMLError, "SCHEMAP_WARN_ATTR_POINTLESS_PROH", INT2NUM(XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH)); +#endif +#if LIBXML_VERSION >= 20623 + rb_define_const(eXMLError, "SCHEMAP_AG_PROPS_CORRECT", INT2NUM(XML_SCHEMAP_AG_PROPS_CORRECT)); + rb_define_const(eXMLError, "SCHEMAP_COS_CT_EXTENDS_1_2", INT2NUM(XML_SCHEMAP_COS_CT_EXTENDS_1_2)); + rb_define_const(eXMLError, "SCHEMAP_AU_PROPS_CORRECT", INT2NUM(XML_SCHEMAP_AU_PROPS_CORRECT)); + rb_define_const(eXMLError, "SCHEMAP_A_PROPS_CORRECT_3", INT2NUM(XML_SCHEMAP_A_PROPS_CORRECT_3)); + rb_define_const(eXMLError, "SCHEMAP_COS_ALL_LIMITED", INT2NUM(XML_SCHEMAP_COS_ALL_LIMITED)); +#endif +#if LIBXML_VERSION >= 20632 + rb_define_const(eXMLError, "SCHEMATRONV_ASSERT", INT2NUM(XML_SCHEMATRONV_ASSERT)); + rb_define_const(eXMLError, "SCHEMATRONV_REPORT", INT2NUM(XML_SCHEMATRONV_REPORT)); +#endif +#if LIBXML_VERSION >= 20618 + rb_define_const(eXMLError, "MODULE_OPEN", INT2NUM(XML_MODULE_OPEN)); + rb_define_const(eXMLError, "MODULE_CLOSE", INT2NUM(XML_MODULE_CLOSE)); +#endif + rb_define_const(eXMLError, "CHECK_FOUND_ELEMENT", INT2NUM(XML_CHECK_FOUND_ELEMENT)); + rb_define_const(eXMLError, "CHECK_FOUND_ATTRIBUTE", INT2NUM(XML_CHECK_FOUND_ATTRIBUTE)); + rb_define_const(eXMLError, "CHECK_FOUND_TEXT", INT2NUM(XML_CHECK_FOUND_TEXT)); + rb_define_const(eXMLError, "CHECK_FOUND_CDATA",INT2NUM(XML_CHECK_FOUND_CDATA)); + rb_define_const(eXMLError, "CHECK_FOUND_ENTITYREF", INT2NUM(XML_CHECK_FOUND_ENTITYREF)); + rb_define_const(eXMLError, "CHECK_FOUND_ENTITY", INT2NUM(XML_CHECK_FOUND_ENTITY)); + rb_define_const(eXMLError, "CHECK_FOUND_PI", INT2NUM(XML_CHECK_FOUND_PI)); + rb_define_const(eXMLError, "CHECK_FOUND_COMMENT", INT2NUM(XML_CHECK_FOUND_COMMENT)); + rb_define_const(eXMLError, "CHECK_FOUND_DOCTYPE", INT2NUM(XML_CHECK_FOUND_DOCTYPE)); + rb_define_const(eXMLError, "CHECK_FOUND_FRAGMENT", INT2NUM(XML_CHECK_FOUND_FRAGMENT)); + rb_define_const(eXMLError, "CHECK_FOUND_NOTATION", INT2NUM(XML_CHECK_FOUND_NOTATION)); + rb_define_const(eXMLError, "CHECK_UNKNOWN_NODE", INT2NUM(XML_CHECK_UNKNOWN_NODE)); + rb_define_const(eXMLError, "CHECK_ENTITY_TYPE", INT2NUM(XML_CHECK_ENTITY_TYPE)); + rb_define_const(eXMLError, "CHECK_NO_PARENT", INT2NUM(XML_CHECK_NO_PARENT)); + rb_define_const(eXMLError, "CHECK_NO_DOC", INT2NUM(XML_CHECK_NO_DOC)); + rb_define_const(eXMLError, "CHECK_NO_NAME", INT2NUM(XML_CHECK_NO_NAME)); + rb_define_const(eXMLError, "CHECK_NO_ELEM", INT2NUM(XML_CHECK_NO_ELEM)); + rb_define_const(eXMLError, "CHECK_WRONG_DOC", INT2NUM(XML_CHECK_WRONG_DOC)); + rb_define_const(eXMLError, "CHECK_NO_PREV", INT2NUM(XML_CHECK_NO_PREV)); + rb_define_const(eXMLError, "CHECK_WRONG_PREV", INT2NUM(XML_CHECK_WRONG_PREV)); + rb_define_const(eXMLError, "CHECK_NO_NEXT", INT2NUM(XML_CHECK_NO_NEXT)); + rb_define_const(eXMLError, "CHECK_WRONG_NEXT", INT2NUM(XML_CHECK_WRONG_NEXT)); + rb_define_const(eXMLError, "CHECK_NOT_DTD", INT2NUM(XML_CHECK_NOT_DTD)); + rb_define_const(eXMLError, "CHECK_NOT_ATTR", INT2NUM(XML_CHECK_NOT_ATTR)); + rb_define_const(eXMLError, "CHECK_NOT_ATTR_DECL", INT2NUM(XML_CHECK_NOT_ATTR_DECL)); + rb_define_const(eXMLError, "CHECK_NOT_ELEM_DECL", INT2NUM(XML_CHECK_NOT_ELEM_DECL)); + rb_define_const(eXMLError, "CHECK_NOT_ENTITY_DECL", INT2NUM(XML_CHECK_NOT_ENTITY_DECL)); + rb_define_const(eXMLError, "CHECK_NOT_NS_DECL", INT2NUM(XML_CHECK_NOT_NS_DECL)); + rb_define_const(eXMLError, "CHECK_NO_HREF", INT2NUM(XML_CHECK_NO_HREF)); + rb_define_const(eXMLError, "CHECK_WRONG_PARENT", INT2NUM(XML_CHECK_WRONG_PARENT)); + rb_define_const(eXMLError, "CHECK_NS_SCOPE", INT2NUM(XML_CHECK_NS_SCOPE)); + rb_define_const(eXMLError, "CHECK_NS_ANCESTOR", INT2NUM(XML_CHECK_NS_ANCESTOR)); + rb_define_const(eXMLError, "CHECK_NOT_UTF8", INT2NUM(XML_CHECK_NOT_UTF8)); + rb_define_const(eXMLError, "CHECK_NO_DICT", INT2NUM(XML_CHECK_NO_DICT)); + rb_define_const(eXMLError, "CHECK_NOT_NCNAME", INT2NUM(XML_CHECK_NOT_NCNAME)); + rb_define_const(eXMLError, "CHECK_OUTSIDE_DICT", INT2NUM(XML_CHECK_OUTSIDE_DICT)); + rb_define_const(eXMLError, "CHECK_WRONG_NAME", INT2NUM(XML_CHECK_WRONG_NAME)); +#if LIBXML_VERSION >= 20621 + rb_define_const(eXMLError, "CHECK_NAME_NOT_NULL", INT2NUM(XML_CHECK_NAME_NOT_NULL)); + rb_define_const(eXMLError, "I18N_NO_NAME", INT2NUM(XML_I18N_NO_NAME)); + rb_define_const(eXMLError, "I18N_NO_HANDLER", INT2NUM(XML_I18N_NO_HANDLER)); + rb_define_const(eXMLError, "I18N_EXCESS_HANDLER", INT2NUM(XML_I18N_EXCESS_HANDLER)); + rb_define_const(eXMLError, "I18N_CONV_FAILED", INT2NUM(XML_I18N_CONV_FAILED)); + rb_define_const(eXMLError, "I18N_NO_OUTPUT", INT2NUM(XML_I18N_NO_OUTPUT)); +#endif +} diff --git a/ext/libxml/ruby_xml_error.h b/ext/libxml/ruby_xml_error.h index dc6b4de4..f82c1a33 100644 --- a/ext/libxml/ruby_xml_error.h +++ b/ext/libxml/ruby_xml_error.h @@ -1,14 +1,14 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#ifndef __RXML_ERROR__ -#define __RXML_ERROR__ - -#include - -extern VALUE eXMLError; - -void rxml_init_error(void); -VALUE rxml_error_wrap(const xmlError *xerror); -void rxml_raise(const xmlError *xerror); - -#endif +/* Please see the LICENSE file for copyright and distribution information */ + +#ifndef __RXML_ERROR__ +#define __RXML_ERROR__ + +#include + +extern VALUE eXMLError; + +void rxml_init_error(void); +VALUE rxml_error_wrap(const xmlError *xerror); +void rxml_raise(const xmlError *xerror); + +#endif diff --git a/ext/libxml/ruby_xml_html_parser_context.c b/ext/libxml/ruby_xml_html_parser_context.c index 4cc48e50..8ee58fc4 100644 --- a/ext/libxml/ruby_xml_html_parser_context.c +++ b/ext/libxml/ruby_xml_html_parser_context.c @@ -1,351 +1,351 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#include "ruby_libxml.h" -#include "ruby_xml_html_parser_context.h" - -#include - -/* - * Document-class: LibXML::XML::HTMLParser::Context - * - * The XML::HTMLParser::Context class provides in-depth control over how - * a document is parsed. - */ - -VALUE cXMLHtmlParserContext; -static ID IO_ATTR; - -/* OS X 10.5 ships with libxml2 version 2.6.16 which does not expose the - htmlNewParserCtxt (or htmlInitParserCtxt which it uses) method. htmlNewParserCtxt - wasn't added to the libxml2 header files until 2.6.27. So the next two - methods are simply copied from a newer version of libxml2 (2.7.2). */ -#if LIBXML_VERSION < 20627 -#define XML_CTXT_FINISH_DTD_0 0xabcd1234 -static int htmlInitParserCtxt(htmlParserCtxtPtr ctxt) -{ - htmlSAXHandler *sax; - if (ctxt == NULL) return(-1); - - memset(ctxt, 0, sizeof(htmlParserCtxt)); - ctxt->dict = xmlDictCreate(); - if (ctxt->dict == NULL) { - rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); - return(-1); - } - sax = (htmlSAXHandler *) xmlMalloc(sizeof(htmlSAXHandler)); - if (sax == NULL) { - rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); - return(-1); - } - else - memset(sax, 0, sizeof(htmlSAXHandler)); - - ctxt->inputTab = (htmlParserInputPtr *) xmlMalloc(5 * sizeof(htmlParserInputPtr)); - if (ctxt->inputTab == NULL) { - rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); - ctxt->inputNr = 0; - ctxt->inputMax = 0; - ctxt->input = NULL; - return(-1); - } - ctxt->inputNr = 0; - ctxt->inputMax = 5; - ctxt->input = NULL; - ctxt->version = NULL; - ctxt->encoding = NULL; - ctxt->standalone = -1; - ctxt->instate = XML_PARSER_START; - - ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr)); - if (ctxt->nodeTab == NULL) { - rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); - ctxt->nodeNr = 0; - ctxt->nodeMax = 0; - ctxt->node = NULL; - ctxt->inputNr = 0; - ctxt->inputMax = 0; - ctxt->input = NULL; - return(-1); - } - ctxt->nodeNr = 0; - ctxt->nodeMax = 10; - ctxt->node = NULL; - - ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *)); - if (ctxt->nameTab == NULL) { - rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); - ctxt->nameNr = 0; - ctxt->nameMax = 10; - ctxt->name = NULL; - ctxt->nodeNr = 0; - ctxt->nodeMax = 0; - ctxt->node = NULL; - ctxt->inputNr = 0; - ctxt->inputMax = 0; - ctxt->input = NULL; - return(-1); - } - ctxt->nameNr = 0; - ctxt->nameMax = 10; - ctxt->name = NULL; - - if (sax == NULL) ctxt->sax = (xmlSAXHandlerPtr) &htmlDefaultSAXHandler; - else { - ctxt->sax = sax; - memcpy(sax, &htmlDefaultSAXHandler, sizeof(xmlSAXHandlerV1)); - } - ctxt->userData = ctxt; - ctxt->myDoc = NULL; - ctxt->wellFormed = 1; - ctxt->replaceEntities = 0; - ctxt->linenumbers = xmlLineNumbersDefaultValue; - ctxt->html = 1; - ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0; - ctxt->vctxt.userData = ctxt; - ctxt->vctxt.error = xmlParserValidityError; - ctxt->vctxt.warning = xmlParserValidityWarning; - ctxt->record_info = 0; - ctxt->validate = 0; - ctxt->nbChars = 0; - ctxt->checkIndex = 0; - ctxt->catalogs = NULL; - xmlInitNodeInfoSeq(&ctxt->node_seq); - return(0); -} - -static htmlParserCtxtPtr htmlNewParserCtxt(void) -{ - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt)); - if (ctxt == NULL) { - rb_raise(rb_eNoMemError, "NewParserCtxt: out of memory\n"); - return(NULL); - } - memset(ctxt, 0, sizeof(xmlParserCtxt)); - if (htmlInitParserCtxt(ctxt) < 0) { - htmlFreeParserCtxt(ctxt); - return(NULL); - } - return(ctxt); -} -#endif - -static void rxml_html_parser_context_free(htmlParserCtxtPtr ctxt) -{ - htmlFreeParserCtxt(ctxt); -} - -static VALUE rxml_html_parser_context_wrap(htmlParserCtxtPtr ctxt) -{ - return Data_Wrap_Struct(cXMLHtmlParserContext, NULL, rxml_html_parser_context_free, ctxt); -} - -/* call-seq: - * XML::HTMLParser::Context.file(file) -> XML::HTMLParser::Context - * - * Creates a new parser context based on the specified file or uri. - * - * Parameters: - * - * file - A filename or uri - * options - A or'ed together list of LibXML::XML::HTMLParser::Options values -*/ -static VALUE rxml_html_parser_context_file(int argc, VALUE* argv, VALUE klass) -{ - VALUE file, options; - rb_scan_args(argc, argv, "11", &file, &options); - - htmlParserCtxtPtr ctxt = htmlCreateFileParserCtxt(StringValuePtr(file), NULL); - if (!ctxt) - rxml_raise(xmlGetLastError()); - - /* This is annoying, but xmlInitParserCtxt (called indirectly above) and - xmlCtxtUseOptionsInternal (called below) initialize slightly different - context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt - sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ - htmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); - - return rxml_html_parser_context_wrap(ctxt); -} - -/* call-seq: - * XML::HTMLParser::Context.io(io) -> XML::HTMLParser::Context - * - * Creates a new parser context based on the specified io object. - * - * Parameters: - * - * io - A ruby IO object - * options - A or'ed together list of LibXML::XML::HTMLParser::Options values -*/ -static VALUE rxml_html_parser_context_io(int argc, VALUE* argv, VALUE klass) -{ - VALUE io, options; - rb_scan_args(argc, argv, "11", &io, &options); - - VALUE result; - htmlParserCtxtPtr ctxt; - xmlParserInputBufferPtr input; - xmlParserInputPtr stream; - - if (NIL_P(io)) - rb_raise(rb_eTypeError, "Must pass in an IO object"); - - input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL, - (void*)io, XML_CHAR_ENCODING_NONE); - - ctxt = htmlNewParserCtxt(); - if (!ctxt) - { - xmlFreeParserInputBuffer(input); - rxml_raise(xmlGetLastError()); - } - - /* This is annoying, but xmlInitParserCtxt (called indirectly above) and - xmlCtxtUseOptionsInternal (called below) initialize slightly different - context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt - sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ - htmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); - - stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); - - if (!stream) - { - xmlFreeParserInputBuffer(input); - xmlFreeParserCtxt(ctxt); - rxml_raise(xmlGetLastError()); - } - inputPush(ctxt, stream); - result = rxml_html_parser_context_wrap(ctxt); - - /* Attach io object to parser so it won't get freed.*/ - rb_ivar_set(result, IO_ATTR, io); - - return result; -} - -/* call-seq: - * XML::HTMLParser::Context.string(string) -> XML::HTMLParser::Context - * - * Creates a new parser context based on the specified string. - * - * Parameters: - * - * string - A string that contains the data to parse - * options - A or'ed together list of LibXML::XML::HTMLParser::Options values -*/ -static VALUE rxml_html_parser_context_string(int argc, VALUE* argv, VALUE klass) -{ - VALUE string, options; - rb_scan_args(argc, argv, "11", &string, &options); - - Check_Type(string, T_STRING); - - if (RSTRING_LEN(string) == 0) - rb_raise(rb_eArgError, "Must specify a string with one or more characters"); - - htmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string), - (int)RSTRING_LEN(string)); - if (!ctxt) - rxml_raise(xmlGetLastError()); - - /* This is annoying, but xmlInitParserCtxt (called indirectly above) and - xmlCtxtUseOptionsInternal (called below) initialize slightly different - context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt - sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ - htmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); - - // Setup sax handler - // TODO - there must be a better way? The sax handler is initialized for XML, but we want - // to use HTML - memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); - xmlSAX2InitHtmlDefaultSAXHandler(ctxt->sax); - - return rxml_html_parser_context_wrap(ctxt); -} - -/* - * call-seq: - * context.close -> nil - * - * Closes the underlying input streams. This is useful when parsing a large amount of - * files and you want to close the files without relying on Ruby's garbage collector - * to run. - */ -static VALUE rxml_html_parser_context_close(VALUE self) -{ - htmlParserCtxtPtr ctxt; - xmlParserInputPtr xinput; - Data_Get_Struct(self, htmlParserCtxt, ctxt); - - while ((xinput = inputPop(ctxt)) != NULL) - { - xmlFreeInputStream(xinput); - } - return Qnil; -} - -/* - * call-seq: - * context.disable_cdata = (true|false) - * - * Control whether the CDATA nodes will be created in this context. - */ -static VALUE rxml_html_parser_context_disable_cdata_set(VALUE self, VALUE value) -{ - htmlParserCtxtPtr ctxt; - Data_Get_Struct(self, htmlParserCtxt, ctxt); - - if (ctxt->sax == NULL) - rb_raise(rb_eRuntimeError, "Sax handler is not yet set"); - - /* LibXML controls this internally with the default SAX handler. */ - if (value) - ctxt->sax->cdataBlock = NULL; - else - ctxt->sax->cdataBlock = xmlSAX2CDataBlock; - - return value; -} - -/* - * call-seq: - * context.options = XML::Parser::Options::NOENT | - XML::Parser::Options::NOCDATA - * - * Provides control over the execution of a parser. Valid values - * are the constants defined on XML::Parser::Options. Multiple - * options can be combined by using Bitwise OR (|). - */ -static VALUE rxml_html_parser_context_options_set(VALUE self, VALUE options) -{ - int xml_options = NUM2INT(options); - htmlParserCtxtPtr ctxt; - Check_Type(options, T_FIXNUM); - - Data_Get_Struct(self, htmlParserCtxt, ctxt); - htmlCtxtUseOptions(ctxt, xml_options); - -#if LIBXML_VERSION >= 20707 - /* Big hack here, but htmlCtxtUseOptions doens't support HTML_PARSE_NOIMPLIED. - So do it ourselves. There must be a better way??? */ - if (xml_options & HTML_PARSE_NOIMPLIED) - { - ctxt->options |= HTML_PARSE_NOIMPLIED; - } -#endif - - return self; -} - -void rxml_init_html_parser_context(void) -{ - IO_ATTR = ID2SYM(rb_intern("@io")); - cXMLHtmlParserContext = rb_define_class_under(cXMLHtmlParser, "Context", cXMLParserContext); - - rb_define_singleton_method(cXMLHtmlParserContext, "file", rxml_html_parser_context_file, -1); - rb_define_singleton_method(cXMLHtmlParserContext, "io", rxml_html_parser_context_io, -1); - rb_define_singleton_method(cXMLHtmlParserContext, "string", rxml_html_parser_context_string, -1); - rb_define_method(cXMLHtmlParserContext, "close", rxml_html_parser_context_close, 0); - rb_define_method(cXMLHtmlParserContext, "disable_cdata=", rxml_html_parser_context_disable_cdata_set, 1); - rb_define_method(cXMLHtmlParserContext, "options=", rxml_html_parser_context_options_set, 1); -} +/* Please see the LICENSE file for copyright and distribution information */ + +#include "ruby_libxml.h" +#include "ruby_xml_html_parser_context.h" + +#include + +/* + * Document-class: LibXML::XML::HTMLParser::Context + * + * The XML::HTMLParser::Context class provides in-depth control over how + * a document is parsed. + */ + +VALUE cXMLHtmlParserContext; +static ID IO_ATTR; + +/* OS X 10.5 ships with libxml2 version 2.6.16 which does not expose the + htmlNewParserCtxt (or htmlInitParserCtxt which it uses) method. htmlNewParserCtxt + wasn't added to the libxml2 header files until 2.6.27. So the next two + methods are simply copied from a newer version of libxml2 (2.7.2). */ +#if LIBXML_VERSION < 20627 +#define XML_CTXT_FINISH_DTD_0 0xabcd1234 +static int htmlInitParserCtxt(htmlParserCtxtPtr ctxt) +{ + htmlSAXHandler *sax; + if (ctxt == NULL) return(-1); + + memset(ctxt, 0, sizeof(htmlParserCtxt)); + ctxt->dict = xmlDictCreate(); + if (ctxt->dict == NULL) { + rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); + return(-1); + } + sax = (htmlSAXHandler *) xmlMalloc(sizeof(htmlSAXHandler)); + if (sax == NULL) { + rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); + return(-1); + } + else + memset(sax, 0, sizeof(htmlSAXHandler)); + + ctxt->inputTab = (htmlParserInputPtr *) xmlMalloc(5 * sizeof(htmlParserInputPtr)); + if (ctxt->inputTab == NULL) { + rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); + ctxt->inputNr = 0; + ctxt->inputMax = 0; + ctxt->input = NULL; + return(-1); + } + ctxt->inputNr = 0; + ctxt->inputMax = 5; + ctxt->input = NULL; + ctxt->version = NULL; + ctxt->encoding = NULL; + ctxt->standalone = -1; + ctxt->instate = XML_PARSER_START; + + ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr)); + if (ctxt->nodeTab == NULL) { + rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); + ctxt->nodeNr = 0; + ctxt->nodeMax = 0; + ctxt->node = NULL; + ctxt->inputNr = 0; + ctxt->inputMax = 0; + ctxt->input = NULL; + return(-1); + } + ctxt->nodeNr = 0; + ctxt->nodeMax = 10; + ctxt->node = NULL; + + ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *)); + if (ctxt->nameTab == NULL) { + rb_raise(rb_eNoMemError, "htmlInitParserCtxt: out of memory\n"); + ctxt->nameNr = 0; + ctxt->nameMax = 10; + ctxt->name = NULL; + ctxt->nodeNr = 0; + ctxt->nodeMax = 0; + ctxt->node = NULL; + ctxt->inputNr = 0; + ctxt->inputMax = 0; + ctxt->input = NULL; + return(-1); + } + ctxt->nameNr = 0; + ctxt->nameMax = 10; + ctxt->name = NULL; + + if (sax == NULL) ctxt->sax = (xmlSAXHandlerPtr) &htmlDefaultSAXHandler; + else { + ctxt->sax = sax; + memcpy(sax, &htmlDefaultSAXHandler, sizeof(xmlSAXHandlerV1)); + } + ctxt->userData = ctxt; + ctxt->myDoc = NULL; + ctxt->wellFormed = 1; + ctxt->replaceEntities = 0; + ctxt->linenumbers = xmlLineNumbersDefaultValue; + ctxt->html = 1; + ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0; + ctxt->vctxt.userData = ctxt; + ctxt->vctxt.error = xmlParserValidityError; + ctxt->vctxt.warning = xmlParserValidityWarning; + ctxt->record_info = 0; + ctxt->validate = 0; + ctxt->nbChars = 0; + ctxt->checkIndex = 0; + ctxt->catalogs = NULL; + xmlInitNodeInfoSeq(&ctxt->node_seq); + return(0); +} + +static htmlParserCtxtPtr htmlNewParserCtxt(void) +{ + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt)); + if (ctxt == NULL) { + rb_raise(rb_eNoMemError, "NewParserCtxt: out of memory\n"); + return(NULL); + } + memset(ctxt, 0, sizeof(xmlParserCtxt)); + if (htmlInitParserCtxt(ctxt) < 0) { + htmlFreeParserCtxt(ctxt); + return(NULL); + } + return(ctxt); +} +#endif + +static void rxml_html_parser_context_free(htmlParserCtxtPtr ctxt) +{ + htmlFreeParserCtxt(ctxt); +} + +static VALUE rxml_html_parser_context_wrap(htmlParserCtxtPtr ctxt) +{ + return Data_Wrap_Struct(cXMLHtmlParserContext, NULL, rxml_html_parser_context_free, ctxt); +} + +/* call-seq: + * XML::HTMLParser::Context.file(file) -> XML::HTMLParser::Context + * + * Creates a new parser context based on the specified file or uri. + * + * Parameters: + * + * file - A filename or uri + * options - A or'ed together list of LibXML::XML::HTMLParser::Options values +*/ +static VALUE rxml_html_parser_context_file(int argc, VALUE* argv, VALUE klass) +{ + VALUE file, options; + rb_scan_args(argc, argv, "11", &file, &options); + + htmlParserCtxtPtr ctxt = htmlCreateFileParserCtxt(StringValuePtr(file), NULL); + if (!ctxt) + rxml_raise(xmlGetLastError()); + + /* This is annoying, but xmlInitParserCtxt (called indirectly above) and + xmlCtxtUseOptionsInternal (called below) initialize slightly different + context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt + sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ + htmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); + + return rxml_html_parser_context_wrap(ctxt); +} + +/* call-seq: + * XML::HTMLParser::Context.io(io) -> XML::HTMLParser::Context + * + * Creates a new parser context based on the specified io object. + * + * Parameters: + * + * io - A ruby IO object + * options - A or'ed together list of LibXML::XML::HTMLParser::Options values +*/ +static VALUE rxml_html_parser_context_io(int argc, VALUE* argv, VALUE klass) +{ + VALUE io, options; + rb_scan_args(argc, argv, "11", &io, &options); + + VALUE result; + htmlParserCtxtPtr ctxt; + xmlParserInputBufferPtr input; + xmlParserInputPtr stream; + + if (NIL_P(io)) + rb_raise(rb_eTypeError, "Must pass in an IO object"); + + input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL, + (void*)io, XML_CHAR_ENCODING_NONE); + + ctxt = htmlNewParserCtxt(); + if (!ctxt) + { + xmlFreeParserInputBuffer(input); + rxml_raise(xmlGetLastError()); + } + + /* This is annoying, but xmlInitParserCtxt (called indirectly above) and + xmlCtxtUseOptionsInternal (called below) initialize slightly different + context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt + sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ + htmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); + + stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); + + if (!stream) + { + xmlFreeParserInputBuffer(input); + xmlFreeParserCtxt(ctxt); + rxml_raise(xmlGetLastError()); + } + inputPush(ctxt, stream); + result = rxml_html_parser_context_wrap(ctxt); + + /* Attach io object to parser so it won't get freed.*/ + rb_ivar_set(result, IO_ATTR, io); + + return result; +} + +/* call-seq: + * XML::HTMLParser::Context.string(string) -> XML::HTMLParser::Context + * + * Creates a new parser context based on the specified string. + * + * Parameters: + * + * string - A string that contains the data to parse + * options - A or'ed together list of LibXML::XML::HTMLParser::Options values +*/ +static VALUE rxml_html_parser_context_string(int argc, VALUE* argv, VALUE klass) +{ + VALUE string, options; + rb_scan_args(argc, argv, "11", &string, &options); + + Check_Type(string, T_STRING); + + if (RSTRING_LEN(string) == 0) + rb_raise(rb_eArgError, "Must specify a string with one or more characters"); + + htmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string), + (int)RSTRING_LEN(string)); + if (!ctxt) + rxml_raise(xmlGetLastError()); + + /* This is annoying, but xmlInitParserCtxt (called indirectly above) and + xmlCtxtUseOptionsInternal (called below) initialize slightly different + context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt + sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ + htmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); + + // Setup sax handler + // TODO - there must be a better way? The sax handler is initialized for XML, but we want + // to use HTML + memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); + xmlSAX2InitHtmlDefaultSAXHandler(ctxt->sax); + + return rxml_html_parser_context_wrap(ctxt); +} + +/* + * call-seq: + * context.close -> nil + * + * Closes the underlying input streams. This is useful when parsing a large amount of + * files and you want to close the files without relying on Ruby's garbage collector + * to run. + */ +static VALUE rxml_html_parser_context_close(VALUE self) +{ + htmlParserCtxtPtr ctxt; + xmlParserInputPtr xinput; + Data_Get_Struct(self, htmlParserCtxt, ctxt); + + while ((xinput = inputPop(ctxt)) != NULL) + { + xmlFreeInputStream(xinput); + } + return Qnil; +} + +/* + * call-seq: + * context.disable_cdata = (true|false) + * + * Control whether the CDATA nodes will be created in this context. + */ +static VALUE rxml_html_parser_context_disable_cdata_set(VALUE self, VALUE value) +{ + htmlParserCtxtPtr ctxt; + Data_Get_Struct(self, htmlParserCtxt, ctxt); + + if (ctxt->sax == NULL) + rb_raise(rb_eRuntimeError, "Sax handler is not yet set"); + + /* LibXML controls this internally with the default SAX handler. */ + if (value) + ctxt->sax->cdataBlock = NULL; + else + ctxt->sax->cdataBlock = xmlSAX2CDataBlock; + + return value; +} + +/* + * call-seq: + * context.options = XML::Parser::Options::NOENT | + XML::Parser::Options::NOCDATA + * + * Provides control over the execution of a parser. Valid values + * are the constants defined on XML::Parser::Options. Multiple + * options can be combined by using Bitwise OR (|). + */ +static VALUE rxml_html_parser_context_options_set(VALUE self, VALUE options) +{ + int xml_options = NUM2INT(options); + htmlParserCtxtPtr ctxt; + Check_Type(options, T_FIXNUM); + + Data_Get_Struct(self, htmlParserCtxt, ctxt); + htmlCtxtUseOptions(ctxt, xml_options); + +#if LIBXML_VERSION >= 20707 + /* Big hack here, but htmlCtxtUseOptions doens't support HTML_PARSE_NOIMPLIED. + So do it ourselves. There must be a better way??? */ + if (xml_options & HTML_PARSE_NOIMPLIED) + { + ctxt->options |= HTML_PARSE_NOIMPLIED; + } +#endif + + return self; +} + +void rxml_init_html_parser_context(void) +{ + IO_ATTR = ID2SYM(rb_intern("@io")); + cXMLHtmlParserContext = rb_define_class_under(cXMLHtmlParser, "Context", cXMLParserContext); + + rb_define_singleton_method(cXMLHtmlParserContext, "file", rxml_html_parser_context_file, -1); + rb_define_singleton_method(cXMLHtmlParserContext, "io", rxml_html_parser_context_io, -1); + rb_define_singleton_method(cXMLHtmlParserContext, "string", rxml_html_parser_context_string, -1); + rb_define_method(cXMLHtmlParserContext, "close", rxml_html_parser_context_close, 0); + rb_define_method(cXMLHtmlParserContext, "disable_cdata=", rxml_html_parser_context_disable_cdata_set, 1); + rb_define_method(cXMLHtmlParserContext, "options=", rxml_html_parser_context_options_set, 1); +} diff --git a/ext/libxml/ruby_xml_input_cbg.c b/ext/libxml/ruby_xml_input_cbg.c index c3ddf66b..1863f52d 100644 --- a/ext/libxml/ruby_xml_input_cbg.c +++ b/ext/libxml/ruby_xml_input_cbg.c @@ -1,188 +1,188 @@ -/* Author: Martin Povolny (xpovolny@fi.muni.cz) */ - -#include "ruby_libxml.h" -#include "ruby_xml_input_cbg.h" - -/* Document-class: LibXML::XML::InputCallbacks - * - * Support for adding custom scheme handlers. */ - -static ic_scheme *first_scheme = 0; - -int ic_match(char const *filename) -{ - ic_scheme *scheme; - - //fprintf( stderr, "ic_match: %s\n", filename ); - - scheme = first_scheme; - while (0 != scheme) - { - if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len)) - { - return 1; - } - scheme = scheme->next_scheme; - } - return 0; -} - -void* ic_open(char const *filename) -{ - ic_doc_context *ic_doc; - ic_scheme *scheme; - VALUE res; - - scheme = first_scheme; - while (0 != scheme) - { - if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len)) - { - ic_doc = (ic_doc_context*) malloc(sizeof(ic_doc_context)); - - res = rb_funcall(scheme->class, rb_intern("document_query"), 1, - rb_str_new2(filename)); - - ic_doc->buffer = strdup(StringValuePtr(res)); - - ic_doc->bpos = ic_doc->buffer; - ic_doc->remaining = (int)strlen(ic_doc->buffer); - return ic_doc; - } - scheme = scheme->next_scheme; - } - return 0; -} - -int ic_read(void *context, char *buffer, int len) -{ - ic_doc_context *ic_doc; - int ret_len; - ic_doc = (ic_doc_context*) context; - - if (len >= ic_doc->remaining) - { - ret_len = ic_doc->remaining; - } - else - { - ret_len = len; - } - ic_doc->remaining -= ret_len; - strncpy(buffer, ic_doc->bpos, ret_len); - ic_doc->bpos += ret_len; - - return ret_len; -} - -int ic_close(void *context) -{ - ruby_xfree(((ic_doc_context*) context)->buffer); - ruby_xfree(context); - return 1; -} - -/* - * call-seq: - * register - * - * Register a new set of I/O callback for handling parser input. - */ -static VALUE input_callbacks_register_input_callbacks(VALUE self) -{ - xmlRegisterInputCallbacks(ic_match, ic_open, ic_read, ic_close); - return (Qtrue); -} - -/* - * call-seq: - * add_scheme - * - * No documentation available. - */ -static VALUE input_callbacks_add_scheme(VALUE self, VALUE scheme_name, - VALUE class) -{ - ic_scheme *scheme; - - Check_Type(scheme_name, T_STRING); - - scheme = (ic_scheme*) malloc(sizeof(ic_scheme)); - scheme->next_scheme = 0; - scheme->scheme_name = strdup(StringValuePtr(scheme_name)); /* TODO alloc, dealloc */ - scheme->name_len = (int)strlen(scheme->scheme_name); - scheme->class = class; /* TODO alloc, dealloc */ - - //fprintf( stderr, "registered: %s, %d, %s\n", scheme->scheme_name, scheme->name_len, scheme->class ); - - if (0 == first_scheme) - first_scheme = scheme; - else - { - ic_scheme *pos; - pos = first_scheme; - while (0 != pos->next_scheme) - pos = pos->next_scheme; - pos->next_scheme = scheme; - } - - return (Qtrue); -} - -/* - * call-seq: - * remove_scheme - * - * No documentation available. - */ -static VALUE input_callbacks_remove_scheme(VALUE self, VALUE scheme_name) -{ - char *name; - ic_scheme *save_scheme, *scheme; - - Check_Type(scheme_name, T_STRING); - name = StringValuePtr(scheme_name); - - if (0 == first_scheme) - return Qfalse; - - if (!strncmp(name, first_scheme->scheme_name, first_scheme->name_len)) - { - save_scheme = first_scheme->next_scheme; - - ruby_xfree(first_scheme->scheme_name); - ruby_xfree(first_scheme); - - first_scheme = save_scheme; - return Qtrue; - } - - scheme = first_scheme; - while (0 != scheme->next_scheme) - { - if (!strncmp(name, scheme->next_scheme->scheme_name, - scheme->next_scheme->name_len)) - { - save_scheme = scheme->next_scheme->next_scheme; - - ruby_xfree(scheme->next_scheme->scheme_name); - ruby_xfree(scheme->next_scheme); - - scheme->next_scheme = save_scheme; - return Qtrue; - } - scheme = scheme->next_scheme; - } - return Qfalse; -} - -void rxml_init_input_callbacks(void) -{ - VALUE cInputCallbacks; - cInputCallbacks = rb_define_class_under(mXML, "InputCallbacks", rb_cObject); - - /* Class Methods */ - rb_define_singleton_method(cInputCallbacks, "register", input_callbacks_register_input_callbacks, 0); - rb_define_singleton_method(cInputCallbacks, "add_scheme", input_callbacks_add_scheme, 2); - rb_define_singleton_method(cInputCallbacks, "remove_scheme", input_callbacks_remove_scheme, 1); -} +/* Author: Martin Povolny (xpovolny@fi.muni.cz) */ + +#include "ruby_libxml.h" +#include "ruby_xml_input_cbg.h" + +/* Document-class: LibXML::XML::InputCallbacks + * + * Support for adding custom scheme handlers. */ + +static ic_scheme *first_scheme = 0; + +int ic_match(char const *filename) +{ + ic_scheme *scheme; + + //fprintf( stderr, "ic_match: %s\n", filename ); + + scheme = first_scheme; + while (0 != scheme) + { + if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len)) + { + return 1; + } + scheme = scheme->next_scheme; + } + return 0; +} + +void* ic_open(char const *filename) +{ + ic_doc_context *ic_doc; + ic_scheme *scheme; + VALUE res; + + scheme = first_scheme; + while (0 != scheme) + { + if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len)) + { + ic_doc = (ic_doc_context*) malloc(sizeof(ic_doc_context)); + + res = rb_funcall(scheme->class, rb_intern("document_query"), 1, + rb_str_new2(filename)); + + ic_doc->buffer = strdup(StringValuePtr(res)); + + ic_doc->bpos = ic_doc->buffer; + ic_doc->remaining = (int)strlen(ic_doc->buffer); + return ic_doc; + } + scheme = scheme->next_scheme; + } + return 0; +} + +int ic_read(void *context, char *buffer, int len) +{ + ic_doc_context *ic_doc; + int ret_len; + ic_doc = (ic_doc_context*) context; + + if (len >= ic_doc->remaining) + { + ret_len = ic_doc->remaining; + } + else + { + ret_len = len; + } + ic_doc->remaining -= ret_len; + strncpy(buffer, ic_doc->bpos, ret_len); + ic_doc->bpos += ret_len; + + return ret_len; +} + +int ic_close(void *context) +{ + ruby_xfree(((ic_doc_context*) context)->buffer); + ruby_xfree(context); + return 1; +} + +/* + * call-seq: + * register + * + * Register a new set of I/O callback for handling parser input. + */ +static VALUE input_callbacks_register_input_callbacks(VALUE self) +{ + xmlRegisterInputCallbacks(ic_match, ic_open, ic_read, ic_close); + return (Qtrue); +} + +/* + * call-seq: + * add_scheme + * + * No documentation available. + */ +static VALUE input_callbacks_add_scheme(VALUE self, VALUE scheme_name, + VALUE class) +{ + ic_scheme *scheme; + + Check_Type(scheme_name, T_STRING); + + scheme = (ic_scheme*) malloc(sizeof(ic_scheme)); + scheme->next_scheme = 0; + scheme->scheme_name = strdup(StringValuePtr(scheme_name)); /* TODO alloc, dealloc */ + scheme->name_len = (int)strlen(scheme->scheme_name); + scheme->class = class; /* TODO alloc, dealloc */ + + //fprintf( stderr, "registered: %s, %d, %s\n", scheme->scheme_name, scheme->name_len, scheme->class ); + + if (0 == first_scheme) + first_scheme = scheme; + else + { + ic_scheme *pos; + pos = first_scheme; + while (0 != pos->next_scheme) + pos = pos->next_scheme; + pos->next_scheme = scheme; + } + + return (Qtrue); +} + +/* + * call-seq: + * remove_scheme + * + * No documentation available. + */ +static VALUE input_callbacks_remove_scheme(VALUE self, VALUE scheme_name) +{ + char *name; + ic_scheme *save_scheme, *scheme; + + Check_Type(scheme_name, T_STRING); + name = StringValuePtr(scheme_name); + + if (0 == first_scheme) + return Qfalse; + + if (!strncmp(name, first_scheme->scheme_name, first_scheme->name_len)) + { + save_scheme = first_scheme->next_scheme; + + ruby_xfree(first_scheme->scheme_name); + ruby_xfree(first_scheme); + + first_scheme = save_scheme; + return Qtrue; + } + + scheme = first_scheme; + while (0 != scheme->next_scheme) + { + if (!strncmp(name, scheme->next_scheme->scheme_name, + scheme->next_scheme->name_len)) + { + save_scheme = scheme->next_scheme->next_scheme; + + ruby_xfree(scheme->next_scheme->scheme_name); + ruby_xfree(scheme->next_scheme); + + scheme->next_scheme = save_scheme; + return Qtrue; + } + scheme = scheme->next_scheme; + } + return Qfalse; +} + +void rxml_init_input_callbacks(void) +{ + VALUE cInputCallbacks; + cInputCallbacks = rb_define_class_under(mXML, "InputCallbacks", rb_cObject); + + /* Class Methods */ + rb_define_singleton_method(cInputCallbacks, "register", input_callbacks_register_input_callbacks, 0); + rb_define_singleton_method(cInputCallbacks, "add_scheme", input_callbacks_add_scheme, 2); + rb_define_singleton_method(cInputCallbacks, "remove_scheme", input_callbacks_remove_scheme, 1); +} diff --git a/ext/libxml/ruby_xml_namespace.c b/ext/libxml/ruby_xml_namespace.c index 43bf9de6..e4c71010 100644 --- a/ext/libxml/ruby_xml_namespace.c +++ b/ext/libxml/ruby_xml_namespace.c @@ -1,151 +1,151 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#include "ruby_libxml.h" -#include "ruby_xml_namespace.h" - -VALUE cXMLNamespace; - -/* Document-class: LibXML::XML::Namespace - * - * The Namespace class represents an XML namespace. - * To add a namespace to a node, create a new instance - * of this class. Note that this does *not* assign the - * node to the namespace. To do that see the - * XML::Namespaces#namespace method. - * - * Usage: - * - * node = XML::Node.new('') - * XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') - * assert_equal("", node.to_s) - * assert_nil(node.namespaces.namespace) - */ - -/* Namespaces are owned and freed by their nodes. Thus, its easier for the - ruby bindings to not manage attribute memory management. */ - -static VALUE rxml_namespace_alloc(VALUE klass) -{ - return Data_Wrap_Struct(klass, NULL, NULL, NULL); -} - -VALUE rxml_namespace_wrap(xmlNsPtr xns) -{ - return Data_Wrap_Struct(cXMLNamespace, NULL, NULL, xns); -} - - -/* - * call-seq: - * initialize(node, "prefix", "href") -> XML::Namespace - * - * Create a new namespace and adds it to the specified node. - * Note this does *not* assign the node to the namespace. - * To do that see the XML::Namespaces#namespace method. - */ -static VALUE rxml_namespace_initialize(VALUE self, VALUE node, VALUE prefix, - VALUE href) -{ - xmlNodePtr xnode; - xmlChar *xmlPrefix; - xmlNsPtr xns; - - Check_Type(node, T_DATA); - Data_Get_Struct(node, xmlNode, xnode); - xmlResetLastError(); - - /* Prefix can be null - that means its the default namespace */ - xmlPrefix = NIL_P(prefix) ? NULL : (xmlChar *)StringValuePtr(prefix); - xns = xmlNewNs(xnode, (xmlChar*) StringValuePtr(href), xmlPrefix); - - DATA_PTR(self) = xns; - return self; -} - -/* - * call-seq: - * ns.href -> "href" - * - * Usage: - * - * doc = XML::Document.string('') - * ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/') - * assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href) - */ -static VALUE rxml_namespace_href_get(VALUE self) -{ - xmlNsPtr xns; - Data_Get_Struct(self, xmlNs, xns); - if (xns->href == NULL) - return Qnil; - else - return rxml_new_cstr( xns->href, NULL); -} - -/* - * call-seq: - * ns.node_type -> num - * - * Obtain this namespace's type identifier. - */ -static VALUE rxml_namespace_node_type(VALUE self) -{ - xmlNsPtr xns; - Data_Get_Struct(self, xmlNs, xns); - return INT2NUM(xns->type); -} - -/* - * call-seq: - * ns.prefix -> "prefix" - * - * Obtain the namespace's prefix. - * - * Usage: - * - * doc = XML::Document.string('') - * ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/') - * assert_equal('soap', ns.prefix) - */ -static VALUE rxml_namespace_prefix_get(VALUE self) -{ - xmlNsPtr xns; - Data_Get_Struct(self, xmlNs, xns); - if (xns->prefix == NULL) - return Qnil; - else - return rxml_new_cstr( xns->prefix, NULL); -} - -/* - * call-seq: - * ns.next -> XML::Namespace - * - * Obtain the next namespace. - * - * Usage: - * - * doc = XML::Document.string('') - * ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/') - * assert_nil(ns.next) - */ -static VALUE rxml_namespace_next(VALUE self) -{ - xmlNsPtr xns; - Data_Get_Struct(self, xmlNs, xns); - if (xns == NULL || xns->next == NULL) - return (Qnil); - else - return rxml_namespace_wrap(xns->next); -} - -void rxml_init_namespace(void) -{ - cXMLNamespace = rb_define_class_under(mXML, "Namespace", rb_cObject); - rb_define_alloc_func(cXMLNamespace, rxml_namespace_alloc); - rb_define_method(cXMLNamespace, "initialize", rxml_namespace_initialize, 3); - rb_define_method(cXMLNamespace, "href", rxml_namespace_href_get, 0); - rb_define_method(cXMLNamespace, "next", rxml_namespace_next, 0); - rb_define_method(cXMLNamespace, "node_type", rxml_namespace_node_type, 0); - rb_define_method(cXMLNamespace, "prefix", rxml_namespace_prefix_get, 0); -} +/* Please see the LICENSE file for copyright and distribution information */ + +#include "ruby_libxml.h" +#include "ruby_xml_namespace.h" + +VALUE cXMLNamespace; + +/* Document-class: LibXML::XML::Namespace + * + * The Namespace class represents an XML namespace. + * To add a namespace to a node, create a new instance + * of this class. Note that this does *not* assign the + * node to the namespace. To do that see the + * XML::Namespaces#namespace method. + * + * Usage: + * + * node = XML::Node.new('') + * XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + * assert_equal("", node.to_s) + * assert_nil(node.namespaces.namespace) + */ + +/* Namespaces are owned and freed by their nodes. Thus, its easier for the + ruby bindings to not manage attribute memory management. */ + +static VALUE rxml_namespace_alloc(VALUE klass) +{ + return Data_Wrap_Struct(klass, NULL, NULL, NULL); +} + +VALUE rxml_namespace_wrap(xmlNsPtr xns) +{ + return Data_Wrap_Struct(cXMLNamespace, NULL, NULL, xns); +} + + +/* + * call-seq: + * initialize(node, "prefix", "href") -> XML::Namespace + * + * Create a new namespace and adds it to the specified node. + * Note this does *not* assign the node to the namespace. + * To do that see the XML::Namespaces#namespace method. + */ +static VALUE rxml_namespace_initialize(VALUE self, VALUE node, VALUE prefix, + VALUE href) +{ + xmlNodePtr xnode; + xmlChar *xmlPrefix; + xmlNsPtr xns; + + Check_Type(node, T_DATA); + Data_Get_Struct(node, xmlNode, xnode); + xmlResetLastError(); + + /* Prefix can be null - that means its the default namespace */ + xmlPrefix = NIL_P(prefix) ? NULL : (xmlChar *)StringValuePtr(prefix); + xns = xmlNewNs(xnode, (xmlChar*) StringValuePtr(href), xmlPrefix); + + DATA_PTR(self) = xns; + return self; +} + +/* + * call-seq: + * ns.href -> "href" + * + * Usage: + * + * doc = XML::Document.string('') + * ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/') + * assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href) + */ +static VALUE rxml_namespace_href_get(VALUE self) +{ + xmlNsPtr xns; + Data_Get_Struct(self, xmlNs, xns); + if (xns->href == NULL) + return Qnil; + else + return rxml_new_cstr( xns->href, NULL); +} + +/* + * call-seq: + * ns.node_type -> num + * + * Obtain this namespace's type identifier. + */ +static VALUE rxml_namespace_node_type(VALUE self) +{ + xmlNsPtr xns; + Data_Get_Struct(self, xmlNs, xns); + return INT2NUM(xns->type); +} + +/* + * call-seq: + * ns.prefix -> "prefix" + * + * Obtain the namespace's prefix. + * + * Usage: + * + * doc = XML::Document.string('') + * ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/') + * assert_equal('soap', ns.prefix) + */ +static VALUE rxml_namespace_prefix_get(VALUE self) +{ + xmlNsPtr xns; + Data_Get_Struct(self, xmlNs, xns); + if (xns->prefix == NULL) + return Qnil; + else + return rxml_new_cstr( xns->prefix, NULL); +} + +/* + * call-seq: + * ns.next -> XML::Namespace + * + * Obtain the next namespace. + * + * Usage: + * + * doc = XML::Document.string('') + * ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/') + * assert_nil(ns.next) + */ +static VALUE rxml_namespace_next(VALUE self) +{ + xmlNsPtr xns; + Data_Get_Struct(self, xmlNs, xns); + if (xns == NULL || xns->next == NULL) + return (Qnil); + else + return rxml_namespace_wrap(xns->next); +} + +void rxml_init_namespace(void) +{ + cXMLNamespace = rb_define_class_under(mXML, "Namespace", rb_cObject); + rb_define_alloc_func(cXMLNamespace, rxml_namespace_alloc); + rb_define_method(cXMLNamespace, "initialize", rxml_namespace_initialize, 3); + rb_define_method(cXMLNamespace, "href", rxml_namespace_href_get, 0); + rb_define_method(cXMLNamespace, "next", rxml_namespace_next, 0); + rb_define_method(cXMLNamespace, "node_type", rxml_namespace_node_type, 0); + rb_define_method(cXMLNamespace, "prefix", rxml_namespace_prefix_get, 0); +} diff --git a/ext/libxml/ruby_xml_parser.h b/ext/libxml/ruby_xml_parser.h index cba7fbde..19fa1c0b 100644 --- a/ext/libxml/ruby_xml_parser.h +++ b/ext/libxml/ruby_xml_parser.h @@ -1,10 +1,10 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#ifndef __RXML_PARSER__ -#define __RXML_PARSER__ - -extern VALUE cXMLParser; - -void rxml_init_parser(void); - -#endif +/* Please see the LICENSE file for copyright and distribution information */ + +#ifndef __RXML_PARSER__ +#define __RXML_PARSER__ + +extern VALUE cXMLParser; + +void rxml_init_parser(void); + +#endif diff --git a/ext/libxml/ruby_xml_parser_context.c b/ext/libxml/ruby_xml_parser_context.c index 45ea1d7b..d9703a76 100644 --- a/ext/libxml/ruby_xml_parser_context.c +++ b/ext/libxml/ruby_xml_parser_context.c @@ -1,1009 +1,1009 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#include "ruby_libxml.h" -#include "ruby_xml_parser_context.h" - -#include - -VALUE cXMLParserContext; -static ID IO_ATTR; - -/* - * Document-class: LibXML::XML::Parser::Context - * - * The XML::Parser::Context class provides in-depth control over how - * a document is parsed. - */ - -static void rxml_parser_context_free(xmlParserCtxtPtr ctxt) -{ - xmlFreeParserCtxt(ctxt); -} - -static VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt) -{ - return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free, ctxt); -} - - -static VALUE rxml_parser_context_alloc(VALUE klass) -{ - xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); - return Data_Wrap_Struct(klass, NULL, rxml_parser_context_free, ctxt); -} - -/* call-seq: - * XML::Parser::Context.document(document) -> XML::Parser::Context - * - * Creates a new parser context based on the specified document. - * - * Parameters: - * - * document - An XML::Document instance - * options - A or'ed together list of LibXML::XML::Parser::Options values - */ -static VALUE rxml_parser_context_document(int argc, VALUE* argv, VALUE klass) -{ - VALUE document, options; - rb_scan_args(argc, argv, "11", &document, &options); - - if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse) - rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object"); - - xmlDocPtr xdoc; - xmlChar *buffer; - int length; - Data_Get_Struct(document, xmlDoc, xdoc); - xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0); - - xmlParserCtxtPtr ctxt = xmlCreateDocParserCtxt(buffer); - - if (!ctxt) - rxml_raise(xmlGetLastError()); - - /* This is annoying, but xmlInitParserCtxt (called indirectly above) and - xmlCtxtUseOptionsInternal (called below) initialize slightly different - context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt - sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ - xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); - - return rxml_parser_context_wrap(ctxt); -} - -/* call-seq: - * XML::Parser::Context.file(file) -> XML::Parser::Context - * - * Creates a new parser context based on the specified file or uri. - * - * Parameters: - * - * file - A filename or uri - * options - A or'ed together list of LibXML::XML::Parser::Options values -*/ -static VALUE rxml_parser_context_file(int argc, VALUE* argv, VALUE klass) -{ - VALUE file, options; - rb_scan_args(argc, argv, "11", &file, &options); - - xmlParserCtxtPtr ctxt = xmlCreateURLParserCtxt(StringValuePtr(file), 0); - - if (!ctxt) - rxml_raise(xmlGetLastError()); - - /* This is annoying, but xmlInitParserCtxt (called indirectly above) and - xmlCtxtUseOptionsInternal (called below) initialize slightly different - context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt - sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ - xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); - - return rxml_parser_context_wrap(ctxt); -} - -/* call-seq: - * XML::Parser::Context.string(string) -> XML::Parser::Context - * - * Creates a new parser context based on the specified string. - * - * Parameters: - * - * string - A string that contains the data to parse - * options - A or'ed together list of LibXML::XML::Parser::Options values -*/ -static VALUE rxml_parser_context_string(int argc, VALUE* argv, VALUE klass) -{ - VALUE string, options; - rb_scan_args(argc, argv, "11", &string, &options); - - Check_Type(string, T_STRING); - - if (RSTRING_LEN(string) == 0) - rb_raise(rb_eArgError, "Must specify a string with one or more characters"); - - xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string), (int)RSTRING_LEN(string)); - - if (!ctxt) - rxml_raise(xmlGetLastError()); - - /* This is annoying, but xmlInitParserCtxt (called indirectly above) and - xmlCtxtUseOptionsInternal (called below) initialize slightly different - context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt - sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ - xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); - - return rxml_parser_context_wrap(ctxt); -} - -/* call-seq: - * XML::Parser::Context.io(io) -> XML::Parser::Context - * - * Creates a new parser context based on the specified io object. - * - * Parameters: - * - * io - A ruby IO object - * options - A or'ed together list of LibXML::XML::Parser::Options values -*/ -static VALUE rxml_parser_context_io(int argc, VALUE* argv, VALUE klass) -{ - VALUE io, options; - rb_scan_args(argc, argv, "11", &io, &options); - - if (NIL_P(io)) - rb_raise(rb_eTypeError, "Must pass in an IO object"); - - xmlParserInputBufferPtr input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL, - (void*)io, XML_CHAR_ENCODING_NONE); - - xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); - - if (!ctxt) - { - xmlFreeParserInputBuffer(input); - rxml_raise(xmlGetLastError()); - } - - /* This is annoying, but xmlInitParserCtxt (called indirectly above) and - xmlCtxtUseOptionsInternal (called below) initialize slightly different - context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt - sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ - xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); - - xmlParserInputPtr stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); - - if (!stream) - { - xmlFreeParserInputBuffer(input); - xmlFreeParserCtxt(ctxt); - rxml_raise(xmlGetLastError()); - } - inputPush(ctxt, stream); - VALUE result = rxml_parser_context_wrap(ctxt); - - /* Attach io object to parser so it won't get freed.*/ - rb_ivar_set(result, IO_ATTR, io); - - return result; -} - -/* - * call-seq: - * context.base_uri -> "http:://libxml.org" - * - * Obtain the base url for this parser context. - */ -static VALUE rxml_parser_context_base_uri_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->input && ctxt->input->filename) - return rxml_new_cstr((const xmlChar*)ctxt->input->filename, ctxt->encoding); - else - return Qnil; -} - -/* - * call-seq: - * context.base_uri = "http:://libxml.org" - * - * Sets the base url for this parser context. - */ -static VALUE rxml_parser_context_base_uri_set(VALUE self, VALUE url) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - Check_Type(url, T_STRING); - - if (ctxt->input && !ctxt->input->filename) - { - const char* xurl = StringValuePtr(url); - ctxt->input->filename = (const char*)xmlStrdup((const xmlChar*)xurl); - } - return self; -} - -/* - * call-seq: - * context.close -> nil - * - * Closes the underlying input streams. This is useful when parsing a large amount of - * files and you want to close the files without relying on Ruby's garbage collector - * to run. - */ -static VALUE rxml_parser_context_close(VALUE self) -{ - xmlParserCtxtPtr ctxt; - xmlParserInputPtr xinput; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - while ((xinput = inputPop(ctxt)) != NULL) - { - xmlFreeInputStream(xinput); - } - return Qnil; -} - -/* - * call-seq: - * context.data_directory -> "dir" - * - * Obtain the data directory associated with this context. - */ -static VALUE rxml_parser_context_data_directory_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->directory == NULL) - return (Qnil); - else - return (rxml_new_cstr((const xmlChar*)ctxt->directory, ctxt->encoding)); -} - -/* - * call-seq: - * context.depth -> num - * - * Obtain the depth of this context. - */ -static VALUE rxml_parser_context_depth_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->depth)); -} - -/* - * call-seq: - * context.disable_cdata? -> (true|false) - * - * Determine whether CDATA nodes will be created in this context. - */ -static VALUE rxml_parser_context_disable_cdata_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - /* LibXML controls this internally with the default SAX handler. */ - if (ctxt->sax && ctxt->sax->cdataBlock) - return (Qfalse); - else - return (Qtrue); -} - -/* - * call-seq: - * context.disable_cdata = (true|false) - * - * Control whether CDATA nodes will be created in this context. - */ -static VALUE rxml_parser_context_disable_cdata_set(VALUE self, VALUE value) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->sax == NULL) - rb_raise(rb_eRuntimeError, "Sax handler is not yet set"); - - /* LibXML controls this internally with the default SAX handler. */ - if (value) - ctxt->sax->cdataBlock = NULL; - else - ctxt->sax->cdataBlock = xmlSAX2CDataBlock; - - return value; -} - -/* - * call-seq: - * context.disable_sax? -> (true|false) - * - * Determine whether SAX-based processing is disabled - * in this context. - */ -static VALUE rxml_parser_context_disable_sax_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->disableSAX) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.docbook? -> (true|false) - * - * Determine whether this is a docbook context. - */ -static VALUE rxml_parser_context_docbook_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->html == 2) // TODO check this - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.encoding -> XML::Encoding::UTF_8 - * - * Obtain the character encoding identifier used in - * this context. - */ -static VALUE rxml_parser_context_encoding_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - return INT2NUM(xmlParseCharEncoding((const char*)ctxt->encoding)); -} - -/* - * call-seq: - * context.encoding = XML::Encoding::UTF_8 - * - * Sets the character encoding for this context. - */ -static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding) -{ - xmlParserCtxtPtr ctxt; - int result; - const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding)); - xmlCharEncodingHandlerPtr hdlr = xmlFindCharEncodingHandler(xencoding); - - if (!hdlr) - rb_raise(rb_eArgError, "Unknown encoding: %i", NUM2INT(encoding)); - - Data_Get_Struct(self, xmlParserCtxt, ctxt); - result = xmlSwitchToEncoding(ctxt, hdlr); - - if (result != 0) - rxml_raise(xmlGetLastError()); - - if (ctxt->encoding != NULL) - xmlFree((xmlChar *) ctxt->encoding); - - ctxt->encoding = xmlStrdup((const xmlChar *) xencoding); - return self; -} - -/* - * call-seq: - * context.errno -> num - * - * Obtain the last-error number in this context. - */ -static VALUE rxml_parser_context_errno_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->errNo)); -} - -/* - * call-seq: - * context.html? -> (true|false) - * - * Determine whether this is an html context. - */ -static VALUE rxml_parser_context_html_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->html == 1) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.max_num_streams -> num - * - * Obtain the limit on the number of IO streams opened in - * this context. - */ -static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self) -{ - // TODO alias to max_streams and dep this? - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->inputMax)); -} - -/* - * call-seq: - * context.num_streams -> "dir" - * - * Obtain the actual number of IO streams in this - * context. - */ -static VALUE rxml_parser_context_io_num_streams_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->inputNr)); -} - -/* - * call-seq: - * context.keep_blanks? -> (true|false) - * - * Determine whether parsers in this context retain - * whitespace. - */ -static VALUE rxml_parser_context_keep_blanks_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->keepBlanks) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.name_depth -> num - * - * Obtain the name depth for this context. - */ -static VALUE rxml_parser_context_name_depth_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->nameNr)); -} - -/* - * call-seq: - * context.name_depth_max -> num - * - * Obtain the maximum name depth for this context. - */ -static VALUE rxml_parser_context_name_depth_max_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->nameMax)); -} - -/* - * call-seq: - * context.name_node -> "name" - * - * Obtain the name node for this context. - */ -static VALUE rxml_parser_context_name_node_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->name == NULL) - return (Qnil); - else - return (rxml_new_cstr( ctxt->name, ctxt->encoding)); -} - -/* - * call-seq: - * context.name_tab -> ["name", ..., "name"] - * - * Obtain the name table for this context. - */ -static VALUE rxml_parser_context_name_tab_get(VALUE self) -{ - int i; - xmlParserCtxtPtr ctxt; - VALUE tab_ary; - - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->nameTab == NULL) - return (Qnil); - - tab_ary = rb_ary_new(); - - for (i = (ctxt->nameNr - 1); i >= 0; i--) - { - if (ctxt->nameTab[i] == NULL) - continue; - else - rb_ary_push(tab_ary, rxml_new_cstr( ctxt->nameTab[i], ctxt->encoding)); - } - - return (tab_ary); -} - -/* - * call-seq: - * context.node_depth -> num - * - * Obtain the node depth for this context. - */ -static VALUE rxml_parser_context_node_depth_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->nodeNr)); -} - -/* - * call-seq: - * context.node -> node - * - * Obtain the root node of this context. - */ -static VALUE rxml_parser_context_node_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->node == NULL) - return (Qnil); - else - return (rxml_node_wrap(ctxt->node)); -} - -/* - * call-seq: - * context.node_depth_max -> num - * - * Obtain the maximum node depth for this context. - */ -static VALUE rxml_parser_context_node_depth_max_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->nodeMax)); -} - -/* - * call-seq: - * context.num_chars -> num - * - * Obtain the number of characters in this context. - */ -static VALUE rxml_parser_context_num_chars_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (LONG2NUM(ctxt->nbChars)); -} - - -/* - * call-seq: - * context.options > XML::Parser::Options::NOENT - * - * Returns the parser options for this context. Multiple - * options can be combined by using Bitwise OR (|). - */ -static VALUE rxml_parser_context_options_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return INT2NUM(ctxt->options); -} - -/* - * call-seq: - * context.options = XML::Parser::Options::NOENT | - XML::Parser::Options::NOCDATA - * - * Provides control over the execution of a parser. Valid values - * are the constants defined on XML::Parser::Options. Multiple - * options can be combined by using Bitwise OR (|). - */ -static VALUE rxml_parser_context_options_set(VALUE self, VALUE options) -{ - xmlParserCtxtPtr ctxt; - Check_Type(options, T_FIXNUM); - - Data_Get_Struct(self, xmlParserCtxt, ctxt); - xmlCtxtUseOptions(ctxt, NUM2INT(options)); - - return self; -} - -/* - * call-seq: - * context.recovery? -> (true|false) - * - * Determine whether recovery mode is enabled in this - * context. - */ -static VALUE rxml_parser_context_recovery_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->recovery) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.recovery = true|false - * - * Control whether recovery mode is enabled in this - * context. - */ -static VALUE rxml_parser_context_recovery_set(VALUE self, VALUE value) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (value == Qfalse) - { - ctxt->recovery = 0; - return (Qfalse); - } - else - { - ctxt->recovery = 1; - return (Qtrue); - } -} - -/* - * call-seq: - * context.replace_entities? -> (true|false) - * - * Determine whether external entity replacement is enabled in this - * context. - */ -static VALUE rxml_parser_context_replace_entities_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->replaceEntities) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.replace_entities = true|false - * - * Control whether external entity replacement is enabled in this - * context. - */ -static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE value) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (value == Qfalse) - { - ctxt->replaceEntities = 0; - return (Qfalse); - } - else - { - ctxt->replaceEntities = 1; - return (Qtrue); - } -} - -/* - * call-seq: - * context.space_depth -> num - * - * Obtain the space depth for this context. - */ -static VALUE rxml_parser_context_space_depth_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->spaceNr)); -} - -/* - * call-seq: - * context.space_depth -> num - * - * Obtain the maximum space depth for this context. - */ -static VALUE rxml_parser_context_space_depth_max_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - return (INT2NUM(ctxt->spaceMax)); -} - -/* - * call-seq: - * context.subset_external? -> (true|false) - * - * Determine whether this context is a subset of an - * external context. - */ -static VALUE rxml_parser_context_subset_external_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->inSubset == 2) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.subset_internal? -> (true|false) - * - * Determine whether this context is a subset of an - * internal context. - */ -static VALUE rxml_parser_context_subset_internal_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->inSubset == 1) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.subset_internal_name -> "name" - * - * Obtain this context's subset name (valid only if - * either of subset_external? or subset_internal? - * is true). - */ -static VALUE rxml_parser_context_subset_name_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->intSubName == NULL) - return (Qnil); - else - return (rxml_new_cstr(ctxt->intSubName, ctxt->encoding)); -} - -/* - * call-seq: - * context.subset_external_uri -> "uri" - * - * Obtain this context's external subset URI. (valid only if - * either of subset_external? or subset_internal? - * is true). - */ -static VALUE rxml_parser_context_subset_external_uri_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->extSubURI == NULL) - return (Qnil); - else - return (rxml_new_cstr( ctxt->extSubURI, ctxt->encoding)); -} - -/* - * call-seq: - * context.subset_external_system_id -> "system_id" - * - * Obtain this context's external subset system identifier. - * (valid only if either of subset_external? or subset_internal? - * is true). - */ -static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->extSubSystem == NULL) - return (Qnil); - else - return (rxml_new_cstr( ctxt->extSubSystem, ctxt->encoding)); -} - -/* - * call-seq: - * context.standalone? -> (true|false) - * - * Determine whether this is a standalone context. - */ -static VALUE rxml_parser_context_standalone_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->standalone) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.stats? -> (true|false) - * - * Determine whether this context maintains statistics. - */ -static VALUE rxml_parser_context_stats_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->record_info) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.valid? -> (true|false) - * - * Determine whether this context is valid. - */ -static VALUE rxml_parser_context_valid_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->valid) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.validate? -> (true|false) - * - * Determine whether validation is enabled in this context. - */ -static VALUE rxml_parser_context_validate_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->validate) - return (Qtrue); - else - return (Qfalse); -} - -/* - * call-seq: - * context.version -> "version" - * - * Obtain this context's version identifier. - */ -static VALUE rxml_parser_context_version_get(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->version == NULL) - return (Qnil); - else - return (rxml_new_cstr( ctxt->version, ctxt->encoding)); -} - -/* - * call-seq: - * context.well_formed? -> (true|false) - * - * Determine whether this context contains well-formed XML. - */ -static VALUE rxml_parser_context_well_formed_q(VALUE self) -{ - xmlParserCtxtPtr ctxt; - Data_Get_Struct(self, xmlParserCtxt, ctxt); - - if (ctxt->wellFormed) - return (Qtrue); - else - return (Qfalse); -} - -void rxml_init_parser_context(void) -{ - IO_ATTR = ID2SYM(rb_intern("@io")); - - cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject); - rb_define_alloc_func(cXMLParserContext, rxml_parser_context_alloc); - - rb_define_singleton_method(cXMLParserContext, "document", rxml_parser_context_document, -1); - rb_define_singleton_method(cXMLParserContext, "file", rxml_parser_context_file, -1); - rb_define_singleton_method(cXMLParserContext, "io", rxml_parser_context_io, -1); - rb_define_singleton_method(cXMLParserContext, "string", rxml_parser_context_string, -1); - - rb_define_method(cXMLParserContext, "base_uri", rxml_parser_context_base_uri_get, 0); - rb_define_method(cXMLParserContext, "base_uri=", rxml_parser_context_base_uri_set, 1); - rb_define_method(cXMLParserContext, "close", rxml_parser_context_close, 0); - rb_define_method(cXMLParserContext, "data_directory", rxml_parser_context_data_directory_get, 0); - rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0); - rb_define_method(cXMLParserContext, "disable_cdata?", rxml_parser_context_disable_cdata_q, 0); - rb_define_method(cXMLParserContext, "disable_cdata=", rxml_parser_context_disable_cdata_set, 1); - rb_define_method(cXMLParserContext, "disable_sax?", rxml_parser_context_disable_sax_q, 0); - rb_define_method(cXMLParserContext, "docbook?", rxml_parser_context_docbook_q, 0); - rb_define_method(cXMLParserContext, "encoding", rxml_parser_context_encoding_get, 0); - rb_define_method(cXMLParserContext, "encoding=", rxml_parser_context_encoding_set, 1); - rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0); - rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0); - rb_define_method(cXMLParserContext, "io_max_num_streams", rxml_parser_context_io_max_num_streams_get, 0); - rb_define_method(cXMLParserContext, "io_num_streams", rxml_parser_context_io_num_streams_get, 0); - rb_define_method(cXMLParserContext, "keep_blanks?", rxml_parser_context_keep_blanks_q, 0); - rb_define_method(cXMLParserContext, "name_node", rxml_parser_context_name_node_get, 0); - rb_define_method(cXMLParserContext, "name_depth", rxml_parser_context_name_depth_get, 0); - rb_define_method(cXMLParserContext, "name_depth_max", rxml_parser_context_name_depth_max_get, 0); - rb_define_method(cXMLParserContext, "name_tab", rxml_parser_context_name_tab_get, 0); - rb_define_method(cXMLParserContext, "node", rxml_parser_context_node_get, 0); - rb_define_method(cXMLParserContext, "node_depth", rxml_parser_context_node_depth_get, 0); - rb_define_method(cXMLParserContext, "node_depth_max", rxml_parser_context_node_depth_max_get, 0); - rb_define_method(cXMLParserContext, "num_chars", rxml_parser_context_num_chars_get, 0); - rb_define_method(cXMLParserContext, "options", rxml_parser_context_options_get, 0); - rb_define_method(cXMLParserContext, "options=", rxml_parser_context_options_set, 1); - rb_define_method(cXMLParserContext, "recovery?", rxml_parser_context_recovery_q, 0); - rb_define_method(cXMLParserContext, "recovery=", rxml_parser_context_recovery_set, 1); - rb_define_method(cXMLParserContext, "replace_entities?", rxml_parser_context_replace_entities_q, 0); - rb_define_method(cXMLParserContext, "replace_entities=", rxml_parser_context_replace_entities_set, 1); - rb_define_method(cXMLParserContext, "space_depth", rxml_parser_context_space_depth_get, 0); - rb_define_method(cXMLParserContext, "space_depth_max", rxml_parser_context_space_depth_max_get, 0); - rb_define_method(cXMLParserContext, "subset_external?", rxml_parser_context_subset_external_q, 0); - rb_define_method(cXMLParserContext, "subset_external_system_id", rxml_parser_context_subset_external_system_id_get, 0); - rb_define_method(cXMLParserContext, "subset_external_uri", rxml_parser_context_subset_external_uri_get, 0); - rb_define_method(cXMLParserContext, "subset_internal?", rxml_parser_context_subset_internal_q, 0); - rb_define_method(cXMLParserContext, "subset_internal_name", rxml_parser_context_subset_name_get, 0); - rb_define_method(cXMLParserContext, "stats?", rxml_parser_context_stats_q, 0); - rb_define_method(cXMLParserContext, "standalone?", rxml_parser_context_standalone_q, 0); - rb_define_method(cXMLParserContext, "valid", rxml_parser_context_valid_q, 0); - rb_define_method(cXMLParserContext, "validate?", rxml_parser_context_validate_q, 0); - rb_define_method(cXMLParserContext, "version", rxml_parser_context_version_get, 0); - rb_define_method(cXMLParserContext, "well_formed?", rxml_parser_context_well_formed_q, 0); -} +/* Please see the LICENSE file for copyright and distribution information */ + +#include "ruby_libxml.h" +#include "ruby_xml_parser_context.h" + +#include + +VALUE cXMLParserContext; +static ID IO_ATTR; + +/* + * Document-class: LibXML::XML::Parser::Context + * + * The XML::Parser::Context class provides in-depth control over how + * a document is parsed. + */ + +static void rxml_parser_context_free(xmlParserCtxtPtr ctxt) +{ + xmlFreeParserCtxt(ctxt); +} + +static VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt) +{ + return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free, ctxt); +} + + +static VALUE rxml_parser_context_alloc(VALUE klass) +{ + xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); + return Data_Wrap_Struct(klass, NULL, rxml_parser_context_free, ctxt); +} + +/* call-seq: + * XML::Parser::Context.document(document) -> XML::Parser::Context + * + * Creates a new parser context based on the specified document. + * + * Parameters: + * + * document - An XML::Document instance + * options - A or'ed together list of LibXML::XML::Parser::Options values + */ +static VALUE rxml_parser_context_document(int argc, VALUE* argv, VALUE klass) +{ + VALUE document, options; + rb_scan_args(argc, argv, "11", &document, &options); + + if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse) + rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object"); + + xmlDocPtr xdoc; + xmlChar *buffer; + int length; + Data_Get_Struct(document, xmlDoc, xdoc); + xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0); + + xmlParserCtxtPtr ctxt = xmlCreateDocParserCtxt(buffer); + + if (!ctxt) + rxml_raise(xmlGetLastError()); + + /* This is annoying, but xmlInitParserCtxt (called indirectly above) and + xmlCtxtUseOptionsInternal (called below) initialize slightly different + context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt + sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ + xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); + + return rxml_parser_context_wrap(ctxt); +} + +/* call-seq: + * XML::Parser::Context.file(file) -> XML::Parser::Context + * + * Creates a new parser context based on the specified file or uri. + * + * Parameters: + * + * file - A filename or uri + * options - A or'ed together list of LibXML::XML::Parser::Options values +*/ +static VALUE rxml_parser_context_file(int argc, VALUE* argv, VALUE klass) +{ + VALUE file, options; + rb_scan_args(argc, argv, "11", &file, &options); + + xmlParserCtxtPtr ctxt = xmlCreateURLParserCtxt(StringValuePtr(file), 0); + + if (!ctxt) + rxml_raise(xmlGetLastError()); + + /* This is annoying, but xmlInitParserCtxt (called indirectly above) and + xmlCtxtUseOptionsInternal (called below) initialize slightly different + context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt + sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ + xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); + + return rxml_parser_context_wrap(ctxt); +} + +/* call-seq: + * XML::Parser::Context.string(string) -> XML::Parser::Context + * + * Creates a new parser context based on the specified string. + * + * Parameters: + * + * string - A string that contains the data to parse + * options - A or'ed together list of LibXML::XML::Parser::Options values +*/ +static VALUE rxml_parser_context_string(int argc, VALUE* argv, VALUE klass) +{ + VALUE string, options; + rb_scan_args(argc, argv, "11", &string, &options); + + Check_Type(string, T_STRING); + + if (RSTRING_LEN(string) == 0) + rb_raise(rb_eArgError, "Must specify a string with one or more characters"); + + xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string), (int)RSTRING_LEN(string)); + + if (!ctxt) + rxml_raise(xmlGetLastError()); + + /* This is annoying, but xmlInitParserCtxt (called indirectly above) and + xmlCtxtUseOptionsInternal (called below) initialize slightly different + context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt + sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ + xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); + + return rxml_parser_context_wrap(ctxt); +} + +/* call-seq: + * XML::Parser::Context.io(io) -> XML::Parser::Context + * + * Creates a new parser context based on the specified io object. + * + * Parameters: + * + * io - A ruby IO object + * options - A or'ed together list of LibXML::XML::Parser::Options values +*/ +static VALUE rxml_parser_context_io(int argc, VALUE* argv, VALUE klass) +{ + VALUE io, options; + rb_scan_args(argc, argv, "11", &io, &options); + + if (NIL_P(io)) + rb_raise(rb_eTypeError, "Must pass in an IO object"); + + xmlParserInputBufferPtr input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL, + (void*)io, XML_CHAR_ENCODING_NONE); + + xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); + + if (!ctxt) + { + xmlFreeParserInputBuffer(input); + rxml_raise(xmlGetLastError()); + } + + /* This is annoying, but xmlInitParserCtxt (called indirectly above) and + xmlCtxtUseOptionsInternal (called below) initialize slightly different + context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt + sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */ + xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options)); + + xmlParserInputPtr stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); + + if (!stream) + { + xmlFreeParserInputBuffer(input); + xmlFreeParserCtxt(ctxt); + rxml_raise(xmlGetLastError()); + } + inputPush(ctxt, stream); + VALUE result = rxml_parser_context_wrap(ctxt); + + /* Attach io object to parser so it won't get freed.*/ + rb_ivar_set(result, IO_ATTR, io); + + return result; +} + +/* + * call-seq: + * context.base_uri -> "http:://libxml.org" + * + * Obtain the base url for this parser context. + */ +static VALUE rxml_parser_context_base_uri_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->input && ctxt->input->filename) + return rxml_new_cstr((const xmlChar*)ctxt->input->filename, ctxt->encoding); + else + return Qnil; +} + +/* + * call-seq: + * context.base_uri = "http:://libxml.org" + * + * Sets the base url for this parser context. + */ +static VALUE rxml_parser_context_base_uri_set(VALUE self, VALUE url) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + Check_Type(url, T_STRING); + + if (ctxt->input && !ctxt->input->filename) + { + const char* xurl = StringValuePtr(url); + ctxt->input->filename = (const char*)xmlStrdup((const xmlChar*)xurl); + } + return self; +} + +/* + * call-seq: + * context.close -> nil + * + * Closes the underlying input streams. This is useful when parsing a large amount of + * files and you want to close the files without relying on Ruby's garbage collector + * to run. + */ +static VALUE rxml_parser_context_close(VALUE self) +{ + xmlParserCtxtPtr ctxt; + xmlParserInputPtr xinput; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + while ((xinput = inputPop(ctxt)) != NULL) + { + xmlFreeInputStream(xinput); + } + return Qnil; +} + +/* + * call-seq: + * context.data_directory -> "dir" + * + * Obtain the data directory associated with this context. + */ +static VALUE rxml_parser_context_data_directory_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->directory == NULL) + return (Qnil); + else + return (rxml_new_cstr((const xmlChar*)ctxt->directory, ctxt->encoding)); +} + +/* + * call-seq: + * context.depth -> num + * + * Obtain the depth of this context. + */ +static VALUE rxml_parser_context_depth_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->depth)); +} + +/* + * call-seq: + * context.disable_cdata? -> (true|false) + * + * Determine whether CDATA nodes will be created in this context. + */ +static VALUE rxml_parser_context_disable_cdata_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + /* LibXML controls this internally with the default SAX handler. */ + if (ctxt->sax && ctxt->sax->cdataBlock) + return (Qfalse); + else + return (Qtrue); +} + +/* + * call-seq: + * context.disable_cdata = (true|false) + * + * Control whether CDATA nodes will be created in this context. + */ +static VALUE rxml_parser_context_disable_cdata_set(VALUE self, VALUE value) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->sax == NULL) + rb_raise(rb_eRuntimeError, "Sax handler is not yet set"); + + /* LibXML controls this internally with the default SAX handler. */ + if (value) + ctxt->sax->cdataBlock = NULL; + else + ctxt->sax->cdataBlock = xmlSAX2CDataBlock; + + return value; +} + +/* + * call-seq: + * context.disable_sax? -> (true|false) + * + * Determine whether SAX-based processing is disabled + * in this context. + */ +static VALUE rxml_parser_context_disable_sax_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->disableSAX) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.docbook? -> (true|false) + * + * Determine whether this is a docbook context. + */ +static VALUE rxml_parser_context_docbook_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->html == 2) // TODO check this + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.encoding -> XML::Encoding::UTF_8 + * + * Obtain the character encoding identifier used in + * this context. + */ +static VALUE rxml_parser_context_encoding_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + return INT2NUM(xmlParseCharEncoding((const char*)ctxt->encoding)); +} + +/* + * call-seq: + * context.encoding = XML::Encoding::UTF_8 + * + * Sets the character encoding for this context. + */ +static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding) +{ + xmlParserCtxtPtr ctxt; + int result; + const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding)); + xmlCharEncodingHandlerPtr hdlr = xmlFindCharEncodingHandler(xencoding); + + if (!hdlr) + rb_raise(rb_eArgError, "Unknown encoding: %i", NUM2INT(encoding)); + + Data_Get_Struct(self, xmlParserCtxt, ctxt); + result = xmlSwitchToEncoding(ctxt, hdlr); + + if (result != 0) + rxml_raise(xmlGetLastError()); + + if (ctxt->encoding != NULL) + xmlFree((xmlChar *) ctxt->encoding); + + ctxt->encoding = xmlStrdup((const xmlChar *) xencoding); + return self; +} + +/* + * call-seq: + * context.errno -> num + * + * Obtain the last-error number in this context. + */ +static VALUE rxml_parser_context_errno_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->errNo)); +} + +/* + * call-seq: + * context.html? -> (true|false) + * + * Determine whether this is an html context. + */ +static VALUE rxml_parser_context_html_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->html == 1) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.max_num_streams -> num + * + * Obtain the limit on the number of IO streams opened in + * this context. + */ +static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self) +{ + // TODO alias to max_streams and dep this? + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->inputMax)); +} + +/* + * call-seq: + * context.num_streams -> "dir" + * + * Obtain the actual number of IO streams in this + * context. + */ +static VALUE rxml_parser_context_io_num_streams_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->inputNr)); +} + +/* + * call-seq: + * context.keep_blanks? -> (true|false) + * + * Determine whether parsers in this context retain + * whitespace. + */ +static VALUE rxml_parser_context_keep_blanks_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->keepBlanks) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.name_depth -> num + * + * Obtain the name depth for this context. + */ +static VALUE rxml_parser_context_name_depth_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->nameNr)); +} + +/* + * call-seq: + * context.name_depth_max -> num + * + * Obtain the maximum name depth for this context. + */ +static VALUE rxml_parser_context_name_depth_max_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->nameMax)); +} + +/* + * call-seq: + * context.name_node -> "name" + * + * Obtain the name node for this context. + */ +static VALUE rxml_parser_context_name_node_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->name == NULL) + return (Qnil); + else + return (rxml_new_cstr( ctxt->name, ctxt->encoding)); +} + +/* + * call-seq: + * context.name_tab -> ["name", ..., "name"] + * + * Obtain the name table for this context. + */ +static VALUE rxml_parser_context_name_tab_get(VALUE self) +{ + int i; + xmlParserCtxtPtr ctxt; + VALUE tab_ary; + + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->nameTab == NULL) + return (Qnil); + + tab_ary = rb_ary_new(); + + for (i = (ctxt->nameNr - 1); i >= 0; i--) + { + if (ctxt->nameTab[i] == NULL) + continue; + else + rb_ary_push(tab_ary, rxml_new_cstr( ctxt->nameTab[i], ctxt->encoding)); + } + + return (tab_ary); +} + +/* + * call-seq: + * context.node_depth -> num + * + * Obtain the node depth for this context. + */ +static VALUE rxml_parser_context_node_depth_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->nodeNr)); +} + +/* + * call-seq: + * context.node -> node + * + * Obtain the root node of this context. + */ +static VALUE rxml_parser_context_node_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->node == NULL) + return (Qnil); + else + return (rxml_node_wrap(ctxt->node)); +} + +/* + * call-seq: + * context.node_depth_max -> num + * + * Obtain the maximum node depth for this context. + */ +static VALUE rxml_parser_context_node_depth_max_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->nodeMax)); +} + +/* + * call-seq: + * context.num_chars -> num + * + * Obtain the number of characters in this context. + */ +static VALUE rxml_parser_context_num_chars_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (LONG2NUM(ctxt->nbChars)); +} + + +/* + * call-seq: + * context.options > XML::Parser::Options::NOENT + * + * Returns the parser options for this context. Multiple + * options can be combined by using Bitwise OR (|). + */ +static VALUE rxml_parser_context_options_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return INT2NUM(ctxt->options); +} + +/* + * call-seq: + * context.options = XML::Parser::Options::NOENT | + XML::Parser::Options::NOCDATA + * + * Provides control over the execution of a parser. Valid values + * are the constants defined on XML::Parser::Options. Multiple + * options can be combined by using Bitwise OR (|). + */ +static VALUE rxml_parser_context_options_set(VALUE self, VALUE options) +{ + xmlParserCtxtPtr ctxt; + Check_Type(options, T_FIXNUM); + + Data_Get_Struct(self, xmlParserCtxt, ctxt); + xmlCtxtUseOptions(ctxt, NUM2INT(options)); + + return self; +} + +/* + * call-seq: + * context.recovery? -> (true|false) + * + * Determine whether recovery mode is enabled in this + * context. + */ +static VALUE rxml_parser_context_recovery_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->recovery) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.recovery = true|false + * + * Control whether recovery mode is enabled in this + * context. + */ +static VALUE rxml_parser_context_recovery_set(VALUE self, VALUE value) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (value == Qfalse) + { + ctxt->recovery = 0; + return (Qfalse); + } + else + { + ctxt->recovery = 1; + return (Qtrue); + } +} + +/* + * call-seq: + * context.replace_entities? -> (true|false) + * + * Determine whether external entity replacement is enabled in this + * context. + */ +static VALUE rxml_parser_context_replace_entities_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->replaceEntities) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.replace_entities = true|false + * + * Control whether external entity replacement is enabled in this + * context. + */ +static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE value) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (value == Qfalse) + { + ctxt->replaceEntities = 0; + return (Qfalse); + } + else + { + ctxt->replaceEntities = 1; + return (Qtrue); + } +} + +/* + * call-seq: + * context.space_depth -> num + * + * Obtain the space depth for this context. + */ +static VALUE rxml_parser_context_space_depth_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->spaceNr)); +} + +/* + * call-seq: + * context.space_depth -> num + * + * Obtain the maximum space depth for this context. + */ +static VALUE rxml_parser_context_space_depth_max_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + return (INT2NUM(ctxt->spaceMax)); +} + +/* + * call-seq: + * context.subset_external? -> (true|false) + * + * Determine whether this context is a subset of an + * external context. + */ +static VALUE rxml_parser_context_subset_external_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->inSubset == 2) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.subset_internal? -> (true|false) + * + * Determine whether this context is a subset of an + * internal context. + */ +static VALUE rxml_parser_context_subset_internal_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->inSubset == 1) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.subset_internal_name -> "name" + * + * Obtain this context's subset name (valid only if + * either of subset_external? or subset_internal? + * is true). + */ +static VALUE rxml_parser_context_subset_name_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->intSubName == NULL) + return (Qnil); + else + return (rxml_new_cstr(ctxt->intSubName, ctxt->encoding)); +} + +/* + * call-seq: + * context.subset_external_uri -> "uri" + * + * Obtain this context's external subset URI. (valid only if + * either of subset_external? or subset_internal? + * is true). + */ +static VALUE rxml_parser_context_subset_external_uri_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->extSubURI == NULL) + return (Qnil); + else + return (rxml_new_cstr( ctxt->extSubURI, ctxt->encoding)); +} + +/* + * call-seq: + * context.subset_external_system_id -> "system_id" + * + * Obtain this context's external subset system identifier. + * (valid only if either of subset_external? or subset_internal? + * is true). + */ +static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->extSubSystem == NULL) + return (Qnil); + else + return (rxml_new_cstr( ctxt->extSubSystem, ctxt->encoding)); +} + +/* + * call-seq: + * context.standalone? -> (true|false) + * + * Determine whether this is a standalone context. + */ +static VALUE rxml_parser_context_standalone_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->standalone) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.stats? -> (true|false) + * + * Determine whether this context maintains statistics. + */ +static VALUE rxml_parser_context_stats_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->record_info) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.valid? -> (true|false) + * + * Determine whether this context is valid. + */ +static VALUE rxml_parser_context_valid_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->valid) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.validate? -> (true|false) + * + * Determine whether validation is enabled in this context. + */ +static VALUE rxml_parser_context_validate_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->validate) + return (Qtrue); + else + return (Qfalse); +} + +/* + * call-seq: + * context.version -> "version" + * + * Obtain this context's version identifier. + */ +static VALUE rxml_parser_context_version_get(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->version == NULL) + return (Qnil); + else + return (rxml_new_cstr( ctxt->version, ctxt->encoding)); +} + +/* + * call-seq: + * context.well_formed? -> (true|false) + * + * Determine whether this context contains well-formed XML. + */ +static VALUE rxml_parser_context_well_formed_q(VALUE self) +{ + xmlParserCtxtPtr ctxt; + Data_Get_Struct(self, xmlParserCtxt, ctxt); + + if (ctxt->wellFormed) + return (Qtrue); + else + return (Qfalse); +} + +void rxml_init_parser_context(void) +{ + IO_ATTR = ID2SYM(rb_intern("@io")); + + cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject); + rb_define_alloc_func(cXMLParserContext, rxml_parser_context_alloc); + + rb_define_singleton_method(cXMLParserContext, "document", rxml_parser_context_document, -1); + rb_define_singleton_method(cXMLParserContext, "file", rxml_parser_context_file, -1); + rb_define_singleton_method(cXMLParserContext, "io", rxml_parser_context_io, -1); + rb_define_singleton_method(cXMLParserContext, "string", rxml_parser_context_string, -1); + + rb_define_method(cXMLParserContext, "base_uri", rxml_parser_context_base_uri_get, 0); + rb_define_method(cXMLParserContext, "base_uri=", rxml_parser_context_base_uri_set, 1); + rb_define_method(cXMLParserContext, "close", rxml_parser_context_close, 0); + rb_define_method(cXMLParserContext, "data_directory", rxml_parser_context_data_directory_get, 0); + rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0); + rb_define_method(cXMLParserContext, "disable_cdata?", rxml_parser_context_disable_cdata_q, 0); + rb_define_method(cXMLParserContext, "disable_cdata=", rxml_parser_context_disable_cdata_set, 1); + rb_define_method(cXMLParserContext, "disable_sax?", rxml_parser_context_disable_sax_q, 0); + rb_define_method(cXMLParserContext, "docbook?", rxml_parser_context_docbook_q, 0); + rb_define_method(cXMLParserContext, "encoding", rxml_parser_context_encoding_get, 0); + rb_define_method(cXMLParserContext, "encoding=", rxml_parser_context_encoding_set, 1); + rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0); + rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0); + rb_define_method(cXMLParserContext, "io_max_num_streams", rxml_parser_context_io_max_num_streams_get, 0); + rb_define_method(cXMLParserContext, "io_num_streams", rxml_parser_context_io_num_streams_get, 0); + rb_define_method(cXMLParserContext, "keep_blanks?", rxml_parser_context_keep_blanks_q, 0); + rb_define_method(cXMLParserContext, "name_node", rxml_parser_context_name_node_get, 0); + rb_define_method(cXMLParserContext, "name_depth", rxml_parser_context_name_depth_get, 0); + rb_define_method(cXMLParserContext, "name_depth_max", rxml_parser_context_name_depth_max_get, 0); + rb_define_method(cXMLParserContext, "name_tab", rxml_parser_context_name_tab_get, 0); + rb_define_method(cXMLParserContext, "node", rxml_parser_context_node_get, 0); + rb_define_method(cXMLParserContext, "node_depth", rxml_parser_context_node_depth_get, 0); + rb_define_method(cXMLParserContext, "node_depth_max", rxml_parser_context_node_depth_max_get, 0); + rb_define_method(cXMLParserContext, "num_chars", rxml_parser_context_num_chars_get, 0); + rb_define_method(cXMLParserContext, "options", rxml_parser_context_options_get, 0); + rb_define_method(cXMLParserContext, "options=", rxml_parser_context_options_set, 1); + rb_define_method(cXMLParserContext, "recovery?", rxml_parser_context_recovery_q, 0); + rb_define_method(cXMLParserContext, "recovery=", rxml_parser_context_recovery_set, 1); + rb_define_method(cXMLParserContext, "replace_entities?", rxml_parser_context_replace_entities_q, 0); + rb_define_method(cXMLParserContext, "replace_entities=", rxml_parser_context_replace_entities_set, 1); + rb_define_method(cXMLParserContext, "space_depth", rxml_parser_context_space_depth_get, 0); + rb_define_method(cXMLParserContext, "space_depth_max", rxml_parser_context_space_depth_max_get, 0); + rb_define_method(cXMLParserContext, "subset_external?", rxml_parser_context_subset_external_q, 0); + rb_define_method(cXMLParserContext, "subset_external_system_id", rxml_parser_context_subset_external_system_id_get, 0); + rb_define_method(cXMLParserContext, "subset_external_uri", rxml_parser_context_subset_external_uri_get, 0); + rb_define_method(cXMLParserContext, "subset_internal?", rxml_parser_context_subset_internal_q, 0); + rb_define_method(cXMLParserContext, "subset_internal_name", rxml_parser_context_subset_name_get, 0); + rb_define_method(cXMLParserContext, "stats?", rxml_parser_context_stats_q, 0); + rb_define_method(cXMLParserContext, "standalone?", rxml_parser_context_standalone_q, 0); + rb_define_method(cXMLParserContext, "valid", rxml_parser_context_valid_q, 0); + rb_define_method(cXMLParserContext, "validate?", rxml_parser_context_validate_q, 0); + rb_define_method(cXMLParserContext, "version", rxml_parser_context_version_get, 0); + rb_define_method(cXMLParserContext, "well_formed?", rxml_parser_context_well_formed_q, 0); +} diff --git a/ext/libxml/ruby_xml_parser_options.c b/ext/libxml/ruby_xml_parser_options.c index d85ec76e..3614bf78 100644 --- a/ext/libxml/ruby_xml_parser_options.c +++ b/ext/libxml/ruby_xml_parser_options.c @@ -1,74 +1,74 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#include -#include "ruby_libxml.h" - -/* Document-class: LibXML::XML::Parser::Options - * - * Options that control the operation of the HTMLParser. The easiest - * way to set a parser's options is to use the methods - * XML::Parser.file, XML::Parser.io or XML::Parser.string. - * For additional control, see XML::Parser::Context#options=. -*/ - -VALUE mXMLParserOptions; - -void rxml_init_parser_options(void) -{ - mXMLParserOptions = rb_define_module_under(cXMLParser, "Options"); - - /* recover on errors */ - rb_define_const(mXMLParserOptions, "RECOVER", INT2NUM(XML_PARSE_RECOVER)); - /* substitute entities */ - rb_define_const(mXMLParserOptions, "NOENT", INT2NUM(XML_PARSE_NOENT)); - /* load the external subset */ - rb_define_const(mXMLParserOptions, "DTDLOAD", INT2NUM(XML_PARSE_DTDLOAD)); - /* default DTD attributes */ - rb_define_const(mXMLParserOptions, "DTDATTR", INT2NUM(XML_PARSE_DTDATTR)); - /* validate with the DTD */ - rb_define_const(mXMLParserOptions, "DTDVALID", INT2NUM(XML_PARSE_DTDVALID)); - /* suppress error reports */ - rb_define_const(mXMLParserOptions, "NOERROR", INT2NUM(XML_PARSE_NOERROR)); - /* suppress warning reports */ - rb_define_const(mXMLParserOptions, "NOWARNING", INT2NUM(XML_PARSE_NOWARNING)); - /* pedantic error reporting */ - rb_define_const(mXMLParserOptions, "PEDANTIC", INT2NUM(XML_PARSE_PEDANTIC)); - /* remove blank nodes */ - rb_define_const(mXMLParserOptions, "NOBLANKS", INT2NUM(XML_PARSE_NOBLANKS)); - /* use the SAX1 interface internally */ - rb_define_const(mXMLParserOptions, "SAX1", INT2NUM(XML_PARSE_SAX1)); - /* Implement XInclude substitition */ - rb_define_const(mXMLParserOptions, "XINCLUDE", INT2NUM(XML_PARSE_XINCLUDE)); - /* Forbid network access */ - rb_define_const(mXMLParserOptions, "NONET", INT2NUM(XML_PARSE_NONET)); - /* Do not reuse the context dictionnary */ - rb_define_const(mXMLParserOptions, "NODICT", INT2NUM(XML_PARSE_NODICT)); - /* remove redundant namespaces declarations */ - rb_define_const(mXMLParserOptions, "NSCLEAN", INT2NUM(XML_PARSE_NSCLEAN)); - /* merge CDATA as text nodes */ - rb_define_const(mXMLParserOptions, "NOCDATA", INT2NUM(XML_PARSE_NOCDATA)); -#if LIBXML_VERSION >= 20621 - /* do not generate XINCLUDE START/END nodes */ - rb_define_const(mXMLParserOptions, "NOXINCNODE", INT2NUM(XML_PARSE_NOXINCNODE)); -#endif -#if LIBXML_VERSION >= 20700 - /* compact small text nodes */ - rb_define_const(mXMLParserOptions, "COMPACT", INT2NUM(XML_PARSE_COMPACT)); - /* parse using XML-1.0 before update 5 */ - rb_define_const(mXMLParserOptions, "OLD10", INT2NUM(XML_PARSE_OLD10)); - /* do not fixup XINCLUDE xml:base uris */ - rb_define_const(mXMLParserOptions, "NOBASEFIX", INT2NUM(XML_PARSE_NOBASEFIX)); -#endif -#if LIBXML_VERSION >= 20703 - /* relax any hardcoded limit from the parser */ - rb_define_const(mXMLParserOptions, "HUGE", INT2NUM(XML_PARSE_HUGE)); -#endif -#if LIBXML_VERSION >= 21106 - /* parse using SAX2 interface before 2.7.0 */ - rb_define_const(mXMLParserOptions, "OLDSAX", INT2NUM(XML_PARSE_OLDSAX)); - /* ignore internal document encoding hint */ - rb_define_const(mXMLParserOptions, "IGNORE_ENC", INT2NUM(XML_PARSE_IGNORE_ENC)); - /* Store big lines numbers in text PSVI field */ - rb_define_const(mXMLParserOptions, "BIG_LINES", INT2NUM(XML_PARSE_BIG_LINES)); -#endif -} +/* Please see the LICENSE file for copyright and distribution information */ + +#include +#include "ruby_libxml.h" + +/* Document-class: LibXML::XML::Parser::Options + * + * Options that control the operation of the HTMLParser. The easiest + * way to set a parser's options is to use the methods + * XML::Parser.file, XML::Parser.io or XML::Parser.string. + * For additional control, see XML::Parser::Context#options=. +*/ + +VALUE mXMLParserOptions; + +void rxml_init_parser_options(void) +{ + mXMLParserOptions = rb_define_module_under(cXMLParser, "Options"); + + /* recover on errors */ + rb_define_const(mXMLParserOptions, "RECOVER", INT2NUM(XML_PARSE_RECOVER)); + /* substitute entities */ + rb_define_const(mXMLParserOptions, "NOENT", INT2NUM(XML_PARSE_NOENT)); + /* load the external subset */ + rb_define_const(mXMLParserOptions, "DTDLOAD", INT2NUM(XML_PARSE_DTDLOAD)); + /* default DTD attributes */ + rb_define_const(mXMLParserOptions, "DTDATTR", INT2NUM(XML_PARSE_DTDATTR)); + /* validate with the DTD */ + rb_define_const(mXMLParserOptions, "DTDVALID", INT2NUM(XML_PARSE_DTDVALID)); + /* suppress error reports */ + rb_define_const(mXMLParserOptions, "NOERROR", INT2NUM(XML_PARSE_NOERROR)); + /* suppress warning reports */ + rb_define_const(mXMLParserOptions, "NOWARNING", INT2NUM(XML_PARSE_NOWARNING)); + /* pedantic error reporting */ + rb_define_const(mXMLParserOptions, "PEDANTIC", INT2NUM(XML_PARSE_PEDANTIC)); + /* remove blank nodes */ + rb_define_const(mXMLParserOptions, "NOBLANKS", INT2NUM(XML_PARSE_NOBLANKS)); + /* use the SAX1 interface internally */ + rb_define_const(mXMLParserOptions, "SAX1", INT2NUM(XML_PARSE_SAX1)); + /* Implement XInclude substitition */ + rb_define_const(mXMLParserOptions, "XINCLUDE", INT2NUM(XML_PARSE_XINCLUDE)); + /* Forbid network access */ + rb_define_const(mXMLParserOptions, "NONET", INT2NUM(XML_PARSE_NONET)); + /* Do not reuse the context dictionnary */ + rb_define_const(mXMLParserOptions, "NODICT", INT2NUM(XML_PARSE_NODICT)); + /* remove redundant namespaces declarations */ + rb_define_const(mXMLParserOptions, "NSCLEAN", INT2NUM(XML_PARSE_NSCLEAN)); + /* merge CDATA as text nodes */ + rb_define_const(mXMLParserOptions, "NOCDATA", INT2NUM(XML_PARSE_NOCDATA)); +#if LIBXML_VERSION >= 20621 + /* do not generate XINCLUDE START/END nodes */ + rb_define_const(mXMLParserOptions, "NOXINCNODE", INT2NUM(XML_PARSE_NOXINCNODE)); +#endif +#if LIBXML_VERSION >= 20700 + /* compact small text nodes */ + rb_define_const(mXMLParserOptions, "COMPACT", INT2NUM(XML_PARSE_COMPACT)); + /* parse using XML-1.0 before update 5 */ + rb_define_const(mXMLParserOptions, "OLD10", INT2NUM(XML_PARSE_OLD10)); + /* do not fixup XINCLUDE xml:base uris */ + rb_define_const(mXMLParserOptions, "NOBASEFIX", INT2NUM(XML_PARSE_NOBASEFIX)); +#endif +#if LIBXML_VERSION >= 20703 + /* relax any hardcoded limit from the parser */ + rb_define_const(mXMLParserOptions, "HUGE", INT2NUM(XML_PARSE_HUGE)); +#endif +#if LIBXML_VERSION >= 21106 + /* parse using SAX2 interface before 2.7.0 */ + rb_define_const(mXMLParserOptions, "OLDSAX", INT2NUM(XML_PARSE_OLDSAX)); + /* ignore internal document encoding hint */ + rb_define_const(mXMLParserOptions, "IGNORE_ENC", INT2NUM(XML_PARSE_IGNORE_ENC)); + /* Store big lines numbers in text PSVI field */ + rb_define_const(mXMLParserOptions, "BIG_LINES", INT2NUM(XML_PARSE_BIG_LINES)); +#endif +} diff --git a/ext/libxml/ruby_xml_parser_options.h b/ext/libxml/ruby_xml_parser_options.h index 37ea10cf..6c340932 100644 --- a/ext/libxml/ruby_xml_parser_options.h +++ b/ext/libxml/ruby_xml_parser_options.h @@ -1,10 +1,10 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#ifndef __RXML_PARSER_OPTIONS__ -#define __RXML_PARSER_OPTIONS__ - -extern VALUE mXMLParserOptions; - -void rxml_init_parser_options(void); - -#endif +/* Please see the LICENSE file for copyright and distribution information */ + +#ifndef __RXML_PARSER_OPTIONS__ +#define __RXML_PARSER_OPTIONS__ + +extern VALUE mXMLParserOptions; + +void rxml_init_parser_options(void); + +#endif diff --git a/ext/libxml/ruby_xml_sax2_handler.c b/ext/libxml/ruby_xml_sax2_handler.c index 5f811b86..0e301df0 100644 --- a/ext/libxml/ruby_xml_sax2_handler.c +++ b/ext/libxml/ruby_xml_sax2_handler.c @@ -1,326 +1,326 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#include "ruby_libxml.h" -#include "ruby_xml_sax2_handler.h" - - -VALUE cbidOnCdataBlock; -VALUE cbidOnCharacters; -VALUE cbidOnComment; -VALUE cbidOnEndDocument; -VALUE cbidOnEndElement; -VALUE cbidOnEndElementNs; -VALUE cbidOnExternalSubset; -VALUE cbidOnHasExternalSubset; -VALUE cbidOnHasInternalSubset; -VALUE cbidOnInternalSubset; -VALUE cbidOnIsStandalone; -VALUE cbidOnError; -VALUE cbidOnProcessingInstruction; -VALUE cbidOnReference; -VALUE cbidOnStartElement; -VALUE cbidOnStartElementNs; -VALUE cbidOnStartDocument; - -/* ====== Callbacks =========== */ -static void cdata_block_callback(void *ctx, const xmlChar *value, int len) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnCdataBlock,1, rxml_new_cstr_len(value, len, NULL)); - } -} - -static void characters_callback(void *ctx, const xmlChar *chars, int len) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - VALUE rchars = rxml_new_cstr_len(chars, len, NULL); - rb_funcall(handler, cbidOnCharacters, 1, rchars); - } -} - -static void comment_callback(void *ctx, const xmlChar *msg) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnComment, 1, rxml_new_cstr(msg, NULL)); - } -} - -static void end_document_callback(void *ctx) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnEndDocument, 0); - } -} - -static void end_element_ns_callback(void *ctx, const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI) -{ - VALUE handler = (VALUE) ctx; - - if (handler == Qnil) - return; - - /* Call end element for old-times sake */ - if (rb_respond_to(handler, cbidOnEndElement)) - { - VALUE name; - if (xprefix) - { - name = rxml_new_cstr(xprefix, NULL); - rb_str_cat2(name, ":"); - rb_str_cat2(name, (const char*)xlocalname); - } - else - { - name = rxml_new_cstr(xlocalname, NULL); - } - rb_funcall(handler, cbidOnEndElement, 1, name); - } - - rb_funcall(handler, cbidOnEndElementNs, 3, - rxml_new_cstr(xlocalname, NULL), - xprefix ? rxml_new_cstr(xprefix, NULL) : Qnil, - xURI ? rxml_new_cstr(xURI, NULL) : Qnil); -} - -static void external_subset_callback(void *ctx, const xmlChar *name, const xmlChar *extid, const xmlChar *sysid) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - VALUE rname = name ? rxml_new_cstr(name, NULL) : Qnil; - VALUE rextid = extid ? rxml_new_cstr(extid, NULL) : Qnil; - VALUE rsysid = sysid ? rxml_new_cstr(sysid, NULL) : Qnil; - rb_funcall(handler, cbidOnExternalSubset, 3, rname, rextid, rsysid); - } -} - -static void has_external_subset_callback(void *ctx) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnHasExternalSubset, 0); - } -} - -static void has_internal_subset_callback(void *ctx) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnHasInternalSubset, 0); - } -} - -static void internal_subset_callback(void *ctx, const xmlChar *name, const xmlChar *extid, const xmlChar *sysid) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - VALUE rname = name ? rxml_new_cstr(name, NULL) : Qnil; - VALUE rextid = extid ? rxml_new_cstr(extid, NULL) : Qnil; - VALUE rsysid = sysid ? rxml_new_cstr(sysid, NULL) : Qnil; - rb_funcall(handler, cbidOnInternalSubset, 3, rname, rextid, rsysid); - } -} - -static void is_standalone_callback(void *ctx) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnIsStandalone,0); - } -} - -static void processing_instruction_callback(void *ctx, const xmlChar *target, const xmlChar *data) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - VALUE rtarget = target ? rxml_new_cstr(target, NULL) : Qnil; - VALUE rdata = data ? rxml_new_cstr(data, NULL) : Qnil; - rb_funcall(handler, cbidOnProcessingInstruction, 2, rtarget, rdata); - } -} - -static void reference_callback(void *ctx, const xmlChar *name) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnReference, 1, rxml_new_cstr(name, NULL)); - } -} - -static void start_document_callback(void *ctx) -{ - VALUE handler = (VALUE) ctx; - - if (handler != Qnil) - { - rb_funcall(handler, cbidOnStartDocument, 0); - } -} - -static void start_element_ns_callback(void *ctx, - const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI, - int nb_namespaces, const xmlChar **xnamespaces, - int nb_attributes, int nb_defaulted, const xmlChar **xattributes) -{ - VALUE handler = (VALUE) ctx; - VALUE attributes = rb_hash_new(); - VALUE namespaces = rb_hash_new(); - - if (handler == Qnil) - return; - - if (xattributes) - { - /* Each attribute is an array of [localname, prefix, URI, value, end] */ - int i; - for (i = 0;i < nb_attributes * 5; i+=5) - { - VALUE attrName = rxml_new_cstr(xattributes[i+0], NULL); - long attrLen = (long)(xattributes[i+4] - xattributes[i+3]); - VALUE attrValue = rxml_new_cstr_len(xattributes[i+3], attrLen, NULL); - rb_hash_aset(attributes, attrName, attrValue); - } - } - - if (xnamespaces) - { - int i; - for (i = 0;i < nb_namespaces * 2; i+=2) - { - VALUE nsPrefix = xnamespaces[i+0] ? rxml_new_cstr(xnamespaces[i+0], NULL) : Qnil; - VALUE nsURI = xnamespaces[i+1] ? rxml_new_cstr(xnamespaces[i+1], NULL) : Qnil; - rb_hash_aset(namespaces, nsPrefix, nsURI); - } - } - - /* Call start element for old-times sake */ - if (rb_respond_to(handler, cbidOnStartElement)) - { - VALUE name; - if (xprefix) - { - name = rxml_new_cstr(xprefix, NULL); - rb_str_cat2(name, ":"); - rb_str_cat2(name, (const char*)xlocalname); - } - else - { - name = rxml_new_cstr(xlocalname, NULL); - } - rb_funcall(handler, cbidOnStartElement, 2, name, attributes); - } - - rb_funcall(handler, cbidOnStartElementNs, 5, - rxml_new_cstr(xlocalname, NULL), - attributes, - xprefix ? rxml_new_cstr(xprefix, NULL) : Qnil, - xURI ? rxml_new_cstr(xURI, NULL) : Qnil, - namespaces); -} - -static void structured_error_callback(void *ctx, const xmlError *xerror) -{ - /* Older versions of Libxml will pass a NULL context from the sax parser. Fixed on - Feb 23, 2011. See: - - http://git.gnome.org/browse/libxml2/commit/?id=241d4a1069e6bedd0ee2295d7b43858109c1c6d1 */ - - VALUE handler; - - #if LIBXML_VERSION <= 20708 - xmlParserCtxtPtr ctxt = (xmlParserCtxt*)(xerror->ctxt); - ctx = ctxt->userData; - #endif - - handler = (VALUE) ctx; - - if (handler != Qnil) - { - VALUE error = rxml_error_wrap(xerror); - rb_funcall(handler, cbidOnError, 1, error); - } -} - -/* ====== Handler =========== */ -xmlSAXHandler rxml_sax_handler = { - (internalSubsetSAXFunc) internal_subset_callback, - (isStandaloneSAXFunc) is_standalone_callback, - (hasInternalSubsetSAXFunc) has_internal_subset_callback, - (hasExternalSubsetSAXFunc) has_external_subset_callback, - 0, /* resolveEntity */ - 0, /* getEntity */ - 0, /* entityDecl */ - 0, /* notationDecl */ - 0, /* attributeDecl */ - 0, /* elementDecl */ - 0, /* unparsedEntityDecl */ - 0, /* setDocumentLocator */ - (startDocumentSAXFunc) start_document_callback, - (endDocumentSAXFunc) end_document_callback, - 0, /* Use start_element_ns_callback instead */ - 0, /* Use end_element_ns_callback instead */ - (referenceSAXFunc) reference_callback, - (charactersSAXFunc) characters_callback, - 0, /* ignorableWhitespace */ - (processingInstructionSAXFunc) processing_instruction_callback, - (commentSAXFunc) comment_callback, - 0, /* xmlStructuredErrorFunc is used instead */ - 0, /* xmlStructuredErrorFunc is used instead */ - 0, /* xmlStructuredErrorFunc is used instead */ - 0, /* xmlGetParameterEntity */ - (cdataBlockSAXFunc) cdata_block_callback, - (externalSubsetSAXFunc) external_subset_callback, - XML_SAX2_MAGIC, /* force SAX2 */ - 0, /* _private */ - (startElementNsSAX2Func) start_element_ns_callback, - (endElementNsSAX2Func) end_element_ns_callback, - (xmlStructuredErrorFunc) structured_error_callback -}; - -void rxml_init_sax2_handler(void) -{ - - /* SaxCallbacks */ - cbidOnCdataBlock = rb_intern("on_cdata_block"); - cbidOnCharacters = rb_intern("on_characters"); - cbidOnComment = rb_intern("on_comment"); - cbidOnEndDocument = rb_intern("on_end_document"); - cbidOnEndElement = rb_intern("on_end_element"); - cbidOnEndElementNs = rb_intern("on_end_element_ns"); - cbidOnError = rb_intern("on_error"); - cbidOnExternalSubset = rb_intern("on_external_subset"); - cbidOnHasExternalSubset = rb_intern("on_has_external_subset"); - cbidOnHasInternalSubset = rb_intern("on_has_internal_subset"); - cbidOnInternalSubset = rb_intern("on_internal_subset"); - cbidOnIsStandalone = rb_intern("on_is_standalone"); - cbidOnProcessingInstruction = rb_intern("on_processing_instruction"); - cbidOnReference = rb_intern("on_reference"); - cbidOnStartElement = rb_intern("on_start_element"); - cbidOnStartElementNs = rb_intern("on_start_element_ns"); - cbidOnStartDocument = rb_intern("on_start_document"); -} +/* Please see the LICENSE file for copyright and distribution information */ + +#include "ruby_libxml.h" +#include "ruby_xml_sax2_handler.h" + + +VALUE cbidOnCdataBlock; +VALUE cbidOnCharacters; +VALUE cbidOnComment; +VALUE cbidOnEndDocument; +VALUE cbidOnEndElement; +VALUE cbidOnEndElementNs; +VALUE cbidOnExternalSubset; +VALUE cbidOnHasExternalSubset; +VALUE cbidOnHasInternalSubset; +VALUE cbidOnInternalSubset; +VALUE cbidOnIsStandalone; +VALUE cbidOnError; +VALUE cbidOnProcessingInstruction; +VALUE cbidOnReference; +VALUE cbidOnStartElement; +VALUE cbidOnStartElementNs; +VALUE cbidOnStartDocument; + +/* ====== Callbacks =========== */ +static void cdata_block_callback(void *ctx, const xmlChar *value, int len) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnCdataBlock,1, rxml_new_cstr_len(value, len, NULL)); + } +} + +static void characters_callback(void *ctx, const xmlChar *chars, int len) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + VALUE rchars = rxml_new_cstr_len(chars, len, NULL); + rb_funcall(handler, cbidOnCharacters, 1, rchars); + } +} + +static void comment_callback(void *ctx, const xmlChar *msg) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnComment, 1, rxml_new_cstr(msg, NULL)); + } +} + +static void end_document_callback(void *ctx) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnEndDocument, 0); + } +} + +static void end_element_ns_callback(void *ctx, const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI) +{ + VALUE handler = (VALUE) ctx; + + if (handler == Qnil) + return; + + /* Call end element for old-times sake */ + if (rb_respond_to(handler, cbidOnEndElement)) + { + VALUE name; + if (xprefix) + { + name = rxml_new_cstr(xprefix, NULL); + rb_str_cat2(name, ":"); + rb_str_cat2(name, (const char*)xlocalname); + } + else + { + name = rxml_new_cstr(xlocalname, NULL); + } + rb_funcall(handler, cbidOnEndElement, 1, name); + } + + rb_funcall(handler, cbidOnEndElementNs, 3, + rxml_new_cstr(xlocalname, NULL), + xprefix ? rxml_new_cstr(xprefix, NULL) : Qnil, + xURI ? rxml_new_cstr(xURI, NULL) : Qnil); +} + +static void external_subset_callback(void *ctx, const xmlChar *name, const xmlChar *extid, const xmlChar *sysid) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + VALUE rname = name ? rxml_new_cstr(name, NULL) : Qnil; + VALUE rextid = extid ? rxml_new_cstr(extid, NULL) : Qnil; + VALUE rsysid = sysid ? rxml_new_cstr(sysid, NULL) : Qnil; + rb_funcall(handler, cbidOnExternalSubset, 3, rname, rextid, rsysid); + } +} + +static void has_external_subset_callback(void *ctx) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnHasExternalSubset, 0); + } +} + +static void has_internal_subset_callback(void *ctx) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnHasInternalSubset, 0); + } +} + +static void internal_subset_callback(void *ctx, const xmlChar *name, const xmlChar *extid, const xmlChar *sysid) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + VALUE rname = name ? rxml_new_cstr(name, NULL) : Qnil; + VALUE rextid = extid ? rxml_new_cstr(extid, NULL) : Qnil; + VALUE rsysid = sysid ? rxml_new_cstr(sysid, NULL) : Qnil; + rb_funcall(handler, cbidOnInternalSubset, 3, rname, rextid, rsysid); + } +} + +static void is_standalone_callback(void *ctx) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnIsStandalone,0); + } +} + +static void processing_instruction_callback(void *ctx, const xmlChar *target, const xmlChar *data) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + VALUE rtarget = target ? rxml_new_cstr(target, NULL) : Qnil; + VALUE rdata = data ? rxml_new_cstr(data, NULL) : Qnil; + rb_funcall(handler, cbidOnProcessingInstruction, 2, rtarget, rdata); + } +} + +static void reference_callback(void *ctx, const xmlChar *name) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnReference, 1, rxml_new_cstr(name, NULL)); + } +} + +static void start_document_callback(void *ctx) +{ + VALUE handler = (VALUE) ctx; + + if (handler != Qnil) + { + rb_funcall(handler, cbidOnStartDocument, 0); + } +} + +static void start_element_ns_callback(void *ctx, + const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI, + int nb_namespaces, const xmlChar **xnamespaces, + int nb_attributes, int nb_defaulted, const xmlChar **xattributes) +{ + VALUE handler = (VALUE) ctx; + VALUE attributes = rb_hash_new(); + VALUE namespaces = rb_hash_new(); + + if (handler == Qnil) + return; + + if (xattributes) + { + /* Each attribute is an array of [localname, prefix, URI, value, end] */ + int i; + for (i = 0;i < nb_attributes * 5; i+=5) + { + VALUE attrName = rxml_new_cstr(xattributes[i+0], NULL); + long attrLen = (long)(xattributes[i+4] - xattributes[i+3]); + VALUE attrValue = rxml_new_cstr_len(xattributes[i+3], attrLen, NULL); + rb_hash_aset(attributes, attrName, attrValue); + } + } + + if (xnamespaces) + { + int i; + for (i = 0;i < nb_namespaces * 2; i+=2) + { + VALUE nsPrefix = xnamespaces[i+0] ? rxml_new_cstr(xnamespaces[i+0], NULL) : Qnil; + VALUE nsURI = xnamespaces[i+1] ? rxml_new_cstr(xnamespaces[i+1], NULL) : Qnil; + rb_hash_aset(namespaces, nsPrefix, nsURI); + } + } + + /* Call start element for old-times sake */ + if (rb_respond_to(handler, cbidOnStartElement)) + { + VALUE name; + if (xprefix) + { + name = rxml_new_cstr(xprefix, NULL); + rb_str_cat2(name, ":"); + rb_str_cat2(name, (const char*)xlocalname); + } + else + { + name = rxml_new_cstr(xlocalname, NULL); + } + rb_funcall(handler, cbidOnStartElement, 2, name, attributes); + } + + rb_funcall(handler, cbidOnStartElementNs, 5, + rxml_new_cstr(xlocalname, NULL), + attributes, + xprefix ? rxml_new_cstr(xprefix, NULL) : Qnil, + xURI ? rxml_new_cstr(xURI, NULL) : Qnil, + namespaces); +} + +static void structured_error_callback(void *ctx, const xmlError *xerror) +{ + /* Older versions of Libxml will pass a NULL context from the sax parser. Fixed on + Feb 23, 2011. See: + + http://git.gnome.org/browse/libxml2/commit/?id=241d4a1069e6bedd0ee2295d7b43858109c1c6d1 */ + + VALUE handler; + + #if LIBXML_VERSION <= 20708 + xmlParserCtxtPtr ctxt = (xmlParserCtxt*)(xerror->ctxt); + ctx = ctxt->userData; + #endif + + handler = (VALUE) ctx; + + if (handler != Qnil) + { + VALUE error = rxml_error_wrap(xerror); + rb_funcall(handler, cbidOnError, 1, error); + } +} + +/* ====== Handler =========== */ +xmlSAXHandler rxml_sax_handler = { + (internalSubsetSAXFunc) internal_subset_callback, + (isStandaloneSAXFunc) is_standalone_callback, + (hasInternalSubsetSAXFunc) has_internal_subset_callback, + (hasExternalSubsetSAXFunc) has_external_subset_callback, + 0, /* resolveEntity */ + 0, /* getEntity */ + 0, /* entityDecl */ + 0, /* notationDecl */ + 0, /* attributeDecl */ + 0, /* elementDecl */ + 0, /* unparsedEntityDecl */ + 0, /* setDocumentLocator */ + (startDocumentSAXFunc) start_document_callback, + (endDocumentSAXFunc) end_document_callback, + 0, /* Use start_element_ns_callback instead */ + 0, /* Use end_element_ns_callback instead */ + (referenceSAXFunc) reference_callback, + (charactersSAXFunc) characters_callback, + 0, /* ignorableWhitespace */ + (processingInstructionSAXFunc) processing_instruction_callback, + (commentSAXFunc) comment_callback, + 0, /* xmlStructuredErrorFunc is used instead */ + 0, /* xmlStructuredErrorFunc is used instead */ + 0, /* xmlStructuredErrorFunc is used instead */ + 0, /* xmlGetParameterEntity */ + (cdataBlockSAXFunc) cdata_block_callback, + (externalSubsetSAXFunc) external_subset_callback, + XML_SAX2_MAGIC, /* force SAX2 */ + 0, /* _private */ + (startElementNsSAX2Func) start_element_ns_callback, + (endElementNsSAX2Func) end_element_ns_callback, + (xmlStructuredErrorFunc) structured_error_callback +}; + +void rxml_init_sax2_handler(void) +{ + + /* SaxCallbacks */ + cbidOnCdataBlock = rb_intern("on_cdata_block"); + cbidOnCharacters = rb_intern("on_characters"); + cbidOnComment = rb_intern("on_comment"); + cbidOnEndDocument = rb_intern("on_end_document"); + cbidOnEndElement = rb_intern("on_end_element"); + cbidOnEndElementNs = rb_intern("on_end_element_ns"); + cbidOnError = rb_intern("on_error"); + cbidOnExternalSubset = rb_intern("on_external_subset"); + cbidOnHasExternalSubset = rb_intern("on_has_external_subset"); + cbidOnHasInternalSubset = rb_intern("on_has_internal_subset"); + cbidOnInternalSubset = rb_intern("on_internal_subset"); + cbidOnIsStandalone = rb_intern("on_is_standalone"); + cbidOnProcessingInstruction = rb_intern("on_processing_instruction"); + cbidOnReference = rb_intern("on_reference"); + cbidOnStartElement = rb_intern("on_start_element"); + cbidOnStartElementNs = rb_intern("on_start_element_ns"); + cbidOnStartDocument = rb_intern("on_start_document"); +} diff --git a/ext/libxml/ruby_xml_sax_parser.c b/ext/libxml/ruby_xml_sax_parser.c index e45adb19..dab5bc83 100644 --- a/ext/libxml/ruby_xml_sax_parser.c +++ b/ext/libxml/ruby_xml_sax_parser.c @@ -1,108 +1,108 @@ -/* Please see the LICENSE file for copyright and distribution information */ - -#include "ruby_libxml.h" -#include "ruby_xml_sax_parser.h" - -/* - * Document-class: LibXML::XML::SaxParser - * - * XML::SaxParser provides a callback based API for parsing documents, - * in contrast to XML::Parser's tree based API and XML::Reader's stream - * based API. - * - * The XML::SaxParser API is fairly complex, not well standardized, - * and does not directly support validation making entity, namespace and - * base processing relatively hard. - * - * To use the XML::SaxParser, register a callback class via the - * XML::SaxParser#callbacks=. It is easiest to include the - * XML::SaxParser::Callbacks module in your class and override - * the methods as needed. - * - * Basic example: - * - * class MyCallbacks - * include XML::SaxParser::Callbacks - * def on_start_element(element, attributes) - * puts #Element started: #{element}" - * end - * end - * - * parser = XML::SaxParser.string(my_string) - * parser.callbacks = MyCallbacks.new - * parser.parse - * - * You can also parse strings (see XML::SaxParser.string) and - * io objects (see XML::SaxParser.io). - */ - -VALUE cXMLSaxParser; -static ID CALLBACKS_ATTR; -static ID CONTEXT_ATTR; - - -/* ====== Parser =========== */ - -/* - * call-seq: - * parser.initialize(context) -> XML::Parser - * - * Creates a new XML::Parser from the specified - * XML::Parser::Context. - */ -static VALUE rxml_sax_parser_initialize(int argc, VALUE *argv, VALUE self) -{ - VALUE context = Qnil; - - rb_scan_args(argc, argv, "01", &context); - - if (context == Qnil) - { - rb_raise(rb_eArgError, "An instance of a XML::Parser::Context must be passed to XML::SaxParser.new"); - } - - rb_ivar_set(self, CONTEXT_ATTR, context); - return self; -} - -/* - * call-seq: - * parser.parse -> (true|false) - * - * Parse the input XML, generating callbacks to the object - * registered via the +callbacks+ attributesibute. - */ -static VALUE rxml_sax_parser_parse(VALUE self) -{ - VALUE context = rb_ivar_get(self, CONTEXT_ATTR); - xmlParserCtxtPtr ctxt; - Data_Get_Struct(context, xmlParserCtxt, ctxt); - - ctxt->sax2 = 1; - ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR); - memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler)); - - int status = xmlParseDocument(ctxt); - - /* Now check the parsing result*/ - if (status == -1 || !ctxt->wellFormed) - { - rxml_raise(&ctxt->lastError); - } - return Qtrue; -} - -void rxml_init_sax_parser(void) -{ - /* SaxParser */ - cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject); - - /* Atributes */ - CALLBACKS_ATTR = rb_intern("@callbacks"); - CONTEXT_ATTR = rb_intern("@context"); - rb_define_attr(cXMLSaxParser, "callbacks", 1, 1); - - /* Instance Methods */ - rb_define_method(cXMLSaxParser, "initialize", rxml_sax_parser_initialize, -1); - rb_define_method(cXMLSaxParser, "parse", rxml_sax_parser_parse, 0); -} +/* Please see the LICENSE file for copyright and distribution information */ + +#include "ruby_libxml.h" +#include "ruby_xml_sax_parser.h" + +/* + * Document-class: LibXML::XML::SaxParser + * + * XML::SaxParser provides a callback based API for parsing documents, + * in contrast to XML::Parser's tree based API and XML::Reader's stream + * based API. + * + * The XML::SaxParser API is fairly complex, not well standardized, + * and does not directly support validation making entity, namespace and + * base processing relatively hard. + * + * To use the XML::SaxParser, register a callback class via the + * XML::SaxParser#callbacks=. It is easiest to include the + * XML::SaxParser::Callbacks module in your class and override + * the methods as needed. + * + * Basic example: + * + * class MyCallbacks + * include XML::SaxParser::Callbacks + * def on_start_element(element, attributes) + * puts #Element started: #{element}" + * end + * end + * + * parser = XML::SaxParser.string(my_string) + * parser.callbacks = MyCallbacks.new + * parser.parse + * + * You can also parse strings (see XML::SaxParser.string) and + * io objects (see XML::SaxParser.io). + */ + +VALUE cXMLSaxParser; +static ID CALLBACKS_ATTR; +static ID CONTEXT_ATTR; + + +/* ====== Parser =========== */ + +/* + * call-seq: + * parser.initialize(context) -> XML::Parser + * + * Creates a new XML::Parser from the specified + * XML::Parser::Context. + */ +static VALUE rxml_sax_parser_initialize(int argc, VALUE *argv, VALUE self) +{ + VALUE context = Qnil; + + rb_scan_args(argc, argv, "01", &context); + + if (context == Qnil) + { + rb_raise(rb_eArgError, "An instance of a XML::Parser::Context must be passed to XML::SaxParser.new"); + } + + rb_ivar_set(self, CONTEXT_ATTR, context); + return self; +} + +/* + * call-seq: + * parser.parse -> (true|false) + * + * Parse the input XML, generating callbacks to the object + * registered via the +callbacks+ attributesibute. + */ +static VALUE rxml_sax_parser_parse(VALUE self) +{ + VALUE context = rb_ivar_get(self, CONTEXT_ATTR); + xmlParserCtxtPtr ctxt; + Data_Get_Struct(context, xmlParserCtxt, ctxt); + + ctxt->sax2 = 1; + ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR); + memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler)); + + int status = xmlParseDocument(ctxt); + + /* Now check the parsing result*/ + if (status == -1 || !ctxt->wellFormed) + { + rxml_raise(&ctxt->lastError); + } + return Qtrue; +} + +void rxml_init_sax_parser(void) +{ + /* SaxParser */ + cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject); + + /* Atributes */ + CALLBACKS_ATTR = rb_intern("@callbacks"); + CONTEXT_ATTR = rb_intern("@context"); + rb_define_attr(cXMLSaxParser, "callbacks", 1, 1); + + /* Instance Methods */ + rb_define_method(cXMLSaxParser, "initialize", rxml_sax_parser_initialize, -1); + rb_define_method(cXMLSaxParser, "parse", rxml_sax_parser_parse, 0); +} diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 7998ffc7..f8b9abb6 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ -/* Don't nuke this block! It is used for automatically updating the - * versions below. VERSION = string formatting, VERNUM = numbered - * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "5.0.2" -#define RUBY_LIBXML_VERNUM 502 -#define RUBY_LIBXML_VER_MAJ 5 -#define RUBY_LIBXML_VER_MIN 0 -#define RUBY_LIBXML_VER_MIC 2 -#define RUBY_LIBXML_VER_PATCH 0 +/* Don't nuke this block! It is used for automatically updating the + * versions below. VERSION = string formatting, VERNUM = numbered + * version for inline testing: increment both or none at all.*/ +#define RUBY_LIBXML_VERSION "5.0.2" +#define RUBY_LIBXML_VERNUM 502 +#define RUBY_LIBXML_VER_MAJ 5 +#define RUBY_LIBXML_VER_MIN 0 +#define RUBY_LIBXML_VER_MIC 2 +#define RUBY_LIBXML_VER_PATCH 0 diff --git a/lib/libxml.rb b/lib/libxml.rb index e9390a87..552a5755 100644 --- a/lib/libxml.rb +++ b/lib/libxml.rb @@ -1,5 +1,5 @@ -# encoding: UTF-8 -# -# This include is deprecated, use libxml-ruby instead! - +# encoding: UTF-8 +# +# This include is deprecated, use libxml-ruby instead! + require 'libxml-ruby' \ No newline at end of file diff --git a/lib/libxml/attr.rb b/lib/libxml/attr.rb index 27865216..a346c171 100644 --- a/lib/libxml/attr.rb +++ b/lib/libxml/attr.rb @@ -1,123 +1,123 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Attr - include Enumerable - - # call-seq: - # attr.child? -> (true|false) - # - # Returns whether this attribute has child attributes. - # - def child? - not self.children.nil? - end - - # call-seq: - # attr.doc? -> (true|false) - # - # Determine whether this attribute is associated with an - # XML::Document. - def doc? - not self.doc.nil? - end - - # call-seq: - # attr.last? -> (true|false) - # - # Determine whether this is the last attribute. - def last? - self.last.nil? - end - - # call-seq: - # attr.next? -> (true|false) - # - # Determine whether there is a next attribute. - def next? - not self.next.nil? - end - - # call-seq: - # attr.ns? -> (true|false) - # - # Determine whether this attribute has an associated - # namespace. - def ns? - not self.ns.nil? - end - - # call-seq: - # attr.namespacess -> XML::Namespaces - # - # Returns this node's XML::Namespaces object, - # which is used to access the namespaces - # associated with this node. - def namespaces - @namespaces ||= XML::Namespaces.new(self) - end - - # - # call-seq: - # attr.parent? -> (true|false) - # - # Determine whether this attribute has a parent. - def parent? - not self.parent.nil? - end - - # call-seq: - # attr.prev? -> (true|false) - # - # Determine whether there is a previous attribute. - def prev? - not self.prev.nil? - end - - # Returns this node's type name - def node_type_name - if node_type == Node::ATTRIBUTE_NODE - 'attribute' - else - raise(UnknownType, "Unknown node type: %n", node.node_type); - end - end - - # Iterates nodes and attributes - def siblings(node, &blk) - if n = node - loop do - blk.call(n) - break unless n = n.next - end - end - end - - def each_sibling(&blk) - siblings(self,&blk) - end - - alias :each_attr :each_sibling - alias :each :each_sibling - - def to_h - inject({}) do |h,a| - h[a.name] = a.value - h - end - end - - def to_a - inject([]) do |ary,a| - ary << [a.name, a.value] - ary - end - end - - def to_s - "#{name} = #{value}" - end - end - end +# encoding: UTF-8 + +module LibXML + module XML + class Attr + include Enumerable + + # call-seq: + # attr.child? -> (true|false) + # + # Returns whether this attribute has child attributes. + # + def child? + not self.children.nil? + end + + # call-seq: + # attr.doc? -> (true|false) + # + # Determine whether this attribute is associated with an + # XML::Document. + def doc? + not self.doc.nil? + end + + # call-seq: + # attr.last? -> (true|false) + # + # Determine whether this is the last attribute. + def last? + self.last.nil? + end + + # call-seq: + # attr.next? -> (true|false) + # + # Determine whether there is a next attribute. + def next? + not self.next.nil? + end + + # call-seq: + # attr.ns? -> (true|false) + # + # Determine whether this attribute has an associated + # namespace. + def ns? + not self.ns.nil? + end + + # call-seq: + # attr.namespacess -> XML::Namespaces + # + # Returns this node's XML::Namespaces object, + # which is used to access the namespaces + # associated with this node. + def namespaces + @namespaces ||= XML::Namespaces.new(self) + end + + # + # call-seq: + # attr.parent? -> (true|false) + # + # Determine whether this attribute has a parent. + def parent? + not self.parent.nil? + end + + # call-seq: + # attr.prev? -> (true|false) + # + # Determine whether there is a previous attribute. + def prev? + not self.prev.nil? + end + + # Returns this node's type name + def node_type_name + if node_type == Node::ATTRIBUTE_NODE + 'attribute' + else + raise(UnknownType, "Unknown node type: %n", node.node_type); + end + end + + # Iterates nodes and attributes + def siblings(node, &blk) + if n = node + loop do + blk.call(n) + break unless n = n.next + end + end + end + + def each_sibling(&blk) + siblings(self,&blk) + end + + alias :each_attr :each_sibling + alias :each :each_sibling + + def to_h + inject({}) do |h,a| + h[a.name] = a.value + h + end + end + + def to_a + inject([]) do |ary,a| + ary << [a.name, a.value] + ary + end + end + + def to_s + "#{name} = #{value}" + end + end + end end \ No newline at end of file diff --git a/lib/libxml/attr_decl.rb b/lib/libxml/attr_decl.rb index b35ce947..15c8be72 100644 --- a/lib/libxml/attr_decl.rb +++ b/lib/libxml/attr_decl.rb @@ -1,80 +1,80 @@ -# encoding: UTF-8 - -module LibXML - module XML - class AttrDecl - include Enumerable - - # call-seq: - # attr_decl.child -> nil - # - # Obtain this attribute declaration's child attribute(s). - # It will always be nil. - def child - nil - end - - # call-seq: - # attr_decl.child? -> (true|false) - # - # Returns whether this attribute declaration has child attributes. - # - def child? - not self.children.nil? - end - - # call-seq: - # attr_decl.doc? -> (true|false) - # - # Determine whether this attribute declaration is associated with an - # XML::Document. - def doc? - not self.doc.nil? - end - - # call-seq: - # attr_decl.next? -> (true|false) - # - # Determine whether there is a next attribute declaration. - def next? - not self.next.nil? - end - - # call-seq: - # attr_decl.parent? -> (true|false) - # - # Determine whether this attribute declaration has a parent . - def parent? - not self.parent.nil? - end - - # call-seq: - # attr_decl.prev? -> (true|false) - # - # Determine whether there is a previous attribute declaration. - def prev? - not self.prev.nil? - end - - # call-seq: - # attr_decl.node_type_name -> 'attribute declaration' - # - # Returns this attribute declaration's node type name. - def node_type_name - if node_type == Node::ATTRIBUTE_DECL - 'attribute declaration' - else - raise(UnknownType, "Unknown node type: %n", node.node_type); - end - end - - # call-seq: - # attr_decl.to_s -> string - # - # Returns a string representation of this attribute declaration. - def to_s - "#{name} = #{value}" - end - end - end -end +# encoding: UTF-8 + +module LibXML + module XML + class AttrDecl + include Enumerable + + # call-seq: + # attr_decl.child -> nil + # + # Obtain this attribute declaration's child attribute(s). + # It will always be nil. + def child + nil + end + + # call-seq: + # attr_decl.child? -> (true|false) + # + # Returns whether this attribute declaration has child attributes. + # + def child? + not self.children.nil? + end + + # call-seq: + # attr_decl.doc? -> (true|false) + # + # Determine whether this attribute declaration is associated with an + # XML::Document. + def doc? + not self.doc.nil? + end + + # call-seq: + # attr_decl.next? -> (true|false) + # + # Determine whether there is a next attribute declaration. + def next? + not self.next.nil? + end + + # call-seq: + # attr_decl.parent? -> (true|false) + # + # Determine whether this attribute declaration has a parent . + def parent? + not self.parent.nil? + end + + # call-seq: + # attr_decl.prev? -> (true|false) + # + # Determine whether there is a previous attribute declaration. + def prev? + not self.prev.nil? + end + + # call-seq: + # attr_decl.node_type_name -> 'attribute declaration' + # + # Returns this attribute declaration's node type name. + def node_type_name + if node_type == Node::ATTRIBUTE_DECL + 'attribute declaration' + else + raise(UnknownType, "Unknown node type: %n", node.node_type); + end + end + + # call-seq: + # attr_decl.to_s -> string + # + # Returns a string representation of this attribute declaration. + def to_s + "#{name} = #{value}" + end + end + end +end diff --git a/lib/libxml/attributes.rb b/lib/libxml/attributes.rb index 4c722d79..345bacdb 100644 --- a/lib/libxml/attributes.rb +++ b/lib/libxml/attributes.rb @@ -1,14 +1,14 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Attributes - def to_h - inject({}) do |hash, attr| - hash[attr.name] = attr.value - hash - end - end - end - end +# encoding: UTF-8 + +module LibXML + module XML + class Attributes + def to_h + inject({}) do |hash, attr| + hash[attr.name] = attr.value + hash + end + end + end + end end \ No newline at end of file diff --git a/lib/libxml/document.rb b/lib/libxml/document.rb index 81af22fc..f012f2e9 100644 --- a/lib/libxml/document.rb +++ b/lib/libxml/document.rb @@ -1,194 +1,194 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Document - # call-seq: - # XML::Document.document(document) -> XML::Document - # - # Creates a new document based on the specified document. - # - # Parameters: - # - # document - A preparsed document. - def self.document(value) - Parser.document(value).parse - end - - # call-seq: - # XML::Document.file(path) -> XML::Document - # XML::Document.file(path, encoding: XML::Encoding::UTF_8, - # options: XML::Parser::Options::NOENT) -> XML::Document - # - # Creates a new document from the specified file or uri. - # - # Parameters: - # - # path - Path to file - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::Parser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.file(path, encoding: nil, options: nil) - Parser.file(path, encoding: encoding, options: options).parse - end - - # call-seq: - # XML::Document.io(io) -> XML::Document - # XML::Document.io(io, :encoding => XML::Encoding::UTF_8, - # :options => XML::Parser::Options::NOENT - # :base_uri="http://libxml.org") -> XML::Document - # - # Creates a new document from the specified io object. - # - # Parameters: - # - # io - io object that contains the xml to parser - # base_uri - The base url for the parsed document. - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::Parser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.io(io, base_uri: nil, encoding: nil, options: nil) - Parser.io(io, base_uri: base_uri, encoding: encoding, options: options).parse - end - - # call-seq: - # XML::Document.string(string) -> XML::Document - # XML::Document.string(string, encoding: XML::Encoding::UTF_8, - # options: XML::Parser::Options::NOENT - # base_uri: "http://libxml.org") -> XML::Document - # - # Creates a new document from the specified string. - # - # Parameters: - # - # string - String to parse - # base_uri - The base url for the parsed document. - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::Parser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.string(value, base_uri: nil, encoding: nil, options: nil) - Parser.string(value, base_uri: base_uri, encoding: encoding, options: options).parse - end - - # Returns a new XML::XPathContext for the document. - # - # call-seq: - # document.context(namespaces=nil) -> XPath::Context - # - # Namespaces is an optional array of XML::NS objects - def context(nslist = nil) - context = XPath::Context.new(self) - context.node = self.root - context.register_namespaces_from_node(self.root) - context.register_namespaces(nslist) if nslist - context - end - - # Return the nodes matching the specified xpath expression, - # optionally using the specified namespace. For more - # information about working with namespaces, please refer - # to the XML::XPath documentation. - # - # call-seq: - # document.find(xpath, nslist=nil) -> XML::XPath::Object - # - # Parameters: - # * xpath - The xpath expression as a string - # * namespaces - An optional list of namespaces (see XML::XPath for information). - # - # document.find('/foo', 'xlink:http://www.w3.org/1999/xlink') - # - # IMPORTANT - The returned XML::Node::Set must be freed before - # its associated document. In a running Ruby program this will - # happen automatically via Ruby's mark and sweep garbage collector. - # However, if the program exits, Ruby does not guarantee the order - # in which objects are freed - # (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700). - # As a result, the associated document may be freed before the node - # list, which will cause a segmentation fault. - # To avoid this, use the following (non-ruby like) coding style: - # - # nodes = doc.find('/header') - # nodes.each do |node| - # ... do stuff ... - # end - # # nodes = nil # GC.start - def find(xpath, nslist = nil) - self.context(nslist).find(xpath) - end - - # Return the first node matching the specified xpath expression. - # For more information, please refer to the documentation - # for XML::Document#find. - def find_first(xpath, nslist = nil) - find(xpath, nslist).first - end - - # Returns this node's type name - def node_type_name - case node_type - when XML::Node::DOCUMENT_NODE - 'document_xml' - when XML::Node::DOCB_DOCUMENT_NODE - 'document_docbook' - when XML::Node::HTML_DOCUMENT_NODE - 'document_html' - else - raise(UnknownType, "Unknown node type: %n", node.node_type); - end - end - # :enddoc: - - # Specifies if this is an document node - def document? - node_type == XML::Node::DOCUMENT_NODE - end - - # Specifies if this is an docbook node - def docbook_doc? - node_type == XML::Node::DOCB_DOCUMENT_NODE - end - - # Specifies if this is an html node - def html_doc? - node_type == XML::Node::HTML_DOCUMENT_NODE - end - - def dump - warn('Document#dump is deprecated. Use Document#to_s instead.') - self.to_s - end - - def format_dump - warn('Document#format_dump is deprecated. Use Document#to_s instead.') - self.to_s - end - - def debug_dump - warn('Document#debug_dump is deprecated. Use Document#debug instead.') - self.debug - end - - def debug_dump_head - warn('Document#debug_dump_head is deprecated. Use Document#debug instead.') - self.debug - end - - def debug_format_dump - warn('Document#debug_format_dump is deprecated. Use Document#to_s instead.') - self.to_s - end - - def reader - warn('Document#reader is deprecated. Use XML::Reader.document(self) instead.') - XML::Reader.document(self) - end - end - end -end +# encoding: UTF-8 + +module LibXML + module XML + class Document + # call-seq: + # XML::Document.document(document) -> XML::Document + # + # Creates a new document based on the specified document. + # + # Parameters: + # + # document - A preparsed document. + def self.document(value) + Parser.document(value).parse + end + + # call-seq: + # XML::Document.file(path) -> XML::Document + # XML::Document.file(path, encoding: XML::Encoding::UTF_8, + # options: XML::Parser::Options::NOENT) -> XML::Document + # + # Creates a new document from the specified file or uri. + # + # Parameters: + # + # path - Path to file + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::Parser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.file(path, encoding: nil, options: nil) + Parser.file(path, encoding: encoding, options: options).parse + end + + # call-seq: + # XML::Document.io(io) -> XML::Document + # XML::Document.io(io, :encoding => XML::Encoding::UTF_8, + # :options => XML::Parser::Options::NOENT + # :base_uri="http://libxml.org") -> XML::Document + # + # Creates a new document from the specified io object. + # + # Parameters: + # + # io - io object that contains the xml to parser + # base_uri - The base url for the parsed document. + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::Parser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.io(io, base_uri: nil, encoding: nil, options: nil) + Parser.io(io, base_uri: base_uri, encoding: encoding, options: options).parse + end + + # call-seq: + # XML::Document.string(string) -> XML::Document + # XML::Document.string(string, encoding: XML::Encoding::UTF_8, + # options: XML::Parser::Options::NOENT + # base_uri: "http://libxml.org") -> XML::Document + # + # Creates a new document from the specified string. + # + # Parameters: + # + # string - String to parse + # base_uri - The base url for the parsed document. + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::Parser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.string(value, base_uri: nil, encoding: nil, options: nil) + Parser.string(value, base_uri: base_uri, encoding: encoding, options: options).parse + end + + # Returns a new XML::XPathContext for the document. + # + # call-seq: + # document.context(namespaces=nil) -> XPath::Context + # + # Namespaces is an optional array of XML::NS objects + def context(nslist = nil) + context = XPath::Context.new(self) + context.node = self.root + context.register_namespaces_from_node(self.root) + context.register_namespaces(nslist) if nslist + context + end + + # Return the nodes matching the specified xpath expression, + # optionally using the specified namespace. For more + # information about working with namespaces, please refer + # to the XML::XPath documentation. + # + # call-seq: + # document.find(xpath, nslist=nil) -> XML::XPath::Object + # + # Parameters: + # * xpath - The xpath expression as a string + # * namespaces - An optional list of namespaces (see XML::XPath for information). + # + # document.find('/foo', 'xlink:http://www.w3.org/1999/xlink') + # + # IMPORTANT - The returned XML::Node::Set must be freed before + # its associated document. In a running Ruby program this will + # happen automatically via Ruby's mark and sweep garbage collector. + # However, if the program exits, Ruby does not guarantee the order + # in which objects are freed + # (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700). + # As a result, the associated document may be freed before the node + # list, which will cause a segmentation fault. + # To avoid this, use the following (non-ruby like) coding style: + # + # nodes = doc.find('/header') + # nodes.each do |node| + # ... do stuff ... + # end + # # nodes = nil # GC.start + def find(xpath, nslist = nil) + self.context(nslist).find(xpath) + end + + # Return the first node matching the specified xpath expression. + # For more information, please refer to the documentation + # for XML::Document#find. + def find_first(xpath, nslist = nil) + find(xpath, nslist).first + end + + # Returns this node's type name + def node_type_name + case node_type + when XML::Node::DOCUMENT_NODE + 'document_xml' + when XML::Node::DOCB_DOCUMENT_NODE + 'document_docbook' + when XML::Node::HTML_DOCUMENT_NODE + 'document_html' + else + raise(UnknownType, "Unknown node type: %n", node.node_type); + end + end + # :enddoc: + + # Specifies if this is an document node + def document? + node_type == XML::Node::DOCUMENT_NODE + end + + # Specifies if this is an docbook node + def docbook_doc? + node_type == XML::Node::DOCB_DOCUMENT_NODE + end + + # Specifies if this is an html node + def html_doc? + node_type == XML::Node::HTML_DOCUMENT_NODE + end + + def dump + warn('Document#dump is deprecated. Use Document#to_s instead.') + self.to_s + end + + def format_dump + warn('Document#format_dump is deprecated. Use Document#to_s instead.') + self.to_s + end + + def debug_dump + warn('Document#debug_dump is deprecated. Use Document#debug instead.') + self.debug + end + + def debug_dump_head + warn('Document#debug_dump_head is deprecated. Use Document#debug instead.') + self.debug + end + + def debug_format_dump + warn('Document#debug_format_dump is deprecated. Use Document#to_s instead.') + self.to_s + end + + def reader + warn('Document#reader is deprecated. Use XML::Reader.document(self) instead.') + XML::Reader.document(self) + end + end + end +end diff --git a/lib/libxml/error.rb b/lib/libxml/error.rb index c5ce71da..648af14f 100644 --- a/lib/libxml/error.rb +++ b/lib/libxml/error.rb @@ -1,95 +1,95 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Error - # Create mapping from domain constant values to keys - DOMAIN_CODE_MAP = [:NO_ERROR, :PARSER, :TREE, :NAMESPACE, :DTD, :HTML, :MEMORY, - :OUTPUT, :IO, :FTP, :HTTP, :XINCLUDE, :XPATH, :XPOINTER, :REGEXP, - :DATATYPE, :SCHEMASP, :SCHEMASV, :RELAXNGP, :RELAXNGV, :CATALOG, - :C14N, :XSLT, :VALID, :CHECK, :WRITER, :MODULE, :I18N, :SCHEMATRONV].inject(Hash.new) do |hash, code| - if const_defined?(code) - hash[const_get(code)] = code - end - hash - end - - # Create mapping from error constant values (so need to remove domain_codes) to keys - ERROR_CODE_MAP = Hash.new.tap do |map| - (constants - - DOMAIN_CODE_MAP.values - #Domains - [:NONE, :WARNING, :ERROR, :FATAL] # Levels - ).each do |code| - map[const_get(code)] = code - end - end - - # Verbose error handler - VERBOSE_HANDLER = lambda do |error| - STDERR << error.to_s << "\n" - STDERR.flush - end - - # Quiet error handler - QUIET_HANDLER = lambda do |error| - end - - def ==(other) - eql?(other) - end - - def eql?(other) - self.code == other.code and - self.domain == other.domain and - self.message == other.message and - self.level == other.level and - self.file == other.file and - self.line == other.line and - self.str1 == other.str1 and - self.str2 == other.str2 and - self.str3 == other.str3 and - self.int1 == other.int1 and - self.int2 == other.int2 and - self.ctxt == other.ctxt and - self.node == other.node - rescue - false - end - - def level_to_s - case self.level - when NONE - '' - when WARNING - 'Warning:' - when ERROR - 'Error:' - when FATAL - 'Fatal error:' - end - end - - def domain_to_s - DOMAIN_CODE_MAP[self.domain].to_s - end - - def code_to_s - ERROR_CODE_MAP[self.code].to_s - end - - def to_s - msg = super - msg = msg ? msg.strip: '' - - if self.line - sprintf("%s %s at %s:%d.", self.level_to_s, msg, - self.file, self.line) - else - sprintf("%s %s.", self.level_to_s, msg) - end - end - end - end -end - -LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER) +# encoding: UTF-8 + +module LibXML + module XML + class Error + # Create mapping from domain constant values to keys + DOMAIN_CODE_MAP = [:NO_ERROR, :PARSER, :TREE, :NAMESPACE, :DTD, :HTML, :MEMORY, + :OUTPUT, :IO, :FTP, :HTTP, :XINCLUDE, :XPATH, :XPOINTER, :REGEXP, + :DATATYPE, :SCHEMASP, :SCHEMASV, :RELAXNGP, :RELAXNGV, :CATALOG, + :C14N, :XSLT, :VALID, :CHECK, :WRITER, :MODULE, :I18N, :SCHEMATRONV].inject(Hash.new) do |hash, code| + if const_defined?(code) + hash[const_get(code)] = code + end + hash + end + + # Create mapping from error constant values (so need to remove domain_codes) to keys + ERROR_CODE_MAP = Hash.new.tap do |map| + (constants - + DOMAIN_CODE_MAP.values - #Domains + [:NONE, :WARNING, :ERROR, :FATAL] # Levels + ).each do |code| + map[const_get(code)] = code + end + end + + # Verbose error handler + VERBOSE_HANDLER = lambda do |error| + STDERR << error.to_s << "\n" + STDERR.flush + end + + # Quiet error handler + QUIET_HANDLER = lambda do |error| + end + + def ==(other) + eql?(other) + end + + def eql?(other) + self.code == other.code and + self.domain == other.domain and + self.message == other.message and + self.level == other.level and + self.file == other.file and + self.line == other.line and + self.str1 == other.str1 and + self.str2 == other.str2 and + self.str3 == other.str3 and + self.int1 == other.int1 and + self.int2 == other.int2 and + self.ctxt == other.ctxt and + self.node == other.node + rescue + false + end + + def level_to_s + case self.level + when NONE + '' + when WARNING + 'Warning:' + when ERROR + 'Error:' + when FATAL + 'Fatal error:' + end + end + + def domain_to_s + DOMAIN_CODE_MAP[self.domain].to_s + end + + def code_to_s + ERROR_CODE_MAP[self.code].to_s + end + + def to_s + msg = super + msg = msg ? msg.strip: '' + + if self.line + sprintf("%s %s at %s:%d.", self.level_to_s, msg, + self.file, self.line) + else + sprintf("%s %s.", self.level_to_s, msg) + end + end + end + end +end + +LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER) diff --git a/lib/libxml/hpricot.rb b/lib/libxml/hpricot.rb index 3e750ef0..955917b5 100644 --- a/lib/libxml/hpricot.rb +++ b/lib/libxml/hpricot.rb @@ -1,78 +1,78 @@ -# encoding: UTF-8 - -## Provide hpricot API for libxml. Provided by Michael Guterl, -## inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml -# -#class String -# def to_libxml_doc -# xp = XML::Parser.new -# xp.string = self -# xp.parse -# end -#end -# -#module LibXML -# module XML -# class Document -# alias :search :find -# end -# -# class Node -# # find the child node with the given xpath -# def at(xpath) -# self.find_first(xpath) -# end -# -# # find the array of child nodes matching the given xpath -# def search(xpath) -# results = self.find(xpath).to_a -# if block_given? -# results.each do |result| -# yield result -# end -# end -# return results -# end -# -# def /(xpath) -# search(xpath) -# end -# -# # return the inner contents of this node as a string -# def inner_xml -# child.to_s -# end -# -# # alias for inner_xml -# def inner_html -# inner_xml -# end -# -# # return this node and its contents as an xml string -# def to_xml -# self.to_s -# end -# -# # alias for path -# def xpath -# self.path -# end -# -# def find_with_default_ns(xpath_expr, namespace=nil) -# find_base(xpath_expr, namespace || default_namespaces) -# end -# -# def find_first_with_default_ns(xpath_expr, namespace=nil) -# find_first_base(xpath_expr, namespace || default_namespaces) -# end -# -## alias_method :find_base, :find unless method_defined?(:find_base) -## alias_method :find, :find_with_default_ns -## alias_method :find_first_base, :find_first unless method_defined?(:find_first_base) -## alias_method :find_first, :find_first_with_default_ns -## alias :child? :first? -## alias :children? :first? -## alias :child :first -# end -# end +# encoding: UTF-8 + +## Provide hpricot API for libxml. Provided by Michael Guterl, +## inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml +# +#class String +# def to_libxml_doc +# xp = XML::Parser.new +# xp.string = self +# xp.parse +# end +#end +# +#module LibXML +# module XML +# class Document +# alias :search :find +# end +# +# class Node +# # find the child node with the given xpath +# def at(xpath) +# self.find_first(xpath) +# end +# +# # find the array of child nodes matching the given xpath +# def search(xpath) +# results = self.find(xpath).to_a +# if block_given? +# results.each do |result| +# yield result +# end +# end +# return results +# end +# +# def /(xpath) +# search(xpath) +# end +# +# # return the inner contents of this node as a string +# def inner_xml +# child.to_s +# end +# +# # alias for inner_xml +# def inner_html +# inner_xml +# end +# +# # return this node and its contents as an xml string +# def to_xml +# self.to_s +# end +# +# # alias for path +# def xpath +# self.path +# end +# +# def find_with_default_ns(xpath_expr, namespace=nil) +# find_base(xpath_expr, namespace || default_namespaces) +# end +# +# def find_first_with_default_ns(xpath_expr, namespace=nil) +# find_first_base(xpath_expr, namespace || default_namespaces) +# end +# +## alias_method :find_base, :find unless method_defined?(:find_base) +## alias_method :find, :find_with_default_ns +## alias_method :find_first_base, :find_first unless method_defined?(:find_first_base) +## alias_method :find_first, :find_first_with_default_ns +## alias :child? :first? +## alias :children? :first? +## alias :child :first +# end +# end #end \ No newline at end of file diff --git a/lib/libxml/html_parser.rb b/lib/libxml/html_parser.rb index 2e8b4f3b..2242281a 100644 --- a/lib/libxml/html_parser.rb +++ b/lib/libxml/html_parser.rb @@ -1,96 +1,96 @@ -# encoding: UTF-8 - -module LibXML - module XML - class HTMLParser - # call-seq: - # XML::HTMLParser.file(path) -> XML::HTMLParser - # XML::HTMLParser.file(path, encoding: XML::Encoding::UTF_8, - # options: XML::HTMLParser::Options::NOENT) -> XML::HTMLParser - # - # Creates a new parser by parsing the specified file or uri. - # - # Parameters: - # - # path - Path to file to parse - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::HTMLParser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.file(path, encoding: nil, options: nil) - context = XML::HTMLParser::Context.file(path) - context.encoding = encoding if encoding - context.options = options if options - self.new(context) - end - - # call-seq: - # XML::HTMLParser.io(io) -> XML::HTMLParser - # XML::HTMLParser.io(io, encoding: XML::Encoding::UTF_8, - # options: XML::HTMLParser::Options::NOENT - # base_uri: "http://libxml.org") -> XML::HTMLParser - # - # Creates a new reader by parsing the specified io object. - # - # Parameters: - # - # io - io object that contains the xml to parser - # base_uri - The base url for the parsed document. - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::HTMLParser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.io(io, base_uri: nil, encoding: nil, options: nil) - context = XML::HTMLParser::Context.io(io) - context.base_uri = base_uri if base_uri - context.encoding = encoding if encoding - context.options = options if options - self.new(context) - end - - # call-seq: - # XML::HTMLParser.string(string) - # XML::HTMLParser.string(string, encoding: XML::Encoding::UTF_8, - # options: XML::HTMLParser::Options::NOENT - # base_uri: "http://libxml.org") -> XML::HTMLParser - # - # Creates a new parser by parsing the specified string. - # - # Parameters: - # - # string - String to parse - # base_uri - The base url for the parsed document. - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::HTMLParser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.string(string, base_uri: nil, encoding: nil, options: nil) - context = XML::HTMLParser::Context.string(string) - context.base_uri = base_uri if base_uri - context.encoding = encoding if encoding - context.options = options if options - self.new(context) - end - - # :enddoc: - - def file=(value) - warn("XML::HTMLParser#file is deprecated. Use XML::HTMLParser.file instead") - @context = XML::HTMLParser::Context.file(value) - end - - def io=(value) - warn("XML::HTMLParser#io is deprecated. Use XML::HTMLParser.io instead") - @context = XML::HTMLParser::Context.io(value) - end - - def string=(value) - warn("XML::HTMLParser#string is deprecated. Use XML::HTMLParser.string instead") - @context = XML::HTMLParser::Context.string(value) - end - end - end -end +# encoding: UTF-8 + +module LibXML + module XML + class HTMLParser + # call-seq: + # XML::HTMLParser.file(path) -> XML::HTMLParser + # XML::HTMLParser.file(path, encoding: XML::Encoding::UTF_8, + # options: XML::HTMLParser::Options::NOENT) -> XML::HTMLParser + # + # Creates a new parser by parsing the specified file or uri. + # + # Parameters: + # + # path - Path to file to parse + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::HTMLParser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.file(path, encoding: nil, options: nil) + context = XML::HTMLParser::Context.file(path) + context.encoding = encoding if encoding + context.options = options if options + self.new(context) + end + + # call-seq: + # XML::HTMLParser.io(io) -> XML::HTMLParser + # XML::HTMLParser.io(io, encoding: XML::Encoding::UTF_8, + # options: XML::HTMLParser::Options::NOENT + # base_uri: "http://libxml.org") -> XML::HTMLParser + # + # Creates a new reader by parsing the specified io object. + # + # Parameters: + # + # io - io object that contains the xml to parser + # base_uri - The base url for the parsed document. + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::HTMLParser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.io(io, base_uri: nil, encoding: nil, options: nil) + context = XML::HTMLParser::Context.io(io) + context.base_uri = base_uri if base_uri + context.encoding = encoding if encoding + context.options = options if options + self.new(context) + end + + # call-seq: + # XML::HTMLParser.string(string) + # XML::HTMLParser.string(string, encoding: XML::Encoding::UTF_8, + # options: XML::HTMLParser::Options::NOENT + # base_uri: "http://libxml.org") -> XML::HTMLParser + # + # Creates a new parser by parsing the specified string. + # + # Parameters: + # + # string - String to parse + # base_uri - The base url for the parsed document. + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::HTMLParser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.string(string, base_uri: nil, encoding: nil, options: nil) + context = XML::HTMLParser::Context.string(string) + context.base_uri = base_uri if base_uri + context.encoding = encoding if encoding + context.options = options if options + self.new(context) + end + + # :enddoc: + + def file=(value) + warn("XML::HTMLParser#file is deprecated. Use XML::HTMLParser.file instead") + @context = XML::HTMLParser::Context.file(value) + end + + def io=(value) + warn("XML::HTMLParser#io is deprecated. Use XML::HTMLParser.io instead") + @context = XML::HTMLParser::Context.io(value) + end + + def string=(value) + warn("XML::HTMLParser#string is deprecated. Use XML::HTMLParser.string instead") + @context = XML::HTMLParser::Context.string(value) + end + end + end +end diff --git a/lib/libxml/namespace.rb b/lib/libxml/namespace.rb index 7547b222..8ec7a671 100644 --- a/lib/libxml/namespace.rb +++ b/lib/libxml/namespace.rb @@ -1,62 +1,62 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Namespace - include Comparable - include Enumerable - - # call-seq: - # namespace1 <=> namespace2 - # - # Compares two namespace objects. Namespace objects are - # considered equal if their prefixes and hrefs are the same. - def <=>(other) - if self.prefix.nil? and other.prefix.nil? - self.href <=> other.href - elsif self.prefix.nil? - -1 - elsif other.prefix.nil? - 1 - else - self.prefix <=> other.prefix - end - end - - # call-seq: - # namespace.each {|ns| .. } - # - # libxml stores namespaces in memory as a linked list. - # Use the each method to iterate over the list. Note - # the first namespace in the loop is the current namespace. - # - # Usage: - # namespace.each do |ns| - # .. - # end - def each - ns = self - - while ns - yield ns - ns = ns.next - end - end - - # call-seq: - # namespace.to_s -> "string" - # - # Returns the string represenation of a namespace. - # - # Usage: - # namespace.to_s - def to_s - if self.prefix - "#{self.prefix}:#{self.href}" - else - self.href - end - end - end - end +# encoding: UTF-8 + +module LibXML + module XML + class Namespace + include Comparable + include Enumerable + + # call-seq: + # namespace1 <=> namespace2 + # + # Compares two namespace objects. Namespace objects are + # considered equal if their prefixes and hrefs are the same. + def <=>(other) + if self.prefix.nil? and other.prefix.nil? + self.href <=> other.href + elsif self.prefix.nil? + -1 + elsif other.prefix.nil? + 1 + else + self.prefix <=> other.prefix + end + end + + # call-seq: + # namespace.each {|ns| .. } + # + # libxml stores namespaces in memory as a linked list. + # Use the each method to iterate over the list. Note + # the first namespace in the loop is the current namespace. + # + # Usage: + # namespace.each do |ns| + # .. + # end + def each + ns = self + + while ns + yield ns + ns = ns.next + end + end + + # call-seq: + # namespace.to_s -> "string" + # + # Returns the string represenation of a namespace. + # + # Usage: + # namespace.to_s + def to_s + if self.prefix + "#{self.prefix}:#{self.href}" + else + self.href + end + end + end + end end \ No newline at end of file diff --git a/lib/libxml/namespaces.rb b/lib/libxml/namespaces.rb index ce3ed707..3995f57f 100644 --- a/lib/libxml/namespaces.rb +++ b/lib/libxml/namespaces.rb @@ -1,38 +1,38 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Namespaces - # call-seq: - # namespace.default -> XML::Namespace - # - # Returns the default namespace for this node or nil. - # - # Usage: - # doc = XML::Document.string('') - # ns = doc.root.namespaces.default_namespace - # assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/') - def default - find_by_prefix(nil) - end - - # call-seq: - # namespace.default_prefix = "string" - # - # Assigns a name (prefix) to the default namespace. - # This makes it much easier to perform XML::XPath - # searches. - # - # Usage: - # doc = XML::Document.string('') - # doc.root.namespaces.default_prefix = 'soap' - # node = doc.root.find_first('soap:Envelope') - def default_prefix=(prefix) - # Find default prefix - ns = find_by_prefix(nil) - raise(ArgumentError, "No default namespace was found") unless ns - Namespace.new(self.node, prefix, ns.href) - end - end - end +# encoding: UTF-8 + +module LibXML + module XML + class Namespaces + # call-seq: + # namespace.default -> XML::Namespace + # + # Returns the default namespace for this node or nil. + # + # Usage: + # doc = XML::Document.string('') + # ns = doc.root.namespaces.default_namespace + # assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/') + def default + find_by_prefix(nil) + end + + # call-seq: + # namespace.default_prefix = "string" + # + # Assigns a name (prefix) to the default namespace. + # This makes it much easier to perform XML::XPath + # searches. + # + # Usage: + # doc = XML::Document.string('') + # doc.root.namespaces.default_prefix = 'soap' + # node = doc.root.find_first('soap:Envelope') + def default_prefix=(prefix) + # Find default prefix + ns = find_by_prefix(nil) + raise(ArgumentError, "No default namespace was found") unless ns + Namespace.new(self.node, prefix, ns.href) + end + end + end end \ No newline at end of file diff --git a/lib/libxml/node.rb b/lib/libxml/node.rb index 2ac35657..638c5a78 100644 --- a/lib/libxml/node.rb +++ b/lib/libxml/node.rb @@ -1,323 +1,323 @@ -# encoding: UTF-8 - -require 'stringio' - -module LibXML - module XML - class Node - # Determines whether this node has attributes - def attributes? - attributes.length > 0 - end - - # Create a shallow copy of the node. To create - # a deep copy call Node#copy(true) - def clone - copy(false) - end - - # call-seq: - # node.inner_xml -> "string" - # node.inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string" - # - # Converts a node's children to a string representation. To include - # the node, use XML::Node#to_s. For more information about - # the supported options, see XML::Node#to_s. - def inner_xml(options = Hash.new) - io = nil - self.each do |node| - xml = node.to_s(options) - # Create the string IO here since we now know the encoding - io = create_string_io(xml) unless io - io << xml - end - - io ? io.string : nil - end - - # :call-seq: - # node.dup -> XML::Node - # - # Create a shallow copy of the node. To create - # a deep copy call Node#copy(true) - def dup - copy(false) - end - - # call-seq: - # node.context(namespaces=nil) -> XPath::Context - # - # Returns a new XML::XPathContext for the current node. - # - # Namespaces is an optional array of XML::NS objects - def context(nslist = nil) - if not self.doc - raise(TypeError, "A node must belong to a document before a xpath context can be created") - end - - context = XPath::Context.new(self.doc) - context.node = self - context.register_namespaces_from_node(self) - context.register_namespaces_from_node(self.doc.root) - context.register_namespaces(nslist) if nslist - context - end - - # call-seq: - # node.find(namespaces=nil) -> XPath::XPathObject - # - # Return nodes matching the specified xpath expression. - # For more information, please refer to the documentation - # for XML::Document#find. - # - # Namespaces is an optional array of XML::NS objects - def find(xpath, nslist = nil) - self.context(nslist).find(xpath) - end - - # call-seq: - # node.find_first(namespaces=nil) -> XML::Node - # - # Return the first node matching the specified xpath expression. - # For more information, please refer to the documentation - # for the #find method. - def find_first(xpath, nslist = nil) - find(xpath, nslist).first - end - - # call-seq: - # node.namespacess -> XML::Namespaces - # - # Returns this node's XML::Namespaces object, - # which is used to access the namespaces - # associated with this node. - def namespaces - @namespaces ||= XML::Namespaces.new(self) - end - - # ------- Traversal ---------------- - # Iterates over this node's attributes. - # - # doc = XML::Document.new('model/books.xml') - # doc.root.each_attr {|attr| puts attr} - def each_attr - attributes.each do |attr| - yield(attr) - end - end - - # Iterates over this node's child elements (nodes - # that have a node_type == ELEMENT_NODE). - # - # doc = XML::Document.new('model/books.xml') - # doc.root.each_element {|element| puts element} - def each_element - each do |node| - yield(node) if node.node_type == ELEMENT_NODE - end - end - - # Determines whether this node has a parent node - def parent? - not parent.nil? - end - - # Determines whether this node has a first node - def first? - not first.nil? - end - - # Returns this node's children as an array. - def children - entries - end - - # Determines whether this node has a next node - def next? - not self.next.nil? - end - - # Determines whether this node has a previous node - def prev? - not prev.nil? - end - - # Determines whether this node has a last node - def last? - not last.nil? - end - - - # ------- Node Types ---------------- - - # Returns this node's type name - def node_type_name - case node_type - # Most common choices first - when ATTRIBUTE_NODE - 'attribute' - when DOCUMENT_NODE - 'document_xml' - when ELEMENT_NODE - 'element' - when TEXT_NODE - 'text' - - # Now the rest - when ATTRIBUTE_DECL - 'attribute_decl' - when CDATA_SECTION_NODE - 'cdata' - when COMMENT_NODE - 'comment' - when DOCB_DOCUMENT_NODE - 'document_docbook' - when DOCUMENT_FRAG_NODE - 'fragment' - when DOCUMENT_TYPE_NODE - 'doctype' - when DTD_NODE - 'dtd' - when ELEMENT_DECL - 'elem_decl' - when ENTITY_DECL - 'entity_decl' - when ENTITY_NODE - 'entity' - when ENTITY_REF_NODE - 'entity_ref' - when HTML_DOCUMENT_NODE - 'document_html' - when NAMESPACE_DECL - 'namespace' - when NOTATION_NODE - 'notation' - when PI_NODE - 'pi' - when XINCLUDE_START - 'xinclude_start' - when XINCLUDE_END - 'xinclude_end' - else - raise(UnknownType, "Unknown node type: %n", node.node_type); - end - end - - # Specifies if this is an attribute node - def attribute? - node_type == ATTRIBUTE_NODE - end - - # Specifies if this is an attribute declaration node - def attribute_decl? - node_type == ATTRIBUTE_DECL - end - - # Specifies if this is an CDATA node - def cdata? - node_type == CDATA_SECTION_NODE - end - - # Specifies if this is an comment node - def comment? - node_type == COMMENT_NODE - end - - # Specifies if this is an docbook node - def docbook_doc? - node_type == DOCB_DOCUMENT_NODE - end - - # Specifies if this is an doctype node - def doctype? - node_type == DOCUMENT_TYPE_NODE - end - - # Specifies if this is an document node - def document? - node_type == DOCUMENT_NODE - end - - # Specifies if this is an DTD node - def dtd? - node_type == DTD_NODE - end - - # Specifies if this is an element node - def element? - node_type == ELEMENT_NODE - end - - # Specifies if this is an entity node - def entity? - node_type == ENTITY_NODE - end - - # Specifies if this is an element declaration node - def element_decl? - node_type == ELEMENT_DECL - end - - # Specifies if this is an entity reference node - def entity_ref? - node_type == ENTITY_REF_NODE - end - - # Specifies if this is a fragment node - def fragment? - node_type == DOCUMENT_FRAG_NODE - end - - # Specifies if this is a html document node - def html_doc? - node_type == HTML_DOCUMENT_NODE - end - - # Specifies if this is a namespace node (not if it - # has a namepsace) - def namespace? - node_type == NAMESPACE_DECL - end - - # Specifies if this is a notation node - def notation? - node_type == NOTATION_NODE - end - - # Specifies if this is a processiong instruction node - def pi? - node_type == PI_NODE - end - - # Specifies if this is a text node - def text? - node_type == TEXT_NODE - end - - # Specifies if this is an xinclude end node - def xinclude_end? - node_type == XINCLUDE_END - end - - # Specifies if this is an xinclude start node - def xinclude_start? - node_type == XINCLUDE_START - end - - alias :child? :first? - alias :children? :first? - alias :child :first - alias :each_child :each - - private - - def create_string_io(xml) - result = StringIO.new("") - if defined?(::Encoding) - result.set_encoding(xml.encoding) - end - result - end - end - end -end +# encoding: UTF-8 + +require 'stringio' + +module LibXML + module XML + class Node + # Determines whether this node has attributes + def attributes? + attributes.length > 0 + end + + # Create a shallow copy of the node. To create + # a deep copy call Node#copy(true) + def clone + copy(false) + end + + # call-seq: + # node.inner_xml -> "string" + # node.inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string" + # + # Converts a node's children to a string representation. To include + # the node, use XML::Node#to_s. For more information about + # the supported options, see XML::Node#to_s. + def inner_xml(options = Hash.new) + io = nil + self.each do |node| + xml = node.to_s(options) + # Create the string IO here since we now know the encoding + io = create_string_io(xml) unless io + io << xml + end + + io ? io.string : nil + end + + # :call-seq: + # node.dup -> XML::Node + # + # Create a shallow copy of the node. To create + # a deep copy call Node#copy(true) + def dup + copy(false) + end + + # call-seq: + # node.context(namespaces=nil) -> XPath::Context + # + # Returns a new XML::XPathContext for the current node. + # + # Namespaces is an optional array of XML::NS objects + def context(nslist = nil) + if not self.doc + raise(TypeError, "A node must belong to a document before a xpath context can be created") + end + + context = XPath::Context.new(self.doc) + context.node = self + context.register_namespaces_from_node(self) + context.register_namespaces_from_node(self.doc.root) + context.register_namespaces(nslist) if nslist + context + end + + # call-seq: + # node.find(namespaces=nil) -> XPath::XPathObject + # + # Return nodes matching the specified xpath expression. + # For more information, please refer to the documentation + # for XML::Document#find. + # + # Namespaces is an optional array of XML::NS objects + def find(xpath, nslist = nil) + self.context(nslist).find(xpath) + end + + # call-seq: + # node.find_first(namespaces=nil) -> XML::Node + # + # Return the first node matching the specified xpath expression. + # For more information, please refer to the documentation + # for the #find method. + def find_first(xpath, nslist = nil) + find(xpath, nslist).first + end + + # call-seq: + # node.namespacess -> XML::Namespaces + # + # Returns this node's XML::Namespaces object, + # which is used to access the namespaces + # associated with this node. + def namespaces + @namespaces ||= XML::Namespaces.new(self) + end + + # ------- Traversal ---------------- + # Iterates over this node's attributes. + # + # doc = XML::Document.new('model/books.xml') + # doc.root.each_attr {|attr| puts attr} + def each_attr + attributes.each do |attr| + yield(attr) + end + end + + # Iterates over this node's child elements (nodes + # that have a node_type == ELEMENT_NODE). + # + # doc = XML::Document.new('model/books.xml') + # doc.root.each_element {|element| puts element} + def each_element + each do |node| + yield(node) if node.node_type == ELEMENT_NODE + end + end + + # Determines whether this node has a parent node + def parent? + not parent.nil? + end + + # Determines whether this node has a first node + def first? + not first.nil? + end + + # Returns this node's children as an array. + def children + entries + end + + # Determines whether this node has a next node + def next? + not self.next.nil? + end + + # Determines whether this node has a previous node + def prev? + not prev.nil? + end + + # Determines whether this node has a last node + def last? + not last.nil? + end + + + # ------- Node Types ---------------- + + # Returns this node's type name + def node_type_name + case node_type + # Most common choices first + when ATTRIBUTE_NODE + 'attribute' + when DOCUMENT_NODE + 'document_xml' + when ELEMENT_NODE + 'element' + when TEXT_NODE + 'text' + + # Now the rest + when ATTRIBUTE_DECL + 'attribute_decl' + when CDATA_SECTION_NODE + 'cdata' + when COMMENT_NODE + 'comment' + when DOCB_DOCUMENT_NODE + 'document_docbook' + when DOCUMENT_FRAG_NODE + 'fragment' + when DOCUMENT_TYPE_NODE + 'doctype' + when DTD_NODE + 'dtd' + when ELEMENT_DECL + 'elem_decl' + when ENTITY_DECL + 'entity_decl' + when ENTITY_NODE + 'entity' + when ENTITY_REF_NODE + 'entity_ref' + when HTML_DOCUMENT_NODE + 'document_html' + when NAMESPACE_DECL + 'namespace' + when NOTATION_NODE + 'notation' + when PI_NODE + 'pi' + when XINCLUDE_START + 'xinclude_start' + when XINCLUDE_END + 'xinclude_end' + else + raise(UnknownType, "Unknown node type: %n", node.node_type); + end + end + + # Specifies if this is an attribute node + def attribute? + node_type == ATTRIBUTE_NODE + end + + # Specifies if this is an attribute declaration node + def attribute_decl? + node_type == ATTRIBUTE_DECL + end + + # Specifies if this is an CDATA node + def cdata? + node_type == CDATA_SECTION_NODE + end + + # Specifies if this is an comment node + def comment? + node_type == COMMENT_NODE + end + + # Specifies if this is an docbook node + def docbook_doc? + node_type == DOCB_DOCUMENT_NODE + end + + # Specifies if this is an doctype node + def doctype? + node_type == DOCUMENT_TYPE_NODE + end + + # Specifies if this is an document node + def document? + node_type == DOCUMENT_NODE + end + + # Specifies if this is an DTD node + def dtd? + node_type == DTD_NODE + end + + # Specifies if this is an element node + def element? + node_type == ELEMENT_NODE + end + + # Specifies if this is an entity node + def entity? + node_type == ENTITY_NODE + end + + # Specifies if this is an element declaration node + def element_decl? + node_type == ELEMENT_DECL + end + + # Specifies if this is an entity reference node + def entity_ref? + node_type == ENTITY_REF_NODE + end + + # Specifies if this is a fragment node + def fragment? + node_type == DOCUMENT_FRAG_NODE + end + + # Specifies if this is a html document node + def html_doc? + node_type == HTML_DOCUMENT_NODE + end + + # Specifies if this is a namespace node (not if it + # has a namepsace) + def namespace? + node_type == NAMESPACE_DECL + end + + # Specifies if this is a notation node + def notation? + node_type == NOTATION_NODE + end + + # Specifies if this is a processiong instruction node + def pi? + node_type == PI_NODE + end + + # Specifies if this is a text node + def text? + node_type == TEXT_NODE + end + + # Specifies if this is an xinclude end node + def xinclude_end? + node_type == XINCLUDE_END + end + + # Specifies if this is an xinclude start node + def xinclude_start? + node_type == XINCLUDE_START + end + + alias :child? :first? + alias :children? :first? + alias :child :first + alias :each_child :each + + private + + def create_string_io(xml) + result = StringIO.new("") + if defined?(::Encoding) + result.set_encoding(xml.encoding) + end + result + end + end + end +end diff --git a/lib/libxml/parser.rb b/lib/libxml/parser.rb index 7ba5a9b7..a78e96cf 100644 --- a/lib/libxml/parser.rb +++ b/lib/libxml/parser.rb @@ -1,103 +1,103 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Parser - # call-seq: - # XML::Parser.document(document) -> XML::Parser - # - # Creates a new parser for the specified document. - # - # Parameters: - # - # document - A preparsed document. - def self.document(doc) - context = XML::Parser::Context.document(doc) - self.new(context) - end - - # call-seq: - # XML::Parser.file(path) -> XML::Parser - # XML::Parser.file(path, encoding: XML::Encoding::UTF_8, - # options: XML::Parser::Options::NOENT) -> XML::Parser - # - # Creates a new parser for the specified file or uri. - # - # Parameters: - # - # path - Path to file - # base_uri - The base url for the parsed document. - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::Parser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.file(path, base_uri: nil, encoding: nil, options: nil) - context = XML::Parser::Context.file(path) - context.base_uri = base_uri if base_uri - context.encoding = encoding if encoding - context.options = options if options - self.new(context) - end - - # call-seq: - # XML::Parser.io(io) -> XML::Parser - # XML::Parser.io(io, encoding: XML::Encoding::UTF_8, - # options: XML::Parser::Options::NOENT - # base_uri: "http://libxml.org") -> XML::Parser - # - # Creates a new parser for the specified io object. - # - # Parameters: - # - # io - io object that contains the xml to parser - # base_uri - The base url for the parsed document. - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::Parser::Options. Mutliple options can be combined - # by using Bitwise OR (|). - def self.io(io, base_uri: nil, encoding: nil, options: nil) - context = XML::Parser::Context.io(io) - context.base_uri = base_uri if base_uri - context.encoding = encoding if encoding - context.options = options if options - self.new(context) - end - - # call-seq: - # XML::Parser.string(string) - # XML::Parser.string(string, encoding: XML::Encoding::UTF_8, - # options: XML::Parser::Options::NOENT - # base_uri: "http://libxml.org") -> XML::Parser - # - # Creates a new parser by parsing the specified string. - # - # Parameters: - # - # string - The string to parse - # base_uri - The base url for the parsed document. - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - # options - Parser options. Valid values are the constants defined on - # XML::Parser::Options. Multiple options can be combined - # by using Bitwise OR (|). - def self.string(string, base_uri: nil, encoding: nil, options: nil) - context = XML::Parser::Context.string(string) - context.base_uri = base_uri if base_uri - context.encoding = encoding if encoding - context.options = options if options - self.new(context) - end - - def self.register_error_handler(proc) - warn('Parser.register_error_handler is deprecated. Use Error.set_handler instead') - if proc.nil? - Error.reset_handler - else - Error.set_handler(&proc) - end - end - end - end +# encoding: UTF-8 + +module LibXML + module XML + class Parser + # call-seq: + # XML::Parser.document(document) -> XML::Parser + # + # Creates a new parser for the specified document. + # + # Parameters: + # + # document - A preparsed document. + def self.document(doc) + context = XML::Parser::Context.document(doc) + self.new(context) + end + + # call-seq: + # XML::Parser.file(path) -> XML::Parser + # XML::Parser.file(path, encoding: XML::Encoding::UTF_8, + # options: XML::Parser::Options::NOENT) -> XML::Parser + # + # Creates a new parser for the specified file or uri. + # + # Parameters: + # + # path - Path to file + # base_uri - The base url for the parsed document. + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::Parser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.file(path, base_uri: nil, encoding: nil, options: nil) + context = XML::Parser::Context.file(path) + context.base_uri = base_uri if base_uri + context.encoding = encoding if encoding + context.options = options if options + self.new(context) + end + + # call-seq: + # XML::Parser.io(io) -> XML::Parser + # XML::Parser.io(io, encoding: XML::Encoding::UTF_8, + # options: XML::Parser::Options::NOENT + # base_uri: "http://libxml.org") -> XML::Parser + # + # Creates a new parser for the specified io object. + # + # Parameters: + # + # io - io object that contains the xml to parser + # base_uri - The base url for the parsed document. + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::Parser::Options. Mutliple options can be combined + # by using Bitwise OR (|). + def self.io(io, base_uri: nil, encoding: nil, options: nil) + context = XML::Parser::Context.io(io) + context.base_uri = base_uri if base_uri + context.encoding = encoding if encoding + context.options = options if options + self.new(context) + end + + # call-seq: + # XML::Parser.string(string) + # XML::Parser.string(string, encoding: XML::Encoding::UTF_8, + # options: XML::Parser::Options::NOENT + # base_uri: "http://libxml.org") -> XML::Parser + # + # Creates a new parser by parsing the specified string. + # + # Parameters: + # + # string - The string to parse + # base_uri - The base url for the parsed document. + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + # options - Parser options. Valid values are the constants defined on + # XML::Parser::Options. Multiple options can be combined + # by using Bitwise OR (|). + def self.string(string, base_uri: nil, encoding: nil, options: nil) + context = XML::Parser::Context.string(string) + context.base_uri = base_uri if base_uri + context.encoding = encoding if encoding + context.options = options if options + self.new(context) + end + + def self.register_error_handler(proc) + warn('Parser.register_error_handler is deprecated. Use Error.set_handler instead') + if proc.nil? + Error.reset_handler + else + Error.set_handler(&proc) + end + end + end + end end \ No newline at end of file diff --git a/lib/libxml/sax_callbacks.rb b/lib/libxml/sax_callbacks.rb index a5ee0934..af223222 100644 --- a/lib/libxml/sax_callbacks.rb +++ b/lib/libxml/sax_callbacks.rb @@ -1,180 +1,180 @@ -# encoding: UTF-8 - -module LibXML - module XML - class SaxParser - module Callbacks - # Called for a CDATA block event. - def on_cdata_block(cdata) - end - - # Called for a characters event. - def on_characters(chars) - end - - # Called for a comment event. - def on_comment(msg) - end - - # Called for a end document event. - def on_end_document - end - - # Called for a end element event. - def on_end_element_ns(name, prefix, uri) - end - - # Called for parser errors. - def on_error(msg) - end - - # Called for an external subset event. - def on_external_subset(name, external_id, system_id) - end - - # Called for an external subset notification event. - def on_has_external_subset - end - - # Called for an internal subset notification event. - def on_has_internal_subset - end - - # Called for an internal subset event. - def on_internal_subset(name, external_id, system_id) - end - - # Called for 'is standalone' event. - def on_is_standalone - end - - # Called for an processing instruction event. - def on_processing_instruction(target, data) - end - - # Called for a reference event. - def on_reference(name) - end - - # Called for a start document event. - def on_start_document - end - - # Called for a start element event. - def on_start_element_ns(name, attributes, prefix, uri, namespaces) - end - end - - module VerboseCallbacks - # Called for a CDATA block event. - def on_cdata_block(cdata) - STDOUT << "on_cdata_block" << "\n" << - " cdata " << cdata << "\n" - STDOUT.flush - end - - # Called for a characters event. - def on_characters(chars) - STDOUT << "on_characters" << "\n" << - " chars " << chars << "\n" - STDOUT.flush - end - - # Called for a comment event. - def on_comment(comment) - STDOUT << "on_comment" << "\n" << - " comment: " << comment << "\n" - STDOUT.flush - end - - # Called for a end document event. - def on_end_document - STDOUT << "on_end_document\n" - STDOUT.flush - end - - # Called for a end element event. - def on_end_element_ns(name, prefix, uri) - STDOUT << "on_end_element_ns" << "\n" << - " name: " << name << "\n" << - " prefix: " << prefix << "\n" << - " uri: " << uri << "\n" - STDOUT.flush - end - - # Called for parser errors. - def on_error(error) - STDOUT << "on_error" << "\n" - " error " << error << "\n" - STDOUT.flush - end - - # Called for an external subset event. - def on_external_subset(name, external_id, system_id) - STDOUT << "on_external_subset" << "\n" - " external_id " << external_id << "\n" << - " system_id " << system_id << "\n" - STDOUT.flush - end - - # Called for an external subset notification event. - def on_has_external_subset - STDOUT << "on_has_internal_subset\n" - STDOUT.flush - end - - # Called for an internal subset notification event. - def on_has_internal_subset - STDOUT << "on_has_internal_subset\n" - STDOUT.flush - end - - # Called for an internal subset event. - def on_internal_subset(name, external_id, system_id) - STDOUT << "on_internal_subset" << "\n" - " external_id " << external_id << "\n" << - " system_id " << system_id << "\n" - STDOUT.flush - end - - # Called for 'is standalone' event. - def on_is_standalone - STDOUT << "on_is_standalone\n" - STDOUT.flush - end - - # Called for an processing instruction event. - def on_processing_instruction(target, data) - STDOUT << "on_characters" << "\n" - " target: " << target << "\n" << - " data: " << data << "\n" - STDOUT.flush - end - - # Called for a reference event. - def on_reference(name) - STDOUT << "on_reference:" << "\n" << - " name:" << name << "\n" - STDOUT.flush - end - - # Called for a start document event. - def on_start_document - STDOUT << "on_start_document\n" - STDOUT.flush - end - - # Called for a start element event. - def on_start_element_ns(name, attributes, prefix, uri, namespaces) - STDOUT << "on_start_element_ns" << "\n" << - " name: " << name << "\n" << - " attr: " << (attributes || Hash.new).inspect << "\n" << - " prefix: " << prefix << "\n" << - " uri: " << uri << "\n" << - " ns_defs: " << (namespaces || Hash.new).inspect << "\n" - STDOUT.flush - end - end - end - end +# encoding: UTF-8 + +module LibXML + module XML + class SaxParser + module Callbacks + # Called for a CDATA block event. + def on_cdata_block(cdata) + end + + # Called for a characters event. + def on_characters(chars) + end + + # Called for a comment event. + def on_comment(msg) + end + + # Called for a end document event. + def on_end_document + end + + # Called for a end element event. + def on_end_element_ns(name, prefix, uri) + end + + # Called for parser errors. + def on_error(msg) + end + + # Called for an external subset event. + def on_external_subset(name, external_id, system_id) + end + + # Called for an external subset notification event. + def on_has_external_subset + end + + # Called for an internal subset notification event. + def on_has_internal_subset + end + + # Called for an internal subset event. + def on_internal_subset(name, external_id, system_id) + end + + # Called for 'is standalone' event. + def on_is_standalone + end + + # Called for an processing instruction event. + def on_processing_instruction(target, data) + end + + # Called for a reference event. + def on_reference(name) + end + + # Called for a start document event. + def on_start_document + end + + # Called for a start element event. + def on_start_element_ns(name, attributes, prefix, uri, namespaces) + end + end + + module VerboseCallbacks + # Called for a CDATA block event. + def on_cdata_block(cdata) + STDOUT << "on_cdata_block" << "\n" << + " cdata " << cdata << "\n" + STDOUT.flush + end + + # Called for a characters event. + def on_characters(chars) + STDOUT << "on_characters" << "\n" << + " chars " << chars << "\n" + STDOUT.flush + end + + # Called for a comment event. + def on_comment(comment) + STDOUT << "on_comment" << "\n" << + " comment: " << comment << "\n" + STDOUT.flush + end + + # Called for a end document event. + def on_end_document + STDOUT << "on_end_document\n" + STDOUT.flush + end + + # Called for a end element event. + def on_end_element_ns(name, prefix, uri) + STDOUT << "on_end_element_ns" << "\n" << + " name: " << name << "\n" << + " prefix: " << prefix << "\n" << + " uri: " << uri << "\n" + STDOUT.flush + end + + # Called for parser errors. + def on_error(error) + STDOUT << "on_error" << "\n" + " error " << error << "\n" + STDOUT.flush + end + + # Called for an external subset event. + def on_external_subset(name, external_id, system_id) + STDOUT << "on_external_subset" << "\n" + " external_id " << external_id << "\n" << + " system_id " << system_id << "\n" + STDOUT.flush + end + + # Called for an external subset notification event. + def on_has_external_subset + STDOUT << "on_has_internal_subset\n" + STDOUT.flush + end + + # Called for an internal subset notification event. + def on_has_internal_subset + STDOUT << "on_has_internal_subset\n" + STDOUT.flush + end + + # Called for an internal subset event. + def on_internal_subset(name, external_id, system_id) + STDOUT << "on_internal_subset" << "\n" + " external_id " << external_id << "\n" << + " system_id " << system_id << "\n" + STDOUT.flush + end + + # Called for 'is standalone' event. + def on_is_standalone + STDOUT << "on_is_standalone\n" + STDOUT.flush + end + + # Called for an processing instruction event. + def on_processing_instruction(target, data) + STDOUT << "on_characters" << "\n" + " target: " << target << "\n" << + " data: " << data << "\n" + STDOUT.flush + end + + # Called for a reference event. + def on_reference(name) + STDOUT << "on_reference:" << "\n" << + " name:" << name << "\n" + STDOUT.flush + end + + # Called for a start document event. + def on_start_document + STDOUT << "on_start_document\n" + STDOUT.flush + end + + # Called for a start element event. + def on_start_element_ns(name, attributes, prefix, uri, namespaces) + STDOUT << "on_start_element_ns" << "\n" << + " name: " << name << "\n" << + " attr: " << (attributes || Hash.new).inspect << "\n" << + " prefix: " << prefix << "\n" << + " uri: " << uri << "\n" << + " ns_defs: " << (namespaces || Hash.new).inspect << "\n" + STDOUT.flush + end + end + end + end end \ No newline at end of file diff --git a/lib/libxml/sax_parser.rb b/lib/libxml/sax_parser.rb index 78cf27d0..93eb7f0e 100644 --- a/lib/libxml/sax_parser.rb +++ b/lib/libxml/sax_parser.rb @@ -1,41 +1,41 @@ -# encoding: UTF-8 - -module LibXML - module XML - class SaxParser - # call-seq: - # XML::SaxParser.file(path) -> XML::SaxParser - # - # Creates a new parser by parsing the specified file or uri. - def self.file(path) - context = XML::Parser::Context.file(path) - self.new(context) - end - - # call-seq: - # XML::SaxParser.io(io) -> XML::SaxParser - # XML::SaxParser.io(io, :encoding => XML::Encoding::UTF_8) -> XML::SaxParser - # - # Creates a new reader by parsing the specified io object. - # - # Parameters: - # - # encoding - The document encoding, defaults to nil. Valid values - # are the encoding constants defined on XML::Encoding. - def self.io(io, options = {}) - context = XML::Parser::Context.io(io) - context.encoding = options[:encoding] if options[:encoding] - self.new(context) - end - - # call-seq: - # XML::SaxParser.string(string) - # - # Creates a new parser by parsing the specified string. - def self.string(string) - context = XML::Parser::Context.string(string) - self.new(context) - end - end - end +# encoding: UTF-8 + +module LibXML + module XML + class SaxParser + # call-seq: + # XML::SaxParser.file(path) -> XML::SaxParser + # + # Creates a new parser by parsing the specified file or uri. + def self.file(path) + context = XML::Parser::Context.file(path) + self.new(context) + end + + # call-seq: + # XML::SaxParser.io(io) -> XML::SaxParser + # XML::SaxParser.io(io, :encoding => XML::Encoding::UTF_8) -> XML::SaxParser + # + # Creates a new reader by parsing the specified io object. + # + # Parameters: + # + # encoding - The document encoding, defaults to nil. Valid values + # are the encoding constants defined on XML::Encoding. + def self.io(io, options = {}) + context = XML::Parser::Context.io(io) + context.encoding = options[:encoding] if options[:encoding] + self.new(context) + end + + # call-seq: + # XML::SaxParser.string(string) + # + # Creates a new parser by parsing the specified string. + def self.string(string) + context = XML::Parser::Context.string(string) + self.new(context) + end + end + end end \ No newline at end of file diff --git a/lib/libxml/tree.rb b/lib/libxml/tree.rb index e04cb26c..58bc47fa 100644 --- a/lib/libxml/tree.rb +++ b/lib/libxml/tree.rb @@ -1,29 +1,29 @@ -# encoding: UTF-8 - -module LibXML - module XML - class Tree # :nodoc: - ELEMENT_NODE = Node::ELEMENT_NODE - ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE - TEXT_NODE = Node::TEXT_NODE - CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE - ENTITY_REF_NODE = Node::ENTITY_REF_NODE - ENTITY_NODE = Node::ENTITY_NODE - PI_NODE = Node::PI_NODE - COMMENT_NODE = Node::COMMENT_NODE - DOCUMENT_NODE = Node::DOCUMENT_NODE - DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE - DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE - NOTATION_NODE = Node::NOTATION_NODE - HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE - DTD_NODE = Node::DTD_NODE - ELEMENT_DECL = Node::ELEMENT_DECL - ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL - ENTITY_DECL = Node::ENTITY_DECL - NAMESPACE_DECL = Node::NAMESPACE_DECL - XINCLUDE_START = Node::XINCLUDE_START - XINCLUDE_END = Node::XINCLUDE_END - DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE - end - end +# encoding: UTF-8 + +module LibXML + module XML + class Tree # :nodoc: + ELEMENT_NODE = Node::ELEMENT_NODE + ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE + TEXT_NODE = Node::TEXT_NODE + CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE + ENTITY_REF_NODE = Node::ENTITY_REF_NODE + ENTITY_NODE = Node::ENTITY_NODE + PI_NODE = Node::PI_NODE + COMMENT_NODE = Node::COMMENT_NODE + DOCUMENT_NODE = Node::DOCUMENT_NODE + DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE + DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE + NOTATION_NODE = Node::NOTATION_NODE + HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE + DTD_NODE = Node::DTD_NODE + ELEMENT_DECL = Node::ELEMENT_DECL + ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL + ENTITY_DECL = Node::ENTITY_DECL + NAMESPACE_DECL = Node::NAMESPACE_DECL + XINCLUDE_START = Node::XINCLUDE_START + XINCLUDE_END = Node::XINCLUDE_END + DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE + end + end end \ No newline at end of file diff --git a/lib/xml.rb b/lib/xml.rb index 2770a1ec..f388b164 100644 --- a/lib/xml.rb +++ b/lib/xml.rb @@ -1,14 +1,14 @@ -# encoding: UTF-8 - -# This file loads libxml and adds the LibXML namespace -# to the toplevel for conveneience. The end result -# is to have XML:: universally exposed. -# -# It is recommend that you only load this file for libs -# that do not have their own namespace, eg. administrative -# scripts, personal programs, etc. For other applications -# require 'libxml' instead and include LibXML into your -# app/libs namespace. - -require 'libxml' +# encoding: UTF-8 + +# This file loads libxml and adds the LibXML namespace +# to the toplevel for conveneience. The end result +# is to have XML:: universally exposed. +# +# It is recommend that you only load this file for libs +# that do not have their own namespace, eg. administrative +# scripts, personal programs, etc. For other applications +# require 'libxml' instead and include LibXML into your +# app/libs namespace. + +require 'libxml' include LibXML \ No newline at end of file diff --git a/lib/xml/libxml.rb b/lib/xml/libxml.rb index a2c50677..2c496ed3 100644 --- a/lib/xml/libxml.rb +++ b/lib/xml/libxml.rb @@ -1,10 +1,10 @@ -# encoding: UTF-8 - -# This is here for backward compatibility. -# -# TODO: DEPRECATE! - -require 'libxml.rb' - -include LibXML - +# encoding: UTF-8 + +# This is here for backward compatibility. +# +# TODO: DEPRECATE! + +require 'libxml.rb' + +include LibXML + diff --git a/test/test_document.rb b/test/test_document.rb index 57ce5582..3367286d 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -1,140 +1,140 @@ -# encoding: UTF-8 -require_relative './test_helper' - -class TestDocument < Minitest::Test - def setup - xp = LibXML::XML::Parser.string('onetwo') - assert_instance_of(LibXML::XML::Parser, xp) - @doc = xp.parse - assert_instance_of(LibXML::XML::Document, @doc) - end - - def teardown - @doc = nil - end - - def test_klass - assert_instance_of(LibXML::XML::Document, @doc) - end - - def test_context - context = @doc.context - assert_instance_of(LibXML::XML::XPath::Context, context) - end - - def test_find - set = @doc.find('/ruby_array/fixnum') - assert_instance_of(LibXML::XML::XPath::Object, set) - assert_raises(NoMethodError) { - set.xpath - } - end - - def test_compression - if LibXML::XML.enabled_zlib? - 0.upto(9) do |i| - assert_equal(i, @doc.compression = i) - assert_equal(i, @doc.compression) - end - - 9.downto(0) do |i| - assert_equal(i, @doc.compression = i) - assert_equal(i, @doc.compression) - end - - 10.upto(20) do |i| - # assert_equal(9, @doc.compression = i) - assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8 - assert_equal(9, @doc.compression) - end - - -1.downto(-10) do |i| - # assert_equal(0, @doc.compression = i) - assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP - assert_equal(0, @doc.compression) - end - end - end - - def test_version - assert_equal('1.0', @doc.version) - - doc = LibXML::XML::Document.new('6.9') - assert_equal('6.9', doc.version) - end - - def test_write_root - @doc.root = LibXML::XML::Node.new('rubynet') - assert_instance_of(LibXML::XML::Node, @doc.root) - assert_instance_of(LibXML::XML::Document, @doc.root.doc) - assert_equal("\n\n", - @doc.to_s(:indent => false)) - end - - def test_doc_node_type - assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type) - end - - def test_doc_node_type_name - assert_equal('document_xml', LibXML::XML::Document.new.node_type_name) - end - - def test_xhtml - doc = LibXML::XML::Document.new - assert(!doc.xhtml?) - LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true) - assert(doc.xhtml?) - end - - def test_document_root - doc1 = LibXML::XML::Document.string("") - doc2 = LibXML::XML::Document.string("") - - error = assert_raises(LibXML::XML::Error) do - doc1.root = doc2.root - end - assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.", - error.to_s) - - doc2.root << doc2.import(doc1.root) - assert_equal('', doc1.root.to_s) - assert_equal('', doc2.root.to_s(:indent => false)) - - assert(!doc1.root.equal?(doc2.root)) - assert(doc1.root.doc != doc2.root.doc) - end - - def test_import_node - doc1 = LibXML::XML::Parser.string('').parse - doc2 = LibXML::XML::Parser.string('').parse - - node = doc1.root.child - - error = assert_raises(LibXML::XML::Error) do - doc2.root << node - end - - assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.", - error.to_s) - - doc2.root << doc2.import(node) - - assert_equal("", - doc2.root.to_s(:indent => false)) - end - - def test_nonet - xml_string = 'onetwo' - xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET) - file = File.join(File.dirname(__FILE__), 'model/atom.xml') - schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET) - end - - def test_io - File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io| - doc = LibXML::XML::Document.io(io) - assert_instance_of(LibXML::XML::Document, doc) - end - end - -end +# encoding: UTF-8 +require_relative './test_helper' + +class TestDocument < Minitest::Test + def setup + xp = LibXML::XML::Parser.string('onetwo') + assert_instance_of(LibXML::XML::Parser, xp) + @doc = xp.parse + assert_instance_of(LibXML::XML::Document, @doc) + end + + def teardown + @doc = nil + end + + def test_klass + assert_instance_of(LibXML::XML::Document, @doc) + end + + def test_context + context = @doc.context + assert_instance_of(LibXML::XML::XPath::Context, context) + end + + def test_find + set = @doc.find('/ruby_array/fixnum') + assert_instance_of(LibXML::XML::XPath::Object, set) + assert_raises(NoMethodError) { + set.xpath + } + end + + def test_compression + if LibXML::XML.enabled_zlib? + 0.upto(9) do |i| + assert_equal(i, @doc.compression = i) + assert_equal(i, @doc.compression) + end + + 9.downto(0) do |i| + assert_equal(i, @doc.compression = i) + assert_equal(i, @doc.compression) + end + + 10.upto(20) do |i| + # assert_equal(9, @doc.compression = i) + assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8 + assert_equal(9, @doc.compression) + end + + -1.downto(-10) do |i| + # assert_equal(0, @doc.compression = i) + assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP + assert_equal(0, @doc.compression) + end + end + end + + def test_version + assert_equal('1.0', @doc.version) + + doc = LibXML::XML::Document.new('6.9') + assert_equal('6.9', doc.version) + end + + def test_write_root + @doc.root = LibXML::XML::Node.new('rubynet') + assert_instance_of(LibXML::XML::Node, @doc.root) + assert_instance_of(LibXML::XML::Document, @doc.root.doc) + assert_equal("\n\n", + @doc.to_s(:indent => false)) + end + + def test_doc_node_type + assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type) + end + + def test_doc_node_type_name + assert_equal('document_xml', LibXML::XML::Document.new.node_type_name) + end + + def test_xhtml + doc = LibXML::XML::Document.new + assert(!doc.xhtml?) + LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true) + assert(doc.xhtml?) + end + + def test_document_root + doc1 = LibXML::XML::Document.string("") + doc2 = LibXML::XML::Document.string("") + + error = assert_raises(LibXML::XML::Error) do + doc1.root = doc2.root + end + assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.", + error.to_s) + + doc2.root << doc2.import(doc1.root) + assert_equal('', doc1.root.to_s) + assert_equal('', doc2.root.to_s(:indent => false)) + + assert(!doc1.root.equal?(doc2.root)) + assert(doc1.root.doc != doc2.root.doc) + end + + def test_import_node + doc1 = LibXML::XML::Parser.string('').parse + doc2 = LibXML::XML::Parser.string('').parse + + node = doc1.root.child + + error = assert_raises(LibXML::XML::Error) do + doc2.root << node + end + + assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.", + error.to_s) + + doc2.root << doc2.import(node) + + assert_equal("", + doc2.root.to_s(:indent => false)) + end + + def test_nonet + xml_string = 'onetwo' + xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET) + file = File.join(File.dirname(__FILE__), 'model/atom.xml') + schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET) + end + + def test_io + File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io| + doc = LibXML::XML::Document.io(io) + assert_instance_of(LibXML::XML::Document, doc) + end + end + +end diff --git a/test/test_document_write.rb b/test/test_document_write.rb index 26ba9daf..cca80189 100644 --- a/test/test_document_write.rb +++ b/test/test_document_write.rb @@ -1,143 +1,143 @@ -# encoding: UTF-8 - -require_relative './test_helper' -require 'tmpdir' - -class TestDocumentWrite < Minitest::Test - def setup - @file_name = "model/bands.utf-8.xml" - - file = File.join(File.dirname(__FILE__), @file_name) - @doc = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NOBLANKS) - end - - def teardown - @doc = nil - end - - # --- to_s tests --- - def test_to_s_default - # Default to_s has indentation - assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - @doc.to_s) - end - - def test_to_s_no_global_indentation - # No indentation due to global setting - LibXML::XML.indent_tree_output = false - value = @doc.to_s - - assert_equal(Encoding::UTF_8, value.encoding) - assert_equal("\n\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n", - value) - ensure - LibXML::XML.indent_tree_output = true - end - - def test_to_s_no_indentation - # No indentation due to local setting - value = @doc.to_s(:indent => false) - assert_equal(Encoding::UTF_8, value.encoding) - assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", - value) - end - - def test_to_s_encoding - # Test encodings - - # UTF8: - # ö - c3 b6 in hex, \303\266 in octal - # ü - c3 bc in hex, \303\274 in octal - value = @doc.to_s(:encoding => LibXML::XML::Encoding::UTF_8) - assert_equal(Encoding::UTF_8, value.encoding) - assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - value) - - # ISO_8859_1: - # ö - f6 in hex, \366 in octal - # ü - fc in hex, \374 in octal - value = @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1) - assert_equal(Encoding::ISO8859_1, value.encoding) - assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), - @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)) - - # Invalid encoding - error = assert_raises(ArgumentError) do - @doc.to_s(:encoding => -9999) - end - assert_equal('Unknown encoding value: -9999', error.to_s) - end - - # --- save tests ----- - def test_save_utf8 - temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml") - - bytes = @doc.save(temp_filename) - assert_equal(305, bytes) - - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) - assert_equal(Encoding::UTF_8, contents.encoding) - assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - contents) - ensure - File.delete(temp_filename) - end - - def test_save_utf8_no_indents - temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml") - - bytes = @doc.save(temp_filename, :indent => false) - assert_equal(298, bytes) - - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) - assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", - contents) - ensure - File.delete(temp_filename) - end - - def test_save_iso_8859_1 - temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml") - bytes = @doc.save(temp_filename, :encoding => LibXML::XML::Encoding::ISO_8859_1) - assert_equal(304, bytes) - - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) - assert_equal(Encoding::ISO8859_1, contents.encoding) - assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), - contents) - ensure - File.delete(temp_filename) - end - - def test_save_iso_8859_1_no_indent - temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml") - bytes = @doc.save(temp_filename, :indent => false, :encoding => LibXML::XML::Encoding::ISO_8859_1) - assert_equal(297, bytes) - - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) - assert_equal(Encoding::ISO8859_1, contents.encoding) - assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), - contents) - ensure - File.delete(temp_filename) - end - - def test_thread_set_root - # Previously a segmentation fault occurred when running libxml in - # background threads. - thread = Thread.new do - 100000.times do |i| - document = LibXML::XML::Document.new - node = LibXML::XML::Node.new('test') - document.root = node - end - end - thread.join - assert(true) - end - - # --- Debug --- - def test_debug - assert(@doc.debug) - end +# encoding: UTF-8 + +require_relative './test_helper' +require 'tmpdir' + +class TestDocumentWrite < Minitest::Test + def setup + @file_name = "model/bands.utf-8.xml" + + file = File.join(File.dirname(__FILE__), @file_name) + @doc = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NOBLANKS) + end + + def teardown + @doc = nil + end + + # --- to_s tests --- + def test_to_s_default + # Default to_s has indentation + assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", + @doc.to_s) + end + + def test_to_s_no_global_indentation + # No indentation due to global setting + LibXML::XML.indent_tree_output = false + value = @doc.to_s + + assert_equal(Encoding::UTF_8, value.encoding) + assert_equal("\n\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n", + value) + ensure + LibXML::XML.indent_tree_output = true + end + + def test_to_s_no_indentation + # No indentation due to local setting + value = @doc.to_s(:indent => false) + assert_equal(Encoding::UTF_8, value.encoding) + assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", + value) + end + + def test_to_s_encoding + # Test encodings + + # UTF8: + # ö - c3 b6 in hex, \303\266 in octal + # ü - c3 bc in hex, \303\274 in octal + value = @doc.to_s(:encoding => LibXML::XML::Encoding::UTF_8) + assert_equal(Encoding::UTF_8, value.encoding) + assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", + value) + + # ISO_8859_1: + # ö - f6 in hex, \366 in octal + # ü - fc in hex, \374 in octal + value = @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1) + assert_equal(Encoding::ISO8859_1, value.encoding) + assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), + @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)) + + # Invalid encoding + error = assert_raises(ArgumentError) do + @doc.to_s(:encoding => -9999) + end + assert_equal('Unknown encoding value: -9999', error.to_s) + end + + # --- save tests ----- + def test_save_utf8 + temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml") + + bytes = @doc.save(temp_filename) + assert_equal(305, bytes) + + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) + assert_equal(Encoding::UTF_8, contents.encoding) + assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", + contents) + ensure + File.delete(temp_filename) + end + + def test_save_utf8_no_indents + temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml") + + bytes = @doc.save(temp_filename, :indent => false) + assert_equal(298, bytes) + + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) + assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", + contents) + ensure + File.delete(temp_filename) + end + + def test_save_iso_8859_1 + temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml") + bytes = @doc.save(temp_filename, :encoding => LibXML::XML::Encoding::ISO_8859_1) + assert_equal(304, bytes) + + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) + assert_equal(Encoding::ISO8859_1, contents.encoding) + assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), + contents) + ensure + File.delete(temp_filename) + end + + def test_save_iso_8859_1_no_indent + temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml") + bytes = @doc.save(temp_filename, :indent => false, :encoding => LibXML::XML::Encoding::ISO_8859_1) + assert_equal(297, bytes) + + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) + assert_equal(Encoding::ISO8859_1, contents.encoding) + assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), + contents) + ensure + File.delete(temp_filename) + end + + def test_thread_set_root + # Previously a segmentation fault occurred when running libxml in + # background threads. + thread = Thread.new do + 100000.times do |i| + document = LibXML::XML::Document.new + node = LibXML::XML::Node.new('test') + document.root = node + end + end + thread.join + assert(true) + end + + # --- Debug --- + def test_debug + assert(@doc.debug) + end end \ No newline at end of file diff --git a/test/test_dtd.rb b/test/test_dtd.rb index d5ef0b63..56c93787 100644 --- a/test/test_dtd.rb +++ b/test/test_dtd.rb @@ -1,126 +1,126 @@ -# encoding: UTF-8 - -require_relative './test_helper' - - -class TestDtd < Minitest::Test - def setup - xp = LibXML::XML::Parser.string(<<-EOS) - - Colorado - Lots of nice mountains - - EOS - @doc = xp.parse - end - - def teardown - @doc = nil - end - - def dtd - LibXML::XML::Dtd.new(<<-EOS) - - - - - EOS - end - - def test_internal_subset - xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true) - assert xhtml_dtd.name.nil? - assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id - - xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true) - assert_equal "xhtml1", xhtml_dtd.name - assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id - end - - def test_external_subset - xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil) - assert xhtml_dtd.name.nil? - assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id - - xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1") - assert_equal "xhtml1", xhtml_dtd.name - assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri - assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id - end - - def test_valid - assert(@doc.validate(dtd)) - end - - def test_node_type - assert_equal(LibXML::XML::Node::DTD_NODE, dtd.node_type) - end - - def test_invalid - new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation') - @doc.root << new_node - - error = assert_raises(LibXML::XML::Error) do - @doc.validate(dtd) - end - - # Check the error worked - refute_nil(error) - assert_kind_of(LibXML::XML::Error, error) - assert_equal("Error: No declaration for element invalid.", error.message) - assert_equal(LibXML::XML::Error::VALID, error.domain) - assert_equal(LibXML::XML::Error::DTD_UNKNOWN_ELEM, error.code) - assert_equal(LibXML::XML::Error::ERROR, error.level) - assert_nil(error.file) - assert_nil(error.line) - assert_equal('invalid', error.str1) - # Different answers across operating systems - # assert_nil(error.str2) - assert_nil(error.str3) - assert_equal(0, error.int1) - assert_equal(0, error.int2) - refute_nil(error.node) - assert_equal('invalid', error.node.name) - end - - def test_external_dtd - xml = <<-EOS - - - T1 - - EOS - - errors = Array.new - LibXML::XML::Error.set_handler do |error| - errors << error - end - - LibXML::XML::Parser.string(xml).parse - assert_equal(0, errors.length) - - errors.clear - LibXML::XML::Parser.string(xml, options: LibXML::XML::Parser::Options::DTDLOAD).parse - assert_equal(1, errors.length) - assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.", - errors[0].to_s) - - errors = Array.new - LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse - assert_equal(1, errors.length) - assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.", - errors[0].to_s) - ensure - LibXML::XML::Error.reset_handler - end -end +# encoding: UTF-8 + +require_relative './test_helper' + + +class TestDtd < Minitest::Test + def setup + xp = LibXML::XML::Parser.string(<<-EOS) + + Colorado + Lots of nice mountains + + EOS + @doc = xp.parse + end + + def teardown + @doc = nil + end + + def dtd + LibXML::XML::Dtd.new(<<-EOS) + + + + + EOS + end + + def test_internal_subset + xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true) + assert xhtml_dtd.name.nil? + assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id + + xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true) + assert_equal "xhtml1", xhtml_dtd.name + assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id + end + + def test_external_subset + xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil) + assert xhtml_dtd.name.nil? + assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id + + xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1") + assert_equal "xhtml1", xhtml_dtd.name + assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri + assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id + end + + def test_valid + assert(@doc.validate(dtd)) + end + + def test_node_type + assert_equal(LibXML::XML::Node::DTD_NODE, dtd.node_type) + end + + def test_invalid + new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation') + @doc.root << new_node + + error = assert_raises(LibXML::XML::Error) do + @doc.validate(dtd) + end + + # Check the error worked + refute_nil(error) + assert_kind_of(LibXML::XML::Error, error) + assert_equal("Error: No declaration for element invalid.", error.message) + assert_equal(LibXML::XML::Error::VALID, error.domain) + assert_equal(LibXML::XML::Error::DTD_UNKNOWN_ELEM, error.code) + assert_equal(LibXML::XML::Error::ERROR, error.level) + assert_nil(error.file) + assert_nil(error.line) + assert_equal('invalid', error.str1) + # Different answers across operating systems + # assert_nil(error.str2) + assert_nil(error.str3) + assert_equal(0, error.int1) + assert_equal(0, error.int2) + refute_nil(error.node) + assert_equal('invalid', error.node.name) + end + + def test_external_dtd + xml = <<-EOS + + + T1 + + EOS + + errors = Array.new + LibXML::XML::Error.set_handler do |error| + errors << error + end + + LibXML::XML::Parser.string(xml).parse + assert_equal(0, errors.length) + + errors.clear + LibXML::XML::Parser.string(xml, options: LibXML::XML::Parser::Options::DTDLOAD).parse + assert_equal(1, errors.length) + assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.", + errors[0].to_s) + + errors = Array.new + LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse + assert_equal(1, errors.length) + assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.", + errors[0].to_s) + ensure + LibXML::XML::Error.reset_handler + end +end diff --git a/test/test_encoding.rb b/test/test_encoding.rb index af72ff5d..e274800c 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -1,126 +1,126 @@ -# encoding: UTF-8 - -require_relative './test_helper' - -# Code UTF8 Latin1 Hex -# m 109 109 6D -# ö 195 182 246 C3 B6 / F6 -# t 116 116 74 -# l 108 108 6C -# e 101 101 65 -# y 121 121 79 -# _ 95 95 5F -# c 99 99 63 -# r 114 114 72 -# ü 195 188 252 C3 BC / FC -# e 101 101 65 - -# See: -# http://en.wikipedia.org/wiki/ISO/IEC_8859-1 -# http://en.wikipedia.org/wiki/List_of_Unicode_characters - -class TestEncoding < Minitest::Test - def setup - @original_encoding = Encoding.default_internal - Encoding.default_internal = nil - end - - def teardown - Encoding.default_internal = @original_encoding - end - - def file_for_encoding(encoding) - file_name = "model/bands.#{encoding.name.downcase}.xml" - File.join(File.dirname(__FILE__), file_name) - end - - def load_encoding(encoding) - @encoding = encoding - file = file_for_encoding(encoding) - - @doc = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NOBLANKS) - end - - def test_encoding - doc = LibXML::XML::Document.new - assert_equal(LibXML::XML::Encoding::NONE, doc.encoding) - assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) - - file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml')) - doc = LibXML::XML::Document.file(file) - assert_equal(LibXML::XML::Encoding::UTF_8, doc.encoding) - assert_equal(Encoding::UTF_8, doc.rb_encoding) - - doc.encoding = LibXML::XML::Encoding::ISO_8859_1 - assert_equal(LibXML::XML::Encoding::ISO_8859_1, doc.encoding) - assert_equal(Encoding::ISO8859_1, doc.rb_encoding) - end - - def test_no_internal_encoding_iso_8859_1 - load_encoding(Encoding::ISO_8859_1) - node = @doc.root.children.first - - name = node.name - assert_equal(Encoding::UTF_8, name.encoding) - assert_equal("m\u00F6tley_cr\u00FCe", name) - assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101", - name.bytes.to_a.join(" ")) - assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.", - node.content) - - name = name.encode(Encoding::ISO_8859_1) - assert_equal(Encoding::ISO_8859_1, name.encoding) - assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name) - assert_equal("109 246 116 108 101 121 95 99 114 252 101", - name.bytes.to_a.join(" ")) - assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1), - node.content.encode(Encoding::ISO_8859_1)) - end - - def test_internal_encoding_iso_8859_1 - Encoding.default_internal = Encoding::ISO_8859_1 - load_encoding(Encoding::ISO_8859_1) - node = @doc.root.children.first - - name = node.name - assert_equal(Encoding::ISO_8859_1, name.encoding) - assert_equal("109 246 116 108 101 121 95 99 114 252 101", - name.bytes.to_a.join(" ")) - assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name) - assert_equal("109 246 116 108 101 121 95 99 114 252 101", - name.bytes.to_a.join(" ")) - assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1), - node.content.encode(Encoding::ISO_8859_1)) - end - - def test_no_internal_encoding_utf_8 - load_encoding(Encoding::UTF_8) - node = @doc.root.children.first - - name = node.name - assert_equal(@encoding, name.encoding) - assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101", - name.bytes.to_a.join(" ")) - - name = name.encode(Encoding::ISO_8859_1) - assert_equal(Encoding::ISO_8859_1, name.encoding) - assert_equal("109 246 116 108 101 121 95 99 114 252 101", - name.bytes.to_a.join(" ")) - end - - def test_internal_encoding_utf_8 - Encoding.default_internal = Encoding::ISO_8859_1 - load_encoding(Encoding::UTF_8) - node = @doc.root.children.first - - name = node.name - assert_equal(Encoding::ISO_8859_1, name.encoding) - assert_equal("109 246 116 108 101 121 95 99 114 252 101", - name.bytes.to_a.join(" ")) - end - - def test_encoding_conversions - assert_equal("UTF-8", LibXML::XML::Encoding.to_s(LibXML::XML::Encoding::UTF_8)) - assert_equal(LibXML::XML::Encoding::UTF_8, LibXML::XML::Encoding.from_s("UTF-8")) - end -end +# encoding: UTF-8 + +require_relative './test_helper' + +# Code UTF8 Latin1 Hex +# m 109 109 6D +# ö 195 182 246 C3 B6 / F6 +# t 116 116 74 +# l 108 108 6C +# e 101 101 65 +# y 121 121 79 +# _ 95 95 5F +# c 99 99 63 +# r 114 114 72 +# ü 195 188 252 C3 BC / FC +# e 101 101 65 + +# See: +# http://en.wikipedia.org/wiki/ISO/IEC_8859-1 +# http://en.wikipedia.org/wiki/List_of_Unicode_characters + +class TestEncoding < Minitest::Test + def setup + @original_encoding = Encoding.default_internal + Encoding.default_internal = nil + end + + def teardown + Encoding.default_internal = @original_encoding + end + + def file_for_encoding(encoding) + file_name = "model/bands.#{encoding.name.downcase}.xml" + File.join(File.dirname(__FILE__), file_name) + end + + def load_encoding(encoding) + @encoding = encoding + file = file_for_encoding(encoding) + + @doc = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NOBLANKS) + end + + def test_encoding + doc = LibXML::XML::Document.new + assert_equal(LibXML::XML::Encoding::NONE, doc.encoding) + assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) + + file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml')) + doc = LibXML::XML::Document.file(file) + assert_equal(LibXML::XML::Encoding::UTF_8, doc.encoding) + assert_equal(Encoding::UTF_8, doc.rb_encoding) + + doc.encoding = LibXML::XML::Encoding::ISO_8859_1 + assert_equal(LibXML::XML::Encoding::ISO_8859_1, doc.encoding) + assert_equal(Encoding::ISO8859_1, doc.rb_encoding) + end + + def test_no_internal_encoding_iso_8859_1 + load_encoding(Encoding::ISO_8859_1) + node = @doc.root.children.first + + name = node.name + assert_equal(Encoding::UTF_8, name.encoding) + assert_equal("m\u00F6tley_cr\u00FCe", name) + assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101", + name.bytes.to_a.join(" ")) + assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.", + node.content) + + name = name.encode(Encoding::ISO_8859_1) + assert_equal(Encoding::ISO_8859_1, name.encoding) + assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name) + assert_equal("109 246 116 108 101 121 95 99 114 252 101", + name.bytes.to_a.join(" ")) + assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1), + node.content.encode(Encoding::ISO_8859_1)) + end + + def test_internal_encoding_iso_8859_1 + Encoding.default_internal = Encoding::ISO_8859_1 + load_encoding(Encoding::ISO_8859_1) + node = @doc.root.children.first + + name = node.name + assert_equal(Encoding::ISO_8859_1, name.encoding) + assert_equal("109 246 116 108 101 121 95 99 114 252 101", + name.bytes.to_a.join(" ")) + assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name) + assert_equal("109 246 116 108 101 121 95 99 114 252 101", + name.bytes.to_a.join(" ")) + assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1), + node.content.encode(Encoding::ISO_8859_1)) + end + + def test_no_internal_encoding_utf_8 + load_encoding(Encoding::UTF_8) + node = @doc.root.children.first + + name = node.name + assert_equal(@encoding, name.encoding) + assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101", + name.bytes.to_a.join(" ")) + + name = name.encode(Encoding::ISO_8859_1) + assert_equal(Encoding::ISO_8859_1, name.encoding) + assert_equal("109 246 116 108 101 121 95 99 114 252 101", + name.bytes.to_a.join(" ")) + end + + def test_internal_encoding_utf_8 + Encoding.default_internal = Encoding::ISO_8859_1 + load_encoding(Encoding::UTF_8) + node = @doc.root.children.first + + name = node.name + assert_equal(Encoding::ISO_8859_1, name.encoding) + assert_equal("109 246 116 108 101 121 95 99 114 252 101", + name.bytes.to_a.join(" ")) + end + + def test_encoding_conversions + assert_equal("UTF-8", LibXML::XML::Encoding.to_s(LibXML::XML::Encoding::UTF_8)) + assert_equal(LibXML::XML::Encoding::UTF_8, LibXML::XML::Encoding.from_s("UTF-8")) + end +end diff --git a/test/test_error.rb b/test/test_error.rb index d65b2009..f9cae193 100644 --- a/test/test_error.rb +++ b/test/test_error.rb @@ -1,194 +1,194 @@ -# encoding: UTF-8 - -require_relative './test_helper' -require 'stringio' - -class TestError < Minitest::Test - def test_error_codes - assert_equal(4, LibXML::XML::Error::DTD) - assert_equal(4, LibXML::XML::Error.const_get('DTD')) - - assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY) - assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY')) - end - - def test_invalid_handler - assert_raises(RuntimeError) do - LibXML::XML::Error.set_handler - end - end - - def test_handler - exception = nil - LibXML::XML::Error.set_handler do |error| - exception = error - end - - # Raise the error - error = assert_raises(LibXML::XML::Error) do - LibXML::XML::Reader.string('').parse - end - ensure - Object.const_set(:STDERR, original_stderr) - end - assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string) - end - - def test_no_handler - LibXML::XML::Error.reset_handler - output = StringIO.new - original_stderr = Object::STDERR - - Object.const_set(:STDERR, output) - begin - assert_raises(LibXML::XML::Error) do - LibXML::XML::Parser.string('').parse - end - ensure - Object.const_set(:STDERR, original_stderr) - end - assert_equal('', output.string) - end - - def test_parse_error - exception = assert_raises(LibXML::XML::Error) do - LibXML::XML::Parser.string('').parse - end - - assert_instance_of(LibXML::XML::Error, exception) - assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message) - assert_equal(LibXML::XML::Error::PARSER, exception.domain) - assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, exception.code) - assert_equal(LibXML::XML::Error::FATAL, exception.level) - assert_nil(exception.file) - assert_equal(1, exception.line) - end - - def test_xpath_error - doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) - - exception = assert_raises(LibXML::XML::Error) do - doc.find('/foo[bar=test') - end - - assert_instance_of(LibXML::XML::Error, exception) - assert_equal("Error: Invalid predicate.", exception.message) - assert_equal(LibXML::XML::Error::XPATH, exception.domain) - assert_equal(LibXML::XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code) - assert_equal(LibXML::XML::Error::ERROR, exception.level) - assert_nil(exception.file) - assert_nil(nil) - end - - def test_double_parse - LibXML::XML::Error.set_handler {|msg| nil } - parser = LibXML::XML::Parser.string("something") - parser.parse - - error = assert_raises(LibXML::XML::Error) do - # Try parsing a second time - parser.parse - end - - assert_equal(" LibXML::XML::Error.", error.to_s) - end - - def test_double_parse_register_handler - LibXML::XML::Parser.register_error_handler(lambda {|msg| nil }) - parser = LibXML::XML::Parser.string("something") - parser.parse - - error = assert_raises(LibXML::XML::Error) do - # Try parsing a second time - parser.parse - end - - assert_equal(" LibXML::XML::Error.", error.to_s) - end - - def test_libxml_parser_empty_string - error = assert_raises(TypeError) do - LibXML::XML::Parser.string(nil) - end - assert_equal('wrong argument type nil (expected String)', error.to_s) - - error = assert_raises(ArgumentError) do - LibXML::XML::Parser.string("") - end - assert_equal('Must specify a string with one or more characters', error.to_s) - end - - def test_error_domain_to_s - exception = assert_raises(LibXML::XML::Error) do - LibXML::XML::Parser.string('').parse - end - - assert_equal(LibXML::XML::Error::PARSER, exception.domain) - assert_equal("PARSER", exception.domain_to_s) - end - - def test_error_code_to_s - exception = assert_raises(LibXML::XML::Error) do - LibXML::XML::Parser.string('').parse - end - assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code) - assert_equal("ENTITYREF_SEMICOL_MISSING", exception.code_to_s) - end -end +# encoding: UTF-8 + +require_relative './test_helper' +require 'stringio' + +class TestError < Minitest::Test + def test_error_codes + assert_equal(4, LibXML::XML::Error::DTD) + assert_equal(4, LibXML::XML::Error.const_get('DTD')) + + assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY) + assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY')) + end + + def test_invalid_handler + assert_raises(RuntimeError) do + LibXML::XML::Error.set_handler + end + end + + def test_handler + exception = nil + LibXML::XML::Error.set_handler do |error| + exception = error + end + + # Raise the error + error = assert_raises(LibXML::XML::Error) do + LibXML::XML::Reader.string('').parse + end + ensure + Object.const_set(:STDERR, original_stderr) + end + assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string) + end + + def test_no_handler + LibXML::XML::Error.reset_handler + output = StringIO.new + original_stderr = Object::STDERR + + Object.const_set(:STDERR, output) + begin + assert_raises(LibXML::XML::Error) do + LibXML::XML::Parser.string('').parse + end + ensure + Object.const_set(:STDERR, original_stderr) + end + assert_equal('', output.string) + end + + def test_parse_error + exception = assert_raises(LibXML::XML::Error) do + LibXML::XML::Parser.string('').parse + end + + assert_instance_of(LibXML::XML::Error, exception) + assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message) + assert_equal(LibXML::XML::Error::PARSER, exception.domain) + assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, exception.code) + assert_equal(LibXML::XML::Error::FATAL, exception.level) + assert_nil(exception.file) + assert_equal(1, exception.line) + end + + def test_xpath_error + doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) + + exception = assert_raises(LibXML::XML::Error) do + doc.find('/foo[bar=test') + end + + assert_instance_of(LibXML::XML::Error, exception) + assert_equal("Error: Invalid predicate.", exception.message) + assert_equal(LibXML::XML::Error::XPATH, exception.domain) + assert_equal(LibXML::XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code) + assert_equal(LibXML::XML::Error::ERROR, exception.level) + assert_nil(exception.file) + assert_nil(nil) + end + + def test_double_parse + LibXML::XML::Error.set_handler {|msg| nil } + parser = LibXML::XML::Parser.string("something") + parser.parse + + error = assert_raises(LibXML::XML::Error) do + # Try parsing a second time + parser.parse + end + + assert_equal(" LibXML::XML::Error.", error.to_s) + end + + def test_double_parse_register_handler + LibXML::XML::Parser.register_error_handler(lambda {|msg| nil }) + parser = LibXML::XML::Parser.string("something") + parser.parse + + error = assert_raises(LibXML::XML::Error) do + # Try parsing a second time + parser.parse + end + + assert_equal(" LibXML::XML::Error.", error.to_s) + end + + def test_libxml_parser_empty_string + error = assert_raises(TypeError) do + LibXML::XML::Parser.string(nil) + end + assert_equal('wrong argument type nil (expected String)', error.to_s) + + error = assert_raises(ArgumentError) do + LibXML::XML::Parser.string("") + end + assert_equal('Must specify a string with one or more characters', error.to_s) + end + + def test_error_domain_to_s + exception = assert_raises(LibXML::XML::Error) do + LibXML::XML::Parser.string('').parse + end + + assert_equal(LibXML::XML::Error::PARSER, exception.domain) + assert_equal("PARSER", exception.domain_to_s) + end + + def test_error_code_to_s + exception = assert_raises(LibXML::XML::Error) do + LibXML::XML::Parser.string('').parse + end + assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code) + assert_equal("ENTITYREF_SEMICOL_MISSING", exception.code_to_s) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 2f00414a..001c4bea 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,20 +1,20 @@ -# encoding: UTF-8 - -# To make testing/debugging easier, test within this source tree versus an installed gem -require 'bundler/setup' - -# Add ext directory to load path to make it easier to test locally built extensions -ext_path = File.expand_path(File.join(__dir__, '..', 'ext', 'libxml')) -$LOAD_PATH.unshift(File.expand_path(ext_path)) - -# Now load code -require 'libxml-ruby' - -def windows? - !(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/).nil? -end - -STDOUT.write "\nlibxml2: #{LibXML::XML::LIBXML_VERSION}\n#{RUBY_DESCRIPTION}\n\n" - -require 'minitest/autorun' - +# encoding: UTF-8 + +# To make testing/debugging easier, test within this source tree versus an installed gem +require 'bundler/setup' + +# Add ext directory to load path to make it easier to test locally built extensions +ext_path = File.expand_path(File.join(__dir__, '..', 'ext', 'libxml')) +$LOAD_PATH.unshift(File.expand_path(ext_path)) + +# Now load code +require 'libxml-ruby' + +def windows? + !(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/).nil? +end + +STDOUT.write "\nlibxml2: #{LibXML::XML::LIBXML_VERSION}\n#{RUBY_DESCRIPTION}\n\n" + +require 'minitest/autorun' + diff --git a/test/test_namespace.rb b/test/test_namespace.rb index 6d74b8b2..608fa1bd 100644 --- a/test/test_namespace.rb +++ b/test/test_namespace.rb @@ -1,58 +1,58 @@ -# encoding: UTF-8 - -require_relative './test_helper' - - -class TestNS < Minitest::Test - def setup - file = File.join(File.dirname(__FILE__), 'model/soap.xml') - @doc = LibXML::XML::Document.file(file) - end - - def teardown - @doc = nil - end - - def test_create_ns - node = LibXML::XML::Node.new('foo') - ns = LibXML::XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com') - assert_equal(ns.prefix, 'my_namepace') - assert_equal(ns.href, 'http://www.mynamespace.com') - end - - def test_create_default_ns - node = LibXML::XML::Node.new('foo') - ns = LibXML::XML::Namespace.new(node, nil, 'http://www.mynamespace.com') - assert_nil(ns.prefix) - assert_equal(ns.href, 'http://www.mynamespace.com') - end - - def test_create_unbound_ns - error = assert_raises(TypeError) do - LibXML::XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com') - end - assert_equal('wrong argument type nil (expected Data)', error.to_s) - end - - def test_duplicate_ns - node = LibXML::XML::Node.new('foo') - LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') - LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') - end - - def test_eql - node = LibXML::XML::Node.new('Envelope') - - assert(node.namespaces.namespace.eql?(node.namespaces.namespace)) - end - - def test_equal - node1 = LibXML::XML::Node.new('Envelope') - ns1 = LibXML::XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') - - node2 = LibXML::XML::Node.new('Envelope') - ns2 = LibXML::XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') - - assert(ns1 == ns2) - end -end +# encoding: UTF-8 + +require_relative './test_helper' + + +class TestNS < Minitest::Test + def setup + file = File.join(File.dirname(__FILE__), 'model/soap.xml') + @doc = LibXML::XML::Document.file(file) + end + + def teardown + @doc = nil + end + + def test_create_ns + node = LibXML::XML::Node.new('foo') + ns = LibXML::XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com') + assert_equal(ns.prefix, 'my_namepace') + assert_equal(ns.href, 'http://www.mynamespace.com') + end + + def test_create_default_ns + node = LibXML::XML::Node.new('foo') + ns = LibXML::XML::Namespace.new(node, nil, 'http://www.mynamespace.com') + assert_nil(ns.prefix) + assert_equal(ns.href, 'http://www.mynamespace.com') + end + + def test_create_unbound_ns + error = assert_raises(TypeError) do + LibXML::XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com') + end + assert_equal('wrong argument type nil (expected Data)', error.to_s) + end + + def test_duplicate_ns + node = LibXML::XML::Node.new('foo') + LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') + LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') + end + + def test_eql + node = LibXML::XML::Node.new('Envelope') + + assert(node.namespaces.namespace.eql?(node.namespaces.namespace)) + end + + def test_equal + node1 = LibXML::XML::Node.new('Envelope') + ns1 = LibXML::XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + + node2 = LibXML::XML::Node.new('Envelope') + ns2 = LibXML::XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + + assert(ns1 == ns2) + end +end diff --git a/test/test_node.rb b/test/test_node.rb index c0063290..06e82e84 100644 --- a/test/test_node.rb +++ b/test/test_node.rb @@ -1,235 +1,235 @@ -# encoding: UTF-8 - -require_relative './test_helper' - -class TestNode < Minitest::Test - def setup - @file_name = "model/bands.utf-8.xml" - - # Strip spaces to make testing easier - file = File.join(File.dirname(__FILE__), @file_name) - @doc = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NOBLANKS) - end - - def teardown - @doc = nil - end - - def nodes - # Find all nodes with a country attributes - @doc.find('*[@country]') - end - - def test_doc_class - assert_instance_of(LibXML::XML::Document, @doc) - end - - def test_doc_node_type - assert_equal LibXML::XML::Node::DOCUMENT_NODE, @doc.node_type - end - - def test_root_class - assert_instance_of(LibXML::XML::Node, @doc.root) - end - - def test_root_node_type - assert_equal LibXML::XML::Node::ELEMENT_NODE, @doc.root.node_type - end - - def test_node_class - for n in nodes - assert_instance_of(LibXML::XML::Node, n) - end - end - - def test_context - node = @doc.root - context = node.context - assert_instance_of(LibXML::XML::XPath::Context, context) - end - - def test_find - assert_instance_of(LibXML::XML::XPath::Object, self.nodes) - end - - def test_node_child_get - assert_instance_of(TrueClass, @doc.root.child?) - assert_instance_of(LibXML::XML::Node, @doc.root.child) - - assert_equal(Encoding::UTF_8, @doc.root.child.name.encoding) - assert_equal("m\u00F6tley_cr\u00FCe", @doc.root.child.name) - end - - def test_node_doc - for n in nodes - assert_instance_of(LibXML::XML::Document, n.doc) if n.document? - end - end - - def test_name - node = @doc.root.children.last - assert_equal("iron_maiden", node.name) - end - - def test_node_find - nodes = @doc.root.find('./fixnum') - for node in nodes - assert_instance_of(LibXML::XML::Node, node) - end - end - - def test_equality - node_a = @doc.find_first('*[@country]') - node_b = @doc.root.child - - # On the ruby side these are different objects - refute(node_a.equal?(node_b)) - - # But they are the same underlying libxml node so specify they are equal - assert(node_a == node_b) - assert(node_a.eql?(node_b)) - - file = File.join(File.dirname(__FILE__), @file_name) - doc2 = LibXML::XML::Document.file(file) - - node_a2 = doc2.find_first('*[@country]') - - refute(node_a == node_a2) - refute(node_a.eql?(node_a2)) - assert_equal(node_a.to_s, node_a2.to_s) - refute(node_a.equal?(node_a2)) - end - - def test_equality_2 - parent = LibXML::XML::Node.new('parent') - child = LibXML::XML::Node.new('child') - parent << child - - node_a = child.parent - node_b = child.parent - # In this case the nodes are equal - the parent being the root - assert(node_a.equal?(node_b)) - assert(node_a == node_b) - assert(node_a.eql?(node_b)) - end - - def test_equality_nil - node = @doc.root - assert(node != nil) - end - - def test_equality_wrong_type - node = @doc.root - - assert_raises(TypeError) do - assert(node != 'abc') - end - end - - def test_content - node = @doc.root.last - assert_equal("Iron Maiden is a British heavy metal band formed in 1975.", - node.content) - end - - def test_base - doc = LibXML::XML::Parser.string('').parse - assert_nil(doc.root.base_uri) - end - - # We use the same facility that libXSLT does here to disable output escaping. - # This lets you specify that the node's content should be rendered unaltered - # whenever it is being output. This is useful for things like