libxml-ruby 4.1.2 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{HISTORY → CHANGELOG.md} +875 -887
- data/LICENSE +20 -20
- data/README.md +67 -0
- data/Rakefile +77 -98
- data/ext/libxml/extconf.rb +39 -20
- data/ext/libxml/libxml.c +67 -79
- data/ext/libxml/ruby_libxml.h +43 -44
- data/ext/libxml/ruby_xml.c +556 -899
- data/ext/libxml/ruby_xml.h +9 -10
- data/ext/libxml/ruby_xml_attr.c +338 -333
- data/ext/libxml/ruby_xml_attr.h +13 -12
- data/ext/libxml/ruby_xml_attr_decl.c +19 -12
- data/ext/libxml/ruby_xml_attr_decl.h +11 -11
- data/ext/libxml/ruby_xml_attributes.c +18 -9
- data/ext/libxml/ruby_xml_attributes.h +17 -15
- data/ext/libxml/ruby_xml_document.c +1142 -1129
- data/ext/libxml/ruby_xml_document.h +12 -11
- data/ext/libxml/ruby_xml_dtd.c +287 -248
- data/ext/libxml/ruby_xml_dtd.h +10 -9
- data/ext/libxml/ruby_xml_encoding.c +250 -250
- data/ext/libxml/ruby_xml_encoding.h +20 -18
- data/ext/libxml/ruby_xml_error.c +1003 -996
- data/ext/libxml/ruby_xml_error.h +14 -14
- data/ext/libxml/ruby_xml_html_parser.c +91 -91
- data/ext/libxml/ruby_xml_html_parser.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_context.c +364 -337
- data/ext/libxml/ruby_xml_html_parser_context.h +11 -10
- data/ext/libxml/ruby_xml_html_parser_options.c +48 -48
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_input_cbg.c +216 -188
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_io.c +49 -47
- data/ext/libxml/ruby_xml_io.h +10 -10
- data/ext/libxml/ruby_xml_namespace.c +159 -154
- data/ext/libxml/ruby_xml_namespace.h +11 -10
- data/ext/libxml/ruby_xml_namespaces.c +313 -293
- data/ext/libxml/ruby_xml_namespaces.h +9 -9
- data/ext/libxml/ruby_xml_node.c +1433 -1398
- data/ext/libxml/ruby_xml_node.h +15 -13
- data/ext/libxml/ruby_xml_parser.c +91 -91
- data/ext/libxml/ruby_xml_parser.h +10 -10
- data/ext/libxml/ruby_xml_parser_context.c +1016 -1001
- data/ext/libxml/ruby_xml_parser_context.h +11 -10
- data/ext/libxml/ruby_xml_parser_options.c +74 -66
- data/ext/libxml/ruby_xml_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_reader.c +40 -31
- data/ext/libxml/ruby_xml_reader.h +14 -14
- data/ext/libxml/ruby_xml_registry.c +31 -0
- data/ext/libxml/ruby_xml_registry.h +22 -0
- data/ext/libxml/ruby_xml_relaxng.c +21 -5
- data/ext/libxml/ruby_xml_relaxng.h +9 -8
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
- data/ext/libxml/ruby_xml_sax_parser.c +108 -116
- data/ext/libxml/ruby_xml_sax_parser.h +10 -10
- data/ext/libxml/ruby_xml_schema.c +22 -15
- data/ext/libxml/ruby_xml_schema.h +26 -25
- data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
- data/ext/libxml/ruby_xml_schema_attribute.h +37 -37
- data/ext/libxml/ruby_xml_schema_element.c +8 -8
- data/ext/libxml/ruby_xml_schema_element.h +11 -11
- data/ext/libxml/ruby_xml_schema_facet.c +50 -50
- data/ext/libxml/ruby_xml_schema_facet.h +9 -9
- data/ext/libxml/ruby_xml_schema_type.c +12 -19
- data/ext/libxml/ruby_xml_schema_type.h +9 -9
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/ext/libxml/ruby_xml_writer.c +183 -185
- data/ext/libxml/ruby_xml_writer.h +6 -6
- data/ext/libxml/ruby_xml_xinclude.c +20 -20
- data/ext/libxml/ruby_xml_xinclude.h +11 -11
- data/ext/libxml/ruby_xml_xpath.c +195 -195
- data/ext/libxml/ruby_xml_xpath.h +15 -15
- data/ext/libxml/ruby_xml_xpath_context.c +408 -362
- data/ext/libxml/ruby_xml_xpath_context.h +9 -9
- data/ext/libxml/ruby_xml_xpath_expression.c +12 -6
- data/ext/libxml/ruby_xml_xpath_expression.h +11 -10
- data/ext/libxml/ruby_xml_xpath_object.c +69 -54
- data/ext/libxml/ruby_xml_xpath_object.h +19 -17
- data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
- data/lib/libxml/attr.rb +122 -122
- data/lib/libxml/attr_decl.rb +80 -80
- data/lib/libxml/attributes.rb +13 -13
- data/lib/libxml/document.rb +165 -194
- data/lib/libxml/error.rb +122 -95
- data/lib/libxml/html_parser.rb +80 -96
- data/lib/libxml/namespace.rb +61 -61
- data/lib/libxml/namespaces.rb +37 -37
- data/lib/libxml/node.rb +321 -323
- data/lib/libxml/parser.rb +94 -100
- data/lib/libxml/sax_callbacks.rb +179 -179
- data/lib/libxml/sax_parser.rb +40 -40
- data/lib/libxml/schema/attribute.rb +27 -19
- data/lib/libxml/schema/element.rb +20 -0
- data/lib/libxml/schema/type.rb +44 -21
- data/lib/libxml/schema.rb +47 -47
- data/lib/libxml/tree.rb +28 -28
- data/lib/libxml-ruby.rb +30 -30
- data/libxml-ruby.gemspec +46 -48
- data/test/c14n/result/1-1-without-comments/example-1 +3 -3
- data/test/c14n/result/1-1-without-comments/example-2 +10 -10
- data/test/c14n/result/1-1-without-comments/example-3 +13 -13
- data/test/c14n/result/1-1-without-comments/example-4 +8 -8
- data/test/c14n/result/1-1-without-comments/example-5 +2 -2
- data/test/c14n/result/with-comments/example-1 +5 -5
- data/test/c14n/result/with-comments/example-2 +10 -10
- data/test/c14n/result/with-comments/example-3 +13 -13
- data/test/c14n/result/with-comments/example-4 +8 -8
- data/test/c14n/result/with-comments/example-5 +3 -3
- data/test/c14n/result/without-comments/example-1 +3 -3
- data/test/c14n/result/without-comments/example-2 +10 -10
- data/test/c14n/result/without-comments/example-3 +13 -13
- data/test/c14n/result/without-comments/example-4 +8 -8
- data/test/c14n/result/without-comments/example-5 +2 -2
- data/test/test_attr.rb +179 -180
- data/test/test_attr_decl.rb +131 -131
- data/test/test_attributes.rb +135 -135
- data/test/test_canonicalize.rb +122 -120
- data/test/test_document.rb +138 -132
- data/test/test_document_write.rb +142 -145
- data/test/test_dtd.rb +134 -129
- data/test/test_encoding.rb +126 -129
- data/test/test_encoding_sax.rb +114 -114
- data/test/test_error.rb +197 -194
- data/test/test_helper.rb +21 -13
- data/test/test_html_parser.rb +166 -162
- data/test/test_html_parser_context.rb +22 -22
- data/test/test_input_callbacks.rb +36 -0
- data/test/test_namespace.rb +58 -60
- data/test/test_namespaces.rb +200 -200
- data/test/test_node.rb +251 -237
- data/test/test_node_cdata.rb +50 -50
- data/test/test_node_comment.rb +32 -32
- data/test/test_node_copy.rb +40 -40
- data/test/test_node_edit.rb +176 -158
- data/test/test_node_pi.rb +37 -37
- data/test/test_node_text.rb +69 -69
- data/test/test_node_write.rb +93 -96
- data/test/test_node_xlink.rb +28 -28
- data/test/test_parser.rb +297 -324
- data/test/test_parser_context.rb +198 -198
- data/test/test_properties.rb +38 -38
- data/test/test_reader.rb +413 -364
- data/test/test_relaxng.rb +59 -53
- data/test/test_sax_parser.rb +345 -326
- data/test/test_schema.rb +28 -0
- data/test/test_traversal.rb +152 -152
- data/test/test_writer.rb +469 -468
- data/test/test_xinclude.rb +20 -20
- data/test/test_xml.rb +164 -267
- data/test/test_xpath.rb +244 -244
- data/test/test_xpath_context.rb +87 -87
- data/test/test_xpath_expression.rb +37 -37
- metadata +49 -31
- data/README.rdoc +0 -217
- data/ext/libxml/extconf.h +0 -3
- data/ext/libxml/ruby_xml_cbg.c +0 -85
- data/lib/libxml/hpricot.rb +0 -78
- data/lib/libxml.rb +0 -5
- data/lib/xml/libxml.rb +0 -10
- data/lib/xml.rb +0 -14
- data/script/benchmark/depixelate +0 -634
- data/script/benchmark/hamlet.xml +0 -9055
- data/script/benchmark/parsecount +0 -170
- data/script/benchmark/sock_entries.xml +0 -507
- data/script/benchmark/throughput +0 -41
- data/script/test +0 -6
- data/test/test_deprecated_require.rb +0 -12
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
-
|
|
3
|
-
#ifndef __RXML_PARSER_CONTEXT__
|
|
4
|
-
#define __RXML_PARSER_CONTEXT__
|
|
5
|
-
|
|
6
|
-
extern VALUE cXMLParserContext;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
+
|
|
3
|
+
#ifndef __RXML_PARSER_CONTEXT__
|
|
4
|
+
#define __RXML_PARSER_CONTEXT__
|
|
5
|
+
|
|
6
|
+
extern VALUE cXMLParserContext;
|
|
7
|
+
extern const rb_data_type_t rxml_parser_context_type;
|
|
8
|
+
|
|
9
|
+
void rxml_init_parser_context(void);
|
|
10
|
+
|
|
11
|
+
#endif
|
|
@@ -1,66 +1,74 @@
|
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
-
|
|
3
|
-
#include <stdarg.h>
|
|
4
|
-
#include "ruby_libxml.h"
|
|
5
|
-
|
|
6
|
-
/* Document-class: LibXML::XML::Parser::Options
|
|
7
|
-
*
|
|
8
|
-
* Options that control the operation of the HTMLParser. The easiest
|
|
9
|
-
* way to set a parser's options is to use the methods
|
|
10
|
-
* XML::Parser.file, XML::Parser.io or XML::Parser.string.
|
|
11
|
-
* For additional control, see XML::Parser::Context#options=.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
VALUE mXMLParserOptions;
|
|
15
|
-
|
|
16
|
-
void rxml_init_parser_options(void)
|
|
17
|
-
{
|
|
18
|
-
mXMLParserOptions = rb_define_module_under(cXMLParser, "Options");
|
|
19
|
-
|
|
20
|
-
/* recover on errors */
|
|
21
|
-
rb_define_const(mXMLParserOptions, "RECOVER", INT2NUM(XML_PARSE_RECOVER));
|
|
22
|
-
/* substitute entities */
|
|
23
|
-
rb_define_const(mXMLParserOptions, "NOENT", INT2NUM(XML_PARSE_NOENT));
|
|
24
|
-
/* load the external subset */
|
|
25
|
-
rb_define_const(mXMLParserOptions, "DTDLOAD", INT2NUM(XML_PARSE_DTDLOAD));
|
|
26
|
-
/* default DTD attributes */
|
|
27
|
-
rb_define_const(mXMLParserOptions, "DTDATTR", INT2NUM(XML_PARSE_DTDATTR));
|
|
28
|
-
/* validate with the DTD */
|
|
29
|
-
rb_define_const(mXMLParserOptions, "DTDVALID", INT2NUM(XML_PARSE_DTDVALID));
|
|
30
|
-
/* suppress error reports */
|
|
31
|
-
rb_define_const(mXMLParserOptions, "NOERROR", INT2NUM(XML_PARSE_NOERROR));
|
|
32
|
-
/* suppress warning reports */
|
|
33
|
-
rb_define_const(mXMLParserOptions, "NOWARNING", INT2NUM(XML_PARSE_NOWARNING));
|
|
34
|
-
/* pedantic error reporting */
|
|
35
|
-
rb_define_const(mXMLParserOptions, "PEDANTIC", INT2NUM(XML_PARSE_PEDANTIC));
|
|
36
|
-
/* remove blank nodes */
|
|
37
|
-
rb_define_const(mXMLParserOptions, "NOBLANKS", INT2NUM(XML_PARSE_NOBLANKS));
|
|
38
|
-
/* use the SAX1 interface internally */
|
|
39
|
-
rb_define_const(mXMLParserOptions, "SAX1", INT2NUM(XML_PARSE_SAX1));
|
|
40
|
-
/* Implement XInclude substitition */
|
|
41
|
-
rb_define_const(mXMLParserOptions, "XINCLUDE", INT2NUM(XML_PARSE_XINCLUDE));
|
|
42
|
-
/* Forbid network access */
|
|
43
|
-
rb_define_const(mXMLParserOptions, "NONET", INT2NUM(XML_PARSE_NONET));
|
|
44
|
-
/* Do not reuse the context dictionnary */
|
|
45
|
-
rb_define_const(mXMLParserOptions, "NODICT", INT2NUM(XML_PARSE_NODICT));
|
|
46
|
-
/* remove redundant namespaces declarations */
|
|
47
|
-
rb_define_const(mXMLParserOptions, "NSCLEAN", INT2NUM(XML_PARSE_NSCLEAN));
|
|
48
|
-
/* merge CDATA as text nodes */
|
|
49
|
-
rb_define_const(mXMLParserOptions, "NOCDATA", INT2NUM(XML_PARSE_NOCDATA));
|
|
50
|
-
#if LIBXML_VERSION >= 20621
|
|
51
|
-
/* do not generate XINCLUDE START/END nodes */
|
|
52
|
-
rb_define_const(mXMLParserOptions, "NOXINCNODE", INT2NUM(XML_PARSE_NOXINCNODE));
|
|
53
|
-
#endif
|
|
54
|
-
#if LIBXML_VERSION >= 20700
|
|
55
|
-
/* compact small text nodes */
|
|
56
|
-
rb_define_const(mXMLParserOptions, "COMPACT", INT2NUM(XML_PARSE_COMPACT));
|
|
57
|
-
/* parse using XML-1.0 before update 5 */
|
|
58
|
-
rb_define_const(mXMLParserOptions, "
|
|
59
|
-
/* do not fixup XINCLUDE xml:base uris */
|
|
60
|
-
rb_define_const(mXMLParserOptions, "NOBASEFIX", INT2NUM(XML_PARSE_NOBASEFIX));
|
|
61
|
-
#endif
|
|
62
|
-
#if LIBXML_VERSION >= 20703
|
|
63
|
-
/* relax any hardcoded limit from the parser */
|
|
64
|
-
rb_define_const(mXMLParserOptions, "HUGE", INT2NUM(XML_PARSE_HUGE));
|
|
65
|
-
#endif
|
|
66
|
-
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
+
|
|
3
|
+
#include <stdarg.h>
|
|
4
|
+
#include "ruby_libxml.h"
|
|
5
|
+
|
|
6
|
+
/* Document-class: LibXML::XML::Parser::Options
|
|
7
|
+
*
|
|
8
|
+
* Options that control the operation of the HTMLParser. The easiest
|
|
9
|
+
* way to set a parser's options is to use the methods
|
|
10
|
+
* XML::Parser.file, XML::Parser.io or XML::Parser.string.
|
|
11
|
+
* For additional control, see XML::Parser::Context#options=.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
VALUE mXMLParserOptions;
|
|
15
|
+
|
|
16
|
+
void rxml_init_parser_options(void)
|
|
17
|
+
{
|
|
18
|
+
mXMLParserOptions = rb_define_module_under(cXMLParser, "Options");
|
|
19
|
+
|
|
20
|
+
/* recover on errors */
|
|
21
|
+
rb_define_const(mXMLParserOptions, "RECOVER", INT2NUM(XML_PARSE_RECOVER));
|
|
22
|
+
/* substitute entities */
|
|
23
|
+
rb_define_const(mXMLParserOptions, "NOENT", INT2NUM(XML_PARSE_NOENT));
|
|
24
|
+
/* load the external subset */
|
|
25
|
+
rb_define_const(mXMLParserOptions, "DTDLOAD", INT2NUM(XML_PARSE_DTDLOAD));
|
|
26
|
+
/* default DTD attributes */
|
|
27
|
+
rb_define_const(mXMLParserOptions, "DTDATTR", INT2NUM(XML_PARSE_DTDATTR));
|
|
28
|
+
/* validate with the DTD */
|
|
29
|
+
rb_define_const(mXMLParserOptions, "DTDVALID", INT2NUM(XML_PARSE_DTDVALID));
|
|
30
|
+
/* suppress error reports */
|
|
31
|
+
rb_define_const(mXMLParserOptions, "NOERROR", INT2NUM(XML_PARSE_NOERROR));
|
|
32
|
+
/* suppress warning reports */
|
|
33
|
+
rb_define_const(mXMLParserOptions, "NOWARNING", INT2NUM(XML_PARSE_NOWARNING));
|
|
34
|
+
/* pedantic error reporting */
|
|
35
|
+
rb_define_const(mXMLParserOptions, "PEDANTIC", INT2NUM(XML_PARSE_PEDANTIC));
|
|
36
|
+
/* remove blank nodes */
|
|
37
|
+
rb_define_const(mXMLParserOptions, "NOBLANKS", INT2NUM(XML_PARSE_NOBLANKS));
|
|
38
|
+
/* use the SAX1 interface internally */
|
|
39
|
+
rb_define_const(mXMLParserOptions, "SAX1", INT2NUM(XML_PARSE_SAX1));
|
|
40
|
+
/* Implement XInclude substitition */
|
|
41
|
+
rb_define_const(mXMLParserOptions, "XINCLUDE", INT2NUM(XML_PARSE_XINCLUDE));
|
|
42
|
+
/* Forbid network access */
|
|
43
|
+
rb_define_const(mXMLParserOptions, "NONET", INT2NUM(XML_PARSE_NONET));
|
|
44
|
+
/* Do not reuse the context dictionnary */
|
|
45
|
+
rb_define_const(mXMLParserOptions, "NODICT", INT2NUM(XML_PARSE_NODICT));
|
|
46
|
+
/* remove redundant namespaces declarations */
|
|
47
|
+
rb_define_const(mXMLParserOptions, "NSCLEAN", INT2NUM(XML_PARSE_NSCLEAN));
|
|
48
|
+
/* merge CDATA as text nodes */
|
|
49
|
+
rb_define_const(mXMLParserOptions, "NOCDATA", INT2NUM(XML_PARSE_NOCDATA));
|
|
50
|
+
#if LIBXML_VERSION >= 20621
|
|
51
|
+
/* do not generate XINCLUDE START/END nodes */
|
|
52
|
+
rb_define_const(mXMLParserOptions, "NOXINCNODE", INT2NUM(XML_PARSE_NOXINCNODE));
|
|
53
|
+
#endif
|
|
54
|
+
#if LIBXML_VERSION >= 20700
|
|
55
|
+
/* compact small text nodes */
|
|
56
|
+
rb_define_const(mXMLParserOptions, "COMPACT", INT2NUM(XML_PARSE_COMPACT));
|
|
57
|
+
/* parse using XML-1.0 before update 5 */
|
|
58
|
+
rb_define_const(mXMLParserOptions, "OLD10", INT2NUM(XML_PARSE_OLD10));
|
|
59
|
+
/* do not fixup XINCLUDE xml:base uris */
|
|
60
|
+
rb_define_const(mXMLParserOptions, "NOBASEFIX", INT2NUM(XML_PARSE_NOBASEFIX));
|
|
61
|
+
#endif
|
|
62
|
+
#if LIBXML_VERSION >= 20703
|
|
63
|
+
/* relax any hardcoded limit from the parser */
|
|
64
|
+
rb_define_const(mXMLParserOptions, "HUGE", INT2NUM(XML_PARSE_HUGE));
|
|
65
|
+
#endif
|
|
66
|
+
#if LIBXML_VERSION >= 21106
|
|
67
|
+
/* parse using SAX2 interface before 2.7.0 */
|
|
68
|
+
rb_define_const(mXMLParserOptions, "OLDSAX", INT2NUM(XML_PARSE_OLDSAX));
|
|
69
|
+
/* ignore internal document encoding hint */
|
|
70
|
+
rb_define_const(mXMLParserOptions, "IGNORE_ENC", INT2NUM(XML_PARSE_IGNORE_ENC));
|
|
71
|
+
/* Store big lines numbers in text PSVI field */
|
|
72
|
+
rb_define_const(mXMLParserOptions, "BIG_LINES", INT2NUM(XML_PARSE_BIG_LINES));
|
|
73
|
+
#endif
|
|
74
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
-
|
|
3
|
-
#ifndef __RXML_PARSER_OPTIONS__
|
|
4
|
-
#define __RXML_PARSER_OPTIONS__
|
|
5
|
-
|
|
6
|
-
extern VALUE mXMLParserOptions;
|
|
7
|
-
|
|
8
|
-
void rxml_init_parser_options();
|
|
9
|
-
|
|
10
|
-
#endif
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
+
|
|
3
|
+
#ifndef __RXML_PARSER_OPTIONS__
|
|
4
|
+
#define __RXML_PARSER_OPTIONS__
|
|
5
|
+
|
|
6
|
+
extern VALUE mXMLParserOptions;
|
|
7
|
+
|
|
8
|
+
void rxml_init_parser_options(void);
|
|
9
|
+
|
|
10
|
+
#endif
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
#include "ruby_libxml.h"
|
|
5
5
|
#include "ruby_xml_reader.h"
|
|
6
6
|
|
|
7
|
+
#include <errno.h>
|
|
8
|
+
|
|
7
9
|
#include <libxml/xmlreader.h>
|
|
8
10
|
#include <libxml/xmlschemas.h>
|
|
9
11
|
|
|
12
|
+
|
|
10
13
|
/*
|
|
11
14
|
* Document-class: LibXML::XML::Reader
|
|
12
15
|
*
|
|
@@ -57,28 +60,40 @@ static ID ENCODING_SYMBOL;
|
|
|
57
60
|
static ID IO_ATTR;
|
|
58
61
|
static ID OPTIONS_SYMBOL;
|
|
59
62
|
|
|
60
|
-
static void rxml_reader_free(
|
|
63
|
+
static void rxml_reader_free(void* data)
|
|
61
64
|
{
|
|
65
|
+
xmlTextReaderPtr xreader = (xmlTextReaderPtr)data;
|
|
62
66
|
xmlFreeTextReader(xreader);
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
static void rxml_reader_mark(
|
|
69
|
+
static void rxml_reader_mark(void* data)
|
|
66
70
|
{
|
|
71
|
+
xmlTextReaderPtr xreader = (xmlTextReaderPtr)data;
|
|
67
72
|
xmlDocPtr xdoc = xmlTextReaderCurrentDoc(xreader);
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
if (xdoc)
|
|
74
|
+
{
|
|
75
|
+
VALUE doc = rxml_registry_lookup(xdoc);
|
|
76
|
+
if (!NIL_P(doc))
|
|
77
|
+
rb_gc_mark(doc);
|
|
78
|
+
}
|
|
70
79
|
}
|
|
71
80
|
|
|
81
|
+
static const rb_data_type_t rxml_reader_data_type = {
|
|
82
|
+
.wrap_struct_name = "LibXML::XML::Reader",
|
|
83
|
+
.function = { .dmark = rxml_reader_mark, .dfree = rxml_reader_free },
|
|
84
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
85
|
+
};
|
|
86
|
+
|
|
72
87
|
static VALUE rxml_reader_wrap(xmlTextReaderPtr xreader)
|
|
73
88
|
{
|
|
74
|
-
return
|
|
89
|
+
return TypedData_Wrap_Struct(cXMLReader, &rxml_reader_data_type, xreader);
|
|
75
90
|
}
|
|
76
91
|
|
|
77
92
|
|
|
78
93
|
static xmlTextReaderPtr rxml_text_reader_get(VALUE obj)
|
|
79
94
|
{
|
|
80
95
|
xmlTextReaderPtr xreader;
|
|
81
|
-
|
|
96
|
+
TypedData_Get_Struct(obj, xmlTextReader, &rxml_reader_data_type, xreader);
|
|
82
97
|
return xreader;
|
|
83
98
|
}
|
|
84
99
|
|
|
@@ -93,12 +108,12 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
|
|
|
93
108
|
xmlDocPtr xdoc;
|
|
94
109
|
xmlTextReaderPtr xreader;
|
|
95
110
|
|
|
96
|
-
|
|
111
|
+
TypedData_Get_Struct(doc, xmlDoc, &rxml_document_data_type, xdoc);
|
|
97
112
|
|
|
98
113
|
xreader = xmlReaderWalker(xdoc);
|
|
99
114
|
|
|
100
115
|
if (xreader == NULL)
|
|
101
|
-
rxml_raise(
|
|
116
|
+
rxml_raise(xmlGetLastError());
|
|
102
117
|
|
|
103
118
|
return rxml_reader_wrap(xreader);
|
|
104
119
|
}
|
|
@@ -122,34 +137,31 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
|
|
|
122
137
|
*/
|
|
123
138
|
static VALUE rxml_reader_file(int argc, VALUE *argv, VALUE klass)
|
|
124
139
|
{
|
|
125
|
-
xmlTextReaderPtr xreader;
|
|
126
140
|
VALUE path;
|
|
127
141
|
VALUE options;
|
|
128
142
|
|
|
129
|
-
const char *xencoding = NULL;
|
|
130
|
-
int xoptions = 0;
|
|
131
|
-
|
|
132
143
|
rb_scan_args(argc, argv, "11", &path, &options);
|
|
133
144
|
Check_Type(path, T_STRING);
|
|
134
145
|
|
|
146
|
+
const char* xencoding = NULL;
|
|
147
|
+
int xoptions = 0;
|
|
148
|
+
|
|
135
149
|
if (!NIL_P(options))
|
|
136
150
|
{
|
|
137
|
-
VALUE encoding = Qnil;
|
|
138
|
-
VALUE parserOptions = Qnil;
|
|
139
|
-
|
|
140
151
|
Check_Type(options, T_HASH);
|
|
141
152
|
|
|
142
|
-
encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
|
|
153
|
+
VALUE encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
|
|
143
154
|
xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding));
|
|
144
155
|
|
|
145
|
-
parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
|
|
156
|
+
VALUE parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
|
|
146
157
|
xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions);
|
|
147
158
|
}
|
|
148
159
|
|
|
149
|
-
xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
|
|
160
|
+
xmlTextReaderPtr xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
|
|
150
161
|
|
|
162
|
+
// Unfortunately libxml2 does not set xmlLastError and just returns a null reader
|
|
151
163
|
if (xreader == NULL)
|
|
152
|
-
|
|
164
|
+
rb_syserr_fail(ENOENT, StringValueCStr(path));
|
|
153
165
|
|
|
154
166
|
return rxml_reader_wrap(xreader);
|
|
155
167
|
}
|
|
@@ -207,7 +219,7 @@ static VALUE rxml_reader_io(int argc, VALUE *argv, VALUE klass)
|
|
|
207
219
|
xbaseurl, xencoding, xoptions);
|
|
208
220
|
|
|
209
221
|
if (xreader == NULL)
|
|
210
|
-
rxml_raise(
|
|
222
|
+
rxml_raise(xmlGetLastError());
|
|
211
223
|
|
|
212
224
|
result = rxml_reader_wrap(xreader);
|
|
213
225
|
|
|
@@ -269,7 +281,7 @@ static VALUE rxml_reader_string(int argc, VALUE *argv, VALUE klass)
|
|
|
269
281
|
xbaseurl, xencoding, xoptions);
|
|
270
282
|
|
|
271
283
|
if (xreader == NULL)
|
|
272
|
-
rxml_raise(
|
|
284
|
+
rxml_raise(xmlGetLastError());
|
|
273
285
|
|
|
274
286
|
return rxml_reader_wrap(xreader);
|
|
275
287
|
}
|
|
@@ -472,7 +484,7 @@ static VALUE rxml_reader_read(VALUE self)
|
|
|
472
484
|
switch(result)
|
|
473
485
|
{
|
|
474
486
|
case -1:
|
|
475
|
-
rxml_raise(
|
|
487
|
+
rxml_raise(xmlGetLastError());
|
|
476
488
|
return Qnil;
|
|
477
489
|
break;
|
|
478
490
|
case 0:
|
|
@@ -607,7 +619,7 @@ static VALUE rxml_reader_relax_ng_validate(VALUE self, VALUE rng)
|
|
|
607
619
|
xmlTextReaderPtr xreader = rxml_text_reader_get(self);
|
|
608
620
|
xmlRelaxNGPtr xrelax;
|
|
609
621
|
int status;
|
|
610
|
-
|
|
622
|
+
TypedData_Get_Struct(rng, xmlRelaxNG, &rxml_relaxng_data_type, xrelax);
|
|
611
623
|
|
|
612
624
|
status = xmlTextReaderRelaxNGSetSchema(xreader, xrelax);
|
|
613
625
|
return (status == 0 ? Qtrue : Qfalse);
|
|
@@ -632,7 +644,7 @@ rxml_reader_schema_validate(VALUE self, VALUE xsd)
|
|
|
632
644
|
xmlSchemaPtr xschema;
|
|
633
645
|
int status;
|
|
634
646
|
|
|
635
|
-
|
|
647
|
+
TypedData_Get_Struct(xsd, xmlSchema, &rxml_schema_type, xschema);
|
|
636
648
|
status = xmlTextReaderSetSchema(xreader, xschema);
|
|
637
649
|
return (status == 0 ? Qtrue : Qfalse);
|
|
638
650
|
}
|
|
@@ -998,12 +1010,12 @@ static VALUE rxml_reader_expand(VALUE self)
|
|
|
998
1010
|
}
|
|
999
1011
|
else
|
|
1000
1012
|
{
|
|
1001
|
-
/* We cannot call rxml_node_wrap here because
|
|
1013
|
+
/* We cannot call rxml_node_wrap here because it sets up a mark function
|
|
1002
1014
|
for the node. But according to the libxml docs (http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderExpand)
|
|
1003
1015
|
this is only valid until the next xmlTextReaderRead call. At that point the node is freed (from reading
|
|
1004
|
-
the libxml2 source code. So don't set a mark or free function, because they will get called in the next
|
|
1016
|
+
the libxml2 source code). So don't set a mark or free function, because they will get called in the next
|
|
1005
1017
|
garbage collection run and cause a segfault.*/
|
|
1006
|
-
return
|
|
1018
|
+
return TypedData_Wrap_Struct(cXMLNode, &rxml_node_unmanaged_data_type, xnode);
|
|
1007
1019
|
}
|
|
1008
1020
|
}
|
|
1009
1021
|
|
|
@@ -1028,9 +1040,6 @@ static VALUE rxml_reader_doc(VALUE self)
|
|
|
1028
1040
|
|
|
1029
1041
|
result = rxml_document_wrap(xdoc);
|
|
1030
1042
|
|
|
1031
|
-
// And now hook in a mark function to keep the document alive as long as the reader is valid
|
|
1032
|
-
RDATA(self)->dmark = (RUBY_DATA_FUNC)rxml_reader_mark;
|
|
1033
|
-
|
|
1034
1043
|
return result;
|
|
1035
1044
|
}
|
|
1036
1045
|
|
|
@@ -1048,7 +1057,7 @@ static VALUE
|
|
|
1048
1057
|
rxml_reader_byte_consumed(VALUE self)
|
|
1049
1058
|
{
|
|
1050
1059
|
xmlTextReaderPtr xreader = rxml_text_reader_get(self);
|
|
1051
|
-
return
|
|
1060
|
+
return LONG2NUM(xmlTextReaderByteConsumed(xreader));
|
|
1052
1061
|
}
|
|
1053
1062
|
#endif
|
|
1054
1063
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/* Copyright (c) 2006 Apple Computer Inc.
|
|
2
|
-
* Please see the LICENSE file for copyright and distribution information. */
|
|
3
|
-
|
|
4
|
-
#ifndef __RXML_READER__
|
|
5
|
-
#define __RXML_READER__
|
|
6
|
-
|
|
7
|
-
extern VALUE cXMLReader;
|
|
8
|
-
|
|
9
|
-
void rxml_init_reader(void);
|
|
10
|
-
|
|
11
|
-
/* Exported to be used by XML::Document#reader */
|
|
12
|
-
VALUE rxml_reader_new_walker(VALUE self, VALUE doc);
|
|
13
|
-
|
|
14
|
-
#endif /* __rxml_READER__ */
|
|
1
|
+
/* Copyright (c) 2006 Apple Computer Inc.
|
|
2
|
+
* Please see the LICENSE file for copyright and distribution information. */
|
|
3
|
+
|
|
4
|
+
#ifndef __RXML_READER__
|
|
5
|
+
#define __RXML_READER__
|
|
6
|
+
|
|
7
|
+
extern VALUE cXMLReader;
|
|
8
|
+
|
|
9
|
+
void rxml_init_reader(void);
|
|
10
|
+
|
|
11
|
+
/* Exported to be used by XML::Document#reader */
|
|
12
|
+
VALUE rxml_reader_new_walker(VALUE self, VALUE doc);
|
|
13
|
+
|
|
14
|
+
#endif /* __rxml_READER__ */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
+
|
|
3
|
+
#include "ruby_libxml.h"
|
|
4
|
+
#include "ruby_xml_registry.h"
|
|
5
|
+
|
|
6
|
+
#include <ruby/st.h>
|
|
7
|
+
|
|
8
|
+
static st_table *rxml_registry;
|
|
9
|
+
|
|
10
|
+
void rxml_init_registry(void)
|
|
11
|
+
{
|
|
12
|
+
rxml_registry = st_init_numtable();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
void rxml_registry_register(void *ptr, VALUE obj)
|
|
16
|
+
{
|
|
17
|
+
st_insert(rxml_registry, (st_data_t)ptr, (st_data_t)obj);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void rxml_registry_unregister(void *ptr)
|
|
21
|
+
{
|
|
22
|
+
st_delete(rxml_registry, (st_data_t *)&ptr, NULL);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
VALUE rxml_registry_lookup(void *ptr)
|
|
26
|
+
{
|
|
27
|
+
st_data_t val;
|
|
28
|
+
if (st_lookup(rxml_registry, (st_data_t)ptr, &val))
|
|
29
|
+
return (VALUE)val;
|
|
30
|
+
return Qnil;
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
+
|
|
3
|
+
#ifndef __RXML_REGISTRY__
|
|
4
|
+
#define __RXML_REGISTRY__
|
|
5
|
+
|
|
6
|
+
/* Pointer-to-VALUE registry for mapping C structs (xmlDocPtr, xmlNodePtr,
|
|
7
|
+
etc.) back to their Ruby wrappers.
|
|
8
|
+
|
|
9
|
+
The registry is a global st_table keyed by C pointer address. It is NOT a
|
|
10
|
+
GC root -- entries do not prevent garbage collection. Objects stay alive
|
|
11
|
+
through the normal mark chains (mark functions look up the registry instead
|
|
12
|
+
of reading _private).
|
|
13
|
+
|
|
14
|
+
Registered pointers MUST be unregistered before the underlying C struct is
|
|
15
|
+
freed, typically in the wrapper's dfree function. */
|
|
16
|
+
|
|
17
|
+
void rxml_init_registry(void);
|
|
18
|
+
void rxml_registry_register(void *ptr, VALUE obj);
|
|
19
|
+
void rxml_registry_unregister(void *ptr);
|
|
20
|
+
VALUE rxml_registry_lookup(void *ptr); /* Qnil on miss */
|
|
21
|
+
|
|
22
|
+
#endif
|
|
@@ -34,11 +34,18 @@
|
|
|
34
34
|
|
|
35
35
|
VALUE cXMLRelaxNG;
|
|
36
36
|
|
|
37
|
-
static void rxml_relaxng_free(
|
|
37
|
+
static void rxml_relaxng_free(void* data)
|
|
38
38
|
{
|
|
39
|
+
xmlRelaxNGPtr xrelaxng = (xmlRelaxNGPtr)data;
|
|
39
40
|
xmlRelaxNGFree(xrelaxng);
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
const rb_data_type_t rxml_relaxng_data_type = {
|
|
44
|
+
.wrap_struct_name = "LibXML::XML::RelaxNG",
|
|
45
|
+
.function = { .dmark = NULL, .dfree = rxml_relaxng_free },
|
|
46
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
47
|
+
};
|
|
48
|
+
|
|
42
49
|
/*
|
|
43
50
|
* call-seq:
|
|
44
51
|
* XML::Relaxng.new(relaxng_uri) -> relaxng
|
|
@@ -56,7 +63,10 @@ static VALUE rxml_relaxng_init_from_uri(VALUE class, VALUE uri)
|
|
|
56
63
|
xrelaxng = xmlRelaxNGParse(xparser);
|
|
57
64
|
xmlRelaxNGFreeParserCtxt(xparser);
|
|
58
65
|
|
|
59
|
-
|
|
66
|
+
if (!xrelaxng)
|
|
67
|
+
rxml_raise(xmlGetLastError());
|
|
68
|
+
|
|
69
|
+
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
/*
|
|
@@ -71,13 +81,16 @@ static VALUE rxml_relaxng_init_from_document(VALUE class, VALUE document)
|
|
|
71
81
|
xmlRelaxNGPtr xrelaxng;
|
|
72
82
|
xmlRelaxNGParserCtxtPtr xparser;
|
|
73
83
|
|
|
74
|
-
|
|
84
|
+
TypedData_Get_Struct(document, xmlDoc, &rxml_document_data_type, xdoc);
|
|
75
85
|
|
|
76
86
|
xparser = xmlRelaxNGNewDocParserCtxt(xdoc);
|
|
77
87
|
xrelaxng = xmlRelaxNGParse(xparser);
|
|
78
88
|
xmlRelaxNGFreeParserCtxt(xparser);
|
|
79
89
|
|
|
80
|
-
|
|
90
|
+
if (!xrelaxng)
|
|
91
|
+
rxml_raise(xmlGetLastError());
|
|
92
|
+
|
|
93
|
+
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
|
|
81
94
|
}
|
|
82
95
|
|
|
83
96
|
/*
|
|
@@ -97,7 +110,10 @@ static VALUE rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str)
|
|
|
97
110
|
xrelaxng = xmlRelaxNGParse(xparser);
|
|
98
111
|
xmlRelaxNGFreeParserCtxt(xparser);
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
if (!xrelaxng)
|
|
114
|
+
rxml_raise(xmlGetLastError());
|
|
115
|
+
|
|
116
|
+
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
|
|
101
117
|
}
|
|
102
118
|
|
|
103
119
|
void rxml_init_relaxng(void)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
#ifndef __RXML_RELAXNG__
|
|
2
|
-
#define __RXML_RELAXNG__
|
|
3
|
-
|
|
4
|
-
extern VALUE cXMLRelaxNG;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
#ifndef __RXML_RELAXNG__
|
|
2
|
+
#define __RXML_RELAXNG__
|
|
3
|
+
|
|
4
|
+
extern VALUE cXMLRelaxNG;
|
|
5
|
+
extern const rb_data_type_t rxml_relaxng_data_type;
|
|
6
|
+
|
|
7
|
+
void rxml_init_relaxng(void);
|
|
8
|
+
#endif
|
|
9
|
+
|