nokogiri 1.13.0-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/LICENSE-DEPENDENCIES.md +1903 -0
- data/LICENSE.md +9 -0
- data/README.md +280 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +73 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1000 -0
- data/ext/nokogiri/gumbo.c +584 -0
- data/ext/nokogiri/html4_document.c +166 -0
- data/ext/nokogiri/html4_element_description.c +294 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +120 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1243 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +368 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +946 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +564 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +278 -0
- data/ext/nokogiri/nokogiri.h +223 -0
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_cdata.c +57 -0
- data/ext/nokogiri/xml_comment.c +62 -0
- data/ext/nokogiri/xml_document.c +680 -0
- data/ext/nokogiri/xml_document_fragment.c +44 -0
- data/ext/nokogiri/xml_dtd.c +208 -0
- data/ext/nokogiri/xml_element_content.c +128 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_encoding_handler.c +104 -0
- data/ext/nokogiri/xml_entity_decl.c +112 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_namespace.c +120 -0
- data/ext/nokogiri/xml_node.c +2144 -0
- data/ext/nokogiri/xml_node_set.c +498 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +719 -0
- data/ext/nokogiri/xml_relax_ng.c +185 -0
- data/ext/nokogiri/xml_sax_parser.c +310 -0
- data/ext/nokogiri/xml_sax_parser_context.c +281 -0
- data/ext/nokogiri/xml_sax_push_parser.c +168 -0
- data/ext/nokogiri/xml_schema.c +284 -0
- data/ext/nokogiri/xml_syntax_error.c +85 -0
- data/ext/nokogiri/xml_text.c +48 -0
- data/ext/nokogiri/xml_xpath_context.c +406 -0
- data/ext/nokogiri/xslt_stylesheet.c +264 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +101 -0
- data/gumbo-parser/THANKS +27 -0
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +54 -0
- data/lib/nokogiri/css/parser.rb +759 -0
- data/lib/nokogiri/css/parser.y +280 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rb +155 -0
- data/lib/nokogiri/css/tokenizer.rex +56 -0
- data/lib/nokogiri/css/xpath_visitor.rb +359 -0
- data/lib/nokogiri/css.rb +60 -0
- data/lib/nokogiri/decorators/slop.rb +44 -0
- data/lib/nokogiri/extension.rb +31 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +48 -0
- data/lib/nokogiri/html4/builder.rb +37 -0
- data/lib/nokogiri/html4/document.rb +331 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/html4/element_description.rb +25 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +578 -0
- data/lib/nokogiri/html4/entity_lookup.rb +15 -0
- data/lib/nokogiri/html4/sax/parser.rb +61 -0
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +46 -0
- data/lib/nokogiri/html5/document.rb +88 -0
- data/lib/nokogiri/html5/document_fragment.rb +83 -0
- data/lib/nokogiri/html5/node.rb +96 -0
- data/lib/nokogiri/html5.rb +477 -0
- data/lib/nokogiri/jruby/dependencies.rb +21 -0
- data/lib/nokogiri/syntax_error.rb +6 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +221 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +17 -0
- data/lib/nokogiri/xml/attribute_decl.rb +20 -0
- data/lib/nokogiri/xml/builder.rb +485 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +418 -0
- data/lib/nokogiri/xml/document_fragment.rb +162 -0
- data/lib/nokogiri/xml/dtd.rb +34 -0
- data/lib/nokogiri/xml/element_content.rb +38 -0
- data/lib/nokogiri/xml/element_decl.rb +15 -0
- data/lib/nokogiri/xml/entity_decl.rb +21 -0
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +16 -0
- data/lib/nokogiri/xml/node/save_options.rb +65 -0
- data/lib/nokogiri/xml/node.rb +1402 -0
- data/lib/nokogiri/xml/node_set.rb +364 -0
- data/lib/nokogiri/xml/notation.rb +19 -0
- data/lib/nokogiri/xml/parse_options.rb +133 -0
- data/lib/nokogiri/xml/pp/character_data.rb +21 -0
- data/lib/nokogiri/xml/pp/node.rb +55 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +10 -0
- data/lib/nokogiri/xml/reader.rb +107 -0
- data/lib/nokogiri/xml/relax_ng.rb +38 -0
- data/lib/nokogiri/xml/sax/document.rb +167 -0
- data/lib/nokogiri/xml/sax/parser.rb +125 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +6 -0
- data/lib/nokogiri/xml/schema.rb +73 -0
- data/lib/nokogiri/xml/searchable.rb +259 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
- data/lib/nokogiri/xml/xpath.rb +21 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xml.rb +75 -0
- data/lib/nokogiri/xslt/stylesheet.rb +27 -0
- data/lib/nokogiri/xslt.rb +58 -0
- data/lib/nokogiri.rb +128 -0
- data/lib/xsd/xmlparser/nokogiri.rb +104 -0
- metadata +536 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlRelaxNG;
|
4
|
+
|
5
|
+
static void
|
6
|
+
dealloc(xmlRelaxNGPtr schema)
|
7
|
+
{
|
8
|
+
NOKOGIRI_DEBUG_START(schema);
|
9
|
+
xmlRelaxNGFree(schema);
|
10
|
+
NOKOGIRI_DEBUG_END(schema);
|
11
|
+
}
|
12
|
+
|
13
|
+
/*
|
14
|
+
* call-seq:
|
15
|
+
* validate_document(document)
|
16
|
+
*
|
17
|
+
* Validate a Nokogiri::XML::Document against this RelaxNG schema.
|
18
|
+
*/
|
19
|
+
static VALUE
|
20
|
+
validate_document(VALUE self, VALUE document)
|
21
|
+
{
|
22
|
+
xmlDocPtr doc;
|
23
|
+
xmlRelaxNGPtr schema;
|
24
|
+
VALUE errors;
|
25
|
+
xmlRelaxNGValidCtxtPtr valid_ctxt;
|
26
|
+
|
27
|
+
Data_Get_Struct(self, xmlRelaxNG, schema);
|
28
|
+
Data_Get_Struct(document, xmlDoc, doc);
|
29
|
+
|
30
|
+
errors = rb_ary_new();
|
31
|
+
|
32
|
+
valid_ctxt = xmlRelaxNGNewValidCtxt(schema);
|
33
|
+
|
34
|
+
if (NULL == valid_ctxt) {
|
35
|
+
/* we have a problem */
|
36
|
+
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
37
|
+
}
|
38
|
+
|
39
|
+
#ifdef HAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS
|
40
|
+
xmlRelaxNGSetValidStructuredErrors(
|
41
|
+
valid_ctxt,
|
42
|
+
Nokogiri_error_array_pusher,
|
43
|
+
(void *)errors
|
44
|
+
);
|
45
|
+
#endif
|
46
|
+
|
47
|
+
xmlRelaxNGValidateDoc(valid_ctxt, doc);
|
48
|
+
|
49
|
+
xmlRelaxNGFreeValidCtxt(valid_ctxt);
|
50
|
+
|
51
|
+
return errors;
|
52
|
+
}
|
53
|
+
|
54
|
+
/*
|
55
|
+
* call-seq:
|
56
|
+
* read_memory(string)
|
57
|
+
*
|
58
|
+
* Create a new RelaxNG from the contents of +string+
|
59
|
+
*/
|
60
|
+
static VALUE
|
61
|
+
read_memory(int argc, VALUE *argv, VALUE klass)
|
62
|
+
{
|
63
|
+
VALUE content;
|
64
|
+
VALUE parse_options;
|
65
|
+
xmlRelaxNGParserCtxtPtr ctx;
|
66
|
+
xmlRelaxNGPtr schema;
|
67
|
+
VALUE errors;
|
68
|
+
VALUE rb_schema;
|
69
|
+
int scanned_args = 0;
|
70
|
+
|
71
|
+
scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
72
|
+
if (scanned_args == 1) {
|
73
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
74
|
+
}
|
75
|
+
|
76
|
+
ctx = xmlRelaxNGNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
77
|
+
|
78
|
+
errors = rb_ary_new();
|
79
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
80
|
+
|
81
|
+
#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
|
82
|
+
xmlRelaxNGSetParserStructuredErrors(
|
83
|
+
ctx,
|
84
|
+
Nokogiri_error_array_pusher,
|
85
|
+
(void *)errors
|
86
|
+
);
|
87
|
+
#endif
|
88
|
+
|
89
|
+
schema = xmlRelaxNGParse(ctx);
|
90
|
+
|
91
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
92
|
+
xmlRelaxNGFreeParserCtxt(ctx);
|
93
|
+
|
94
|
+
if (NULL == schema) {
|
95
|
+
xmlErrorPtr error = xmlGetLastError();
|
96
|
+
if (error) {
|
97
|
+
Nokogiri_error_raise(NULL, error);
|
98
|
+
} else {
|
99
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
100
|
+
}
|
101
|
+
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
106
|
+
rb_iv_set(rb_schema, "@errors", errors);
|
107
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
108
|
+
|
109
|
+
return rb_schema;
|
110
|
+
}
|
111
|
+
|
112
|
+
/*
|
113
|
+
* call-seq:
|
114
|
+
* from_document(doc)
|
115
|
+
*
|
116
|
+
* Create a new RelaxNG schema from the Nokogiri::XML::Document +doc+
|
117
|
+
*/
|
118
|
+
static VALUE
|
119
|
+
from_document(int argc, VALUE *argv, VALUE klass)
|
120
|
+
{
|
121
|
+
VALUE document;
|
122
|
+
VALUE parse_options;
|
123
|
+
xmlDocPtr doc;
|
124
|
+
xmlRelaxNGParserCtxtPtr ctx;
|
125
|
+
xmlRelaxNGPtr schema;
|
126
|
+
VALUE errors;
|
127
|
+
VALUE rb_schema;
|
128
|
+
int scanned_args = 0;
|
129
|
+
|
130
|
+
scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
|
131
|
+
|
132
|
+
Data_Get_Struct(document, xmlDoc, doc);
|
133
|
+
doc = doc->doc; /* In case someone passes us a node. ugh. */
|
134
|
+
|
135
|
+
if (scanned_args == 1) {
|
136
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
137
|
+
}
|
138
|
+
|
139
|
+
ctx = xmlRelaxNGNewDocParserCtxt(doc);
|
140
|
+
|
141
|
+
errors = rb_ary_new();
|
142
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
143
|
+
|
144
|
+
#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
|
145
|
+
xmlRelaxNGSetParserStructuredErrors(
|
146
|
+
ctx,
|
147
|
+
Nokogiri_error_array_pusher,
|
148
|
+
(void *)errors
|
149
|
+
);
|
150
|
+
#endif
|
151
|
+
|
152
|
+
schema = xmlRelaxNGParse(ctx);
|
153
|
+
|
154
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
155
|
+
xmlRelaxNGFreeParserCtxt(ctx);
|
156
|
+
|
157
|
+
if (NULL == schema) {
|
158
|
+
xmlErrorPtr error = xmlGetLastError();
|
159
|
+
if (error) {
|
160
|
+
Nokogiri_error_raise(NULL, error);
|
161
|
+
} else {
|
162
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
163
|
+
}
|
164
|
+
|
165
|
+
return Qnil;
|
166
|
+
}
|
167
|
+
|
168
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
169
|
+
rb_iv_set(rb_schema, "@errors", errors);
|
170
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
171
|
+
|
172
|
+
return rb_schema;
|
173
|
+
}
|
174
|
+
|
175
|
+
void
|
176
|
+
noko_init_xml_relax_ng()
|
177
|
+
{
|
178
|
+
assert(cNokogiriXmlSchema);
|
179
|
+
cNokogiriXmlRelaxNG = rb_define_class_under(mNokogiriXml, "RelaxNG", cNokogiriXmlSchema);
|
180
|
+
|
181
|
+
rb_define_singleton_method(cNokogiriXmlRelaxNG, "read_memory", read_memory, -1);
|
182
|
+
rb_define_singleton_method(cNokogiriXmlRelaxNG, "from_document", from_document, -1);
|
183
|
+
|
184
|
+
rb_define_private_method(cNokogiriXmlRelaxNG, "validate_document", validate_document, 1);
|
185
|
+
}
|
@@ -0,0 +1,310 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSaxParser ;
|
4
|
+
|
5
|
+
static ID id_start_document, id_end_document, id_start_element, id_end_element;
|
6
|
+
static ID id_start_element_namespace, id_end_element_namespace;
|
7
|
+
static ID id_comment, id_characters, id_xmldecl, id_error, id_warning;
|
8
|
+
static ID id_cdata_block;
|
9
|
+
static ID id_processing_instruction;
|
10
|
+
|
11
|
+
static void
|
12
|
+
start_document(void *ctx)
|
13
|
+
{
|
14
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
15
|
+
VALUE doc = rb_iv_get(self, "@document");
|
16
|
+
|
17
|
+
xmlParserCtxtPtr ctxt = NOKOGIRI_SAX_CTXT(ctx);
|
18
|
+
|
19
|
+
if (NULL != ctxt && ctxt->html != 1) {
|
20
|
+
if (ctxt->standalone != -1) { /* -1 means there was no declaration */
|
21
|
+
VALUE encoding = Qnil ;
|
22
|
+
VALUE standalone = Qnil;
|
23
|
+
VALUE version;
|
24
|
+
if (ctxt->encoding) {
|
25
|
+
encoding = NOKOGIRI_STR_NEW2(ctxt->encoding) ;
|
26
|
+
} else if (ctxt->input && ctxt->input->encoding) {
|
27
|
+
encoding = NOKOGIRI_STR_NEW2(ctxt->input->encoding) ;
|
28
|
+
}
|
29
|
+
|
30
|
+
version = ctxt->version ? NOKOGIRI_STR_NEW2(ctxt->version) : Qnil;
|
31
|
+
|
32
|
+
switch (ctxt->standalone) {
|
33
|
+
case 0:
|
34
|
+
standalone = NOKOGIRI_STR_NEW2("no");
|
35
|
+
break;
|
36
|
+
case 1:
|
37
|
+
standalone = NOKOGIRI_STR_NEW2("yes");
|
38
|
+
break;
|
39
|
+
}
|
40
|
+
|
41
|
+
rb_funcall(doc, id_xmldecl, 3, version, encoding, standalone);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
rb_funcall(doc, id_start_document, 0);
|
46
|
+
}
|
47
|
+
|
48
|
+
static void
|
49
|
+
end_document(void *ctx)
|
50
|
+
{
|
51
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
52
|
+
VALUE doc = rb_iv_get(self, "@document");
|
53
|
+
rb_funcall(doc, id_end_document, 0);
|
54
|
+
}
|
55
|
+
|
56
|
+
static void
|
57
|
+
start_element(void *ctx, const xmlChar *name, const xmlChar **atts)
|
58
|
+
{
|
59
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
60
|
+
VALUE doc = rb_iv_get(self, "@document");
|
61
|
+
VALUE attributes = rb_ary_new();
|
62
|
+
const xmlChar *attr;
|
63
|
+
int i = 0;
|
64
|
+
if (atts) {
|
65
|
+
while ((attr = atts[i]) != NULL) {
|
66
|
+
const xmlChar *val = atts[i + 1];
|
67
|
+
VALUE value = val != NULL ? NOKOGIRI_STR_NEW2(val) : Qnil;
|
68
|
+
rb_ary_push(attributes, rb_ary_new3(2, NOKOGIRI_STR_NEW2(attr), value));
|
69
|
+
i += 2;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
rb_funcall(doc,
|
74
|
+
id_start_element,
|
75
|
+
2,
|
76
|
+
NOKOGIRI_STR_NEW2(name),
|
77
|
+
attributes
|
78
|
+
);
|
79
|
+
}
|
80
|
+
|
81
|
+
static void
|
82
|
+
end_element(void *ctx, const xmlChar *name)
|
83
|
+
{
|
84
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
85
|
+
VALUE doc = rb_iv_get(self, "@document");
|
86
|
+
rb_funcall(doc, id_end_element, 1, NOKOGIRI_STR_NEW2(name));
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE
|
90
|
+
attributes_as_array(int attributes_len, const xmlChar **c_attributes)
|
91
|
+
{
|
92
|
+
VALUE rb_array = rb_ary_new2((long)attributes_len);
|
93
|
+
VALUE cNokogiriXmlSaxParserAttribute;
|
94
|
+
|
95
|
+
cNokogiriXmlSaxParserAttribute = rb_const_get_at(cNokogiriXmlSaxParser, rb_intern("Attribute"));
|
96
|
+
if (c_attributes) {
|
97
|
+
/* Each attribute is an array of [localname, prefix, URI, value, end] */
|
98
|
+
int i;
|
99
|
+
for (i = 0; i < attributes_len * 5; i += 5) {
|
100
|
+
VALUE rb_constructor_args[4], rb_attribute;
|
101
|
+
|
102
|
+
rb_constructor_args[0] = RBSTR_OR_QNIL(c_attributes[i + 0]); /* localname */
|
103
|
+
rb_constructor_args[1] = RBSTR_OR_QNIL(c_attributes[i + 1]); /* prefix */
|
104
|
+
rb_constructor_args[2] = RBSTR_OR_QNIL(c_attributes[i + 2]); /* URI */
|
105
|
+
|
106
|
+
/* value */
|
107
|
+
rb_constructor_args[3] = NOKOGIRI_STR_NEW((const char *)c_attributes[i + 3],
|
108
|
+
(c_attributes[i + 4] - c_attributes[i + 3]));
|
109
|
+
|
110
|
+
rb_attribute = rb_class_new_instance(4, rb_constructor_args, cNokogiriXmlSaxParserAttribute);
|
111
|
+
rb_ary_push(rb_array, rb_attribute);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
return rb_array;
|
116
|
+
}
|
117
|
+
|
118
|
+
static void
|
119
|
+
start_element_ns(
|
120
|
+
void *ctx,
|
121
|
+
const xmlChar *localname,
|
122
|
+
const xmlChar *prefix,
|
123
|
+
const xmlChar *uri,
|
124
|
+
int nb_namespaces,
|
125
|
+
const xmlChar **namespaces,
|
126
|
+
int nb_attributes,
|
127
|
+
int nb_defaulted,
|
128
|
+
const xmlChar **attributes)
|
129
|
+
{
|
130
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
131
|
+
VALUE doc = rb_iv_get(self, "@document");
|
132
|
+
|
133
|
+
VALUE attribute_ary = attributes_as_array(nb_attributes, attributes);
|
134
|
+
|
135
|
+
VALUE ns_list = rb_ary_new2((long)nb_namespaces);
|
136
|
+
|
137
|
+
if (namespaces) {
|
138
|
+
int i;
|
139
|
+
for (i = 0; i < nb_namespaces * 2; i += 2) {
|
140
|
+
rb_ary_push(ns_list,
|
141
|
+
rb_ary_new3((long)2,
|
142
|
+
RBSTR_OR_QNIL(namespaces[i + 0]),
|
143
|
+
RBSTR_OR_QNIL(namespaces[i + 1])
|
144
|
+
)
|
145
|
+
);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
rb_funcall(doc,
|
150
|
+
id_start_element_namespace,
|
151
|
+
5,
|
152
|
+
NOKOGIRI_STR_NEW2(localname),
|
153
|
+
attribute_ary,
|
154
|
+
RBSTR_OR_QNIL(prefix),
|
155
|
+
RBSTR_OR_QNIL(uri),
|
156
|
+
ns_list
|
157
|
+
);
|
158
|
+
}
|
159
|
+
|
160
|
+
/**
|
161
|
+
* end_element_ns was borrowed heavily from libxml-ruby.
|
162
|
+
*/
|
163
|
+
static void
|
164
|
+
end_element_ns(
|
165
|
+
void *ctx,
|
166
|
+
const xmlChar *localname,
|
167
|
+
const xmlChar *prefix,
|
168
|
+
const xmlChar *uri)
|
169
|
+
{
|
170
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
171
|
+
VALUE doc = rb_iv_get(self, "@document");
|
172
|
+
|
173
|
+
rb_funcall(doc, id_end_element_namespace, 3,
|
174
|
+
NOKOGIRI_STR_NEW2(localname),
|
175
|
+
RBSTR_OR_QNIL(prefix),
|
176
|
+
RBSTR_OR_QNIL(uri)
|
177
|
+
);
|
178
|
+
}
|
179
|
+
|
180
|
+
static void
|
181
|
+
characters_func(void *ctx, const xmlChar *ch, int len)
|
182
|
+
{
|
183
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
184
|
+
VALUE doc = rb_iv_get(self, "@document");
|
185
|
+
VALUE str = NOKOGIRI_STR_NEW(ch, len);
|
186
|
+
rb_funcall(doc, id_characters, 1, str);
|
187
|
+
}
|
188
|
+
|
189
|
+
static void
|
190
|
+
comment_func(void *ctx, const xmlChar *value)
|
191
|
+
{
|
192
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
193
|
+
VALUE doc = rb_iv_get(self, "@document");
|
194
|
+
VALUE str = NOKOGIRI_STR_NEW2(value);
|
195
|
+
rb_funcall(doc, id_comment, 1, str);
|
196
|
+
}
|
197
|
+
|
198
|
+
static void
|
199
|
+
warning_func(void *ctx, const char *msg, ...)
|
200
|
+
{
|
201
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
202
|
+
VALUE doc = rb_iv_get(self, "@document");
|
203
|
+
char *message;
|
204
|
+
VALUE ruby_message;
|
205
|
+
|
206
|
+
va_list args;
|
207
|
+
va_start(args, msg);
|
208
|
+
vasprintf(&message, msg, args);
|
209
|
+
va_end(args);
|
210
|
+
|
211
|
+
ruby_message = NOKOGIRI_STR_NEW2(message);
|
212
|
+
free(message);
|
213
|
+
rb_funcall(doc, id_warning, 1, ruby_message);
|
214
|
+
}
|
215
|
+
|
216
|
+
static void
|
217
|
+
error_func(void *ctx, const char *msg, ...)
|
218
|
+
{
|
219
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
220
|
+
VALUE doc = rb_iv_get(self, "@document");
|
221
|
+
char *message;
|
222
|
+
VALUE ruby_message;
|
223
|
+
|
224
|
+
va_list args;
|
225
|
+
va_start(args, msg);
|
226
|
+
vasprintf(&message, msg, args);
|
227
|
+
va_end(args);
|
228
|
+
|
229
|
+
ruby_message = NOKOGIRI_STR_NEW2(message);
|
230
|
+
free(message);
|
231
|
+
rb_funcall(doc, id_error, 1, ruby_message);
|
232
|
+
}
|
233
|
+
|
234
|
+
static void
|
235
|
+
cdata_block(void *ctx, const xmlChar *value, int len)
|
236
|
+
{
|
237
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
238
|
+
VALUE doc = rb_iv_get(self, "@document");
|
239
|
+
VALUE string = NOKOGIRI_STR_NEW(value, len);
|
240
|
+
rb_funcall(doc, id_cdata_block, 1, string);
|
241
|
+
}
|
242
|
+
|
243
|
+
static void
|
244
|
+
processing_instruction(void *ctx, const xmlChar *name, const xmlChar *content)
|
245
|
+
{
|
246
|
+
VALUE rb_content;
|
247
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
248
|
+
VALUE doc = rb_iv_get(self, "@document");
|
249
|
+
|
250
|
+
rb_content = content ? NOKOGIRI_STR_NEW2(content) : Qnil;
|
251
|
+
|
252
|
+
rb_funcall(doc,
|
253
|
+
id_processing_instruction,
|
254
|
+
2,
|
255
|
+
NOKOGIRI_STR_NEW2(name),
|
256
|
+
rb_content
|
257
|
+
);
|
258
|
+
}
|
259
|
+
|
260
|
+
static void
|
261
|
+
deallocate(xmlSAXHandlerPtr handler)
|
262
|
+
{
|
263
|
+
NOKOGIRI_DEBUG_START(handler);
|
264
|
+
free(handler);
|
265
|
+
NOKOGIRI_DEBUG_END(handler);
|
266
|
+
}
|
267
|
+
|
268
|
+
static VALUE
|
269
|
+
allocate(VALUE klass)
|
270
|
+
{
|
271
|
+
xmlSAXHandlerPtr handler = calloc((size_t)1, sizeof(xmlSAXHandler));
|
272
|
+
|
273
|
+
handler->startDocument = start_document;
|
274
|
+
handler->endDocument = end_document;
|
275
|
+
handler->startElement = start_element;
|
276
|
+
handler->endElement = end_element;
|
277
|
+
handler->startElementNs = start_element_ns;
|
278
|
+
handler->endElementNs = end_element_ns;
|
279
|
+
handler->characters = characters_func;
|
280
|
+
handler->comment = comment_func;
|
281
|
+
handler->warning = warning_func;
|
282
|
+
handler->error = error_func;
|
283
|
+
handler->cdataBlock = cdata_block;
|
284
|
+
handler->processingInstruction = processing_instruction;
|
285
|
+
handler->initialized = XML_SAX2_MAGIC;
|
286
|
+
|
287
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, handler);
|
288
|
+
}
|
289
|
+
|
290
|
+
void
|
291
|
+
noko_init_xml_sax_parser()
|
292
|
+
{
|
293
|
+
cNokogiriXmlSaxParser = rb_define_class_under(mNokogiriXmlSax, "Parser", rb_cObject);
|
294
|
+
|
295
|
+
rb_define_alloc_func(cNokogiriXmlSaxParser, allocate);
|
296
|
+
|
297
|
+
id_start_document = rb_intern("start_document");
|
298
|
+
id_end_document = rb_intern("end_document");
|
299
|
+
id_start_element = rb_intern("start_element");
|
300
|
+
id_end_element = rb_intern("end_element");
|
301
|
+
id_comment = rb_intern("comment");
|
302
|
+
id_characters = rb_intern("characters");
|
303
|
+
id_xmldecl = rb_intern("xmldecl");
|
304
|
+
id_error = rb_intern("error");
|
305
|
+
id_warning = rb_intern("warning");
|
306
|
+
id_cdata_block = rb_intern("cdata_block");
|
307
|
+
id_start_element_namespace = rb_intern("start_element_namespace");
|
308
|
+
id_end_element_namespace = rb_intern("end_element_namespace");
|
309
|
+
id_processing_instruction = rb_intern("processing_instruction");
|
310
|
+
}
|