nokogiri 1.18.0.rc1-arm-linux-musl
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +38 -0
- data/LICENSE-DEPENDENCIES.md +2224 -0
- data/LICENSE.md +9 -0
- data/README.md +293 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +42 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1173 -0
- data/ext/nokogiri/gumbo.c +610 -0
- data/ext/nokogiri/html4_document.c +171 -0
- data/ext/nokogiri/html4_element_description.c +299 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser.c +40 -0
- data/ext/nokogiri/html4_sax_parser_context.c +98 -0
- data/ext/nokogiri/html4_sax_push_parser.c +96 -0
- data/ext/nokogiri/include/libexslt/exslt.h +108 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +63 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +336 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +171 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +115 -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 +82 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +244 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +166 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +41 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +251 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +186 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +98 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1390 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +671 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +106 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +219 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +959 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +143 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +87 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1382 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +106 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +477 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +136 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +438 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +962 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +188 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +436 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +215 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +102 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +249 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +152 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +366 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +347 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +489 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +579 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +633 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +138 -0
- data/ext/nokogiri/include/libxslt/attributes.h +39 -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 +1995 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +146 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +44 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +343 -0
- data/ext/nokogiri/libxml2_polyfill.c +114 -0
- data/ext/nokogiri/nokogiri.c +294 -0
- data/ext/nokogiri/nokogiri.h +238 -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 +62 -0
- data/ext/nokogiri/xml_comment.c +57 -0
- data/ext/nokogiri/xml_document.c +784 -0
- data/ext/nokogiri/xml_document_fragment.c +29 -0
- data/ext/nokogiri/xml_dtd.c +208 -0
- data/ext/nokogiri/xml_element_content.c +131 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_encoding_handler.c +112 -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 +181 -0
- data/ext/nokogiri/xml_node.c +2459 -0
- data/ext/nokogiri/xml_node_set.c +518 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +777 -0
- data/ext/nokogiri/xml_relax_ng.c +149 -0
- data/ext/nokogiri/xml_sax_parser.c +403 -0
- data/ext/nokogiri/xml_sax_parser_context.c +390 -0
- data/ext/nokogiri/xml_sax_push_parser.c +206 -0
- data/ext/nokogiri/xml_schema.c +226 -0
- data/ext/nokogiri/xml_syntax_error.c +93 -0
- data/ext/nokogiri/xml_text.c +59 -0
- data/ext/nokogiri/xml_xpath_context.c +502 -0
- data/ext/nokogiri/xslt_stylesheet.c +421 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +129 -0
- data/gumbo-parser/THANKS +27 -0
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/3.2/nokogiri.so +0 -0
- data/lib/nokogiri/3.3/nokogiri.so +0 -0
- data/lib/nokogiri/3.4/nokogiri.so +0 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +58 -0
- data/lib/nokogiri/css/parser.rb +772 -0
- data/lib/nokogiri/css/parser.y +277 -0
- data/lib/nokogiri/css/parser_extras.rb +36 -0
- data/lib/nokogiri/css/selector_cache.rb +38 -0
- data/lib/nokogiri/css/syntax_error.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rb +155 -0
- data/lib/nokogiri/css/tokenizer.rex +57 -0
- data/lib/nokogiri/css/xpath_visitor.rb +375 -0
- data/lib/nokogiri/css.rb +132 -0
- data/lib/nokogiri/decorators/slop.rb +42 -0
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +32 -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 +235 -0
- data/lib/nokogiri/html4/document_fragment.rb +166 -0
- data/lib/nokogiri/html4/element_description.rb +25 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +2040 -0
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4/entity_lookup.rb +15 -0
- data/lib/nokogiri/html4/sax/parser.rb +48 -0
- data/lib/nokogiri/html4/sax/parser_context.rb +15 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +42 -0
- data/lib/nokogiri/html5/builder.rb +40 -0
- data/lib/nokogiri/html5/document.rb +199 -0
- data/lib/nokogiri/html5/document_fragment.rb +200 -0
- data/lib/nokogiri/html5/node.rb +103 -0
- data/lib/nokogiri/html5.rb +368 -0
- data/lib/nokogiri/jruby/dependencies.rb +3 -0
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +6 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +224 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +66 -0
- data/lib/nokogiri/xml/attribute_decl.rb +22 -0
- data/lib/nokogiri/xml/builder.rb +494 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +514 -0
- data/lib/nokogiri/xml/document_fragment.rb +276 -0
- data/lib/nokogiri/xml/dtd.rb +34 -0
- data/lib/nokogiri/xml/element_content.rb +46 -0
- data/lib/nokogiri/xml/element_decl.rb +17 -0
- data/lib/nokogiri/xml/entity_decl.rb +23 -0
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +57 -0
- data/lib/nokogiri/xml/node/save_options.rb +76 -0
- data/lib/nokogiri/xml/node.rb +1650 -0
- data/lib/nokogiri/xml/node_set.rb +449 -0
- data/lib/nokogiri/xml/notation.rb +19 -0
- data/lib/nokogiri/xml/parse_options.rb +213 -0
- data/lib/nokogiri/xml/pp/character_data.rb +21 -0
- data/lib/nokogiri/xml/pp/node.rb +73 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +11 -0
- data/lib/nokogiri/xml/reader.rb +139 -0
- data/lib/nokogiri/xml/relax_ng.rb +75 -0
- data/lib/nokogiri/xml/sax/document.rb +258 -0
- data/lib/nokogiri/xml/sax/parser.rb +199 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +129 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +64 -0
- data/lib/nokogiri/xml/sax.rb +54 -0
- data/lib/nokogiri/xml/schema.rb +140 -0
- data/lib/nokogiri/xml/searchable.rb +297 -0
- data/lib/nokogiri/xml/syntax_error.rb +94 -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 +49 -0
- data/lib/nokogiri/xml.rb +65 -0
- data/lib/nokogiri/xslt/stylesheet.rb +49 -0
- data/lib/nokogiri/xslt.rb +129 -0
- data/lib/nokogiri.rb +128 -0
- data/lib/xsd/xmlparser/nokogiri.rb +105 -0
- metadata +324 -0
@@ -0,0 +1,226 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSchema;
|
4
|
+
|
5
|
+
static void
|
6
|
+
xml_schema_deallocate(void *data)
|
7
|
+
{
|
8
|
+
xmlSchemaPtr schema = data;
|
9
|
+
xmlSchemaFree(schema);
|
10
|
+
}
|
11
|
+
|
12
|
+
static const rb_data_type_t xml_schema_type = {
|
13
|
+
.wrap_struct_name = "xmlSchema",
|
14
|
+
.function = {
|
15
|
+
.dfree = xml_schema_deallocate,
|
16
|
+
},
|
17
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
18
|
+
};
|
19
|
+
|
20
|
+
static VALUE
|
21
|
+
noko_xml_schema__validate_document(VALUE self, VALUE document)
|
22
|
+
{
|
23
|
+
xmlDocPtr doc;
|
24
|
+
xmlSchemaPtr schema;
|
25
|
+
xmlSchemaValidCtxtPtr valid_ctxt;
|
26
|
+
VALUE errors;
|
27
|
+
|
28
|
+
TypedData_Get_Struct(self, xmlSchema, &xml_schema_type, schema);
|
29
|
+
doc = noko_xml_document_unwrap(document);
|
30
|
+
|
31
|
+
errors = rb_ary_new();
|
32
|
+
|
33
|
+
valid_ctxt = xmlSchemaNewValidCtxt(schema);
|
34
|
+
|
35
|
+
if (NULL == valid_ctxt) {
|
36
|
+
/* we have a problem */
|
37
|
+
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
38
|
+
}
|
39
|
+
|
40
|
+
xmlSchemaSetValidStructuredErrors(
|
41
|
+
valid_ctxt,
|
42
|
+
noko__error_array_pusher,
|
43
|
+
(void *)errors
|
44
|
+
);
|
45
|
+
|
46
|
+
int status = xmlSchemaValidateDoc(valid_ctxt, doc);
|
47
|
+
|
48
|
+
xmlSchemaFreeValidCtxt(valid_ctxt);
|
49
|
+
|
50
|
+
if (status != 0) {
|
51
|
+
if (RARRAY_LEN(errors) == 0) {
|
52
|
+
rb_ary_push(errors, rb_str_new2("Could not validate document"));
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return errors;
|
57
|
+
}
|
58
|
+
|
59
|
+
static VALUE
|
60
|
+
noko_xml_schema__validate_file(VALUE self, VALUE rb_filename)
|
61
|
+
{
|
62
|
+
xmlSchemaPtr schema;
|
63
|
+
xmlSchemaValidCtxtPtr valid_ctxt;
|
64
|
+
const char *filename ;
|
65
|
+
VALUE errors;
|
66
|
+
|
67
|
+
TypedData_Get_Struct(self, xmlSchema, &xml_schema_type, schema);
|
68
|
+
filename = (const char *)StringValueCStr(rb_filename) ;
|
69
|
+
|
70
|
+
errors = rb_ary_new();
|
71
|
+
|
72
|
+
valid_ctxt = xmlSchemaNewValidCtxt(schema);
|
73
|
+
|
74
|
+
if (NULL == valid_ctxt) {
|
75
|
+
/* we have a problem */
|
76
|
+
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
77
|
+
}
|
78
|
+
|
79
|
+
xmlSchemaSetValidStructuredErrors(
|
80
|
+
valid_ctxt,
|
81
|
+
noko__error_array_pusher,
|
82
|
+
(void *)errors
|
83
|
+
);
|
84
|
+
|
85
|
+
int status = xmlSchemaValidateFile(valid_ctxt, filename, 0);
|
86
|
+
|
87
|
+
xmlSchemaFreeValidCtxt(valid_ctxt);
|
88
|
+
|
89
|
+
if (status != 0) {
|
90
|
+
if (RARRAY_LEN(errors) == 0) {
|
91
|
+
rb_ary_push(errors, rb_str_new2("Could not validate file."));
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
return errors;
|
96
|
+
}
|
97
|
+
|
98
|
+
static VALUE
|
99
|
+
xml_schema_parse_schema(
|
100
|
+
VALUE rb_class,
|
101
|
+
xmlSchemaParserCtxtPtr c_parser_context,
|
102
|
+
VALUE rb_parse_options
|
103
|
+
)
|
104
|
+
{
|
105
|
+
xmlExternalEntityLoader saved_loader = 0;
|
106
|
+
libxmlStructuredErrorHandlerState handler_state;
|
107
|
+
|
108
|
+
if (NIL_P(rb_parse_options)) {
|
109
|
+
rb_parse_options = rb_const_get_at(
|
110
|
+
rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")),
|
111
|
+
rb_intern("DEFAULT_SCHEMA")
|
112
|
+
);
|
113
|
+
}
|
114
|
+
int c_parse_options = (int)NUM2INT(rb_funcall(rb_parse_options, rb_intern("to_i"), 0));
|
115
|
+
|
116
|
+
VALUE rb_errors = rb_ary_new();
|
117
|
+
noko__structured_error_func_save_and_set(&handler_state, (void *)rb_errors, noko__error_array_pusher);
|
118
|
+
|
119
|
+
xmlSchemaSetParserStructuredErrors(
|
120
|
+
c_parser_context,
|
121
|
+
noko__error_array_pusher,
|
122
|
+
(void *)rb_errors
|
123
|
+
);
|
124
|
+
|
125
|
+
if (c_parse_options & XML_PARSE_NONET) {
|
126
|
+
saved_loader = xmlGetExternalEntityLoader();
|
127
|
+
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
|
128
|
+
}
|
129
|
+
|
130
|
+
xmlSchemaPtr c_schema = xmlSchemaParse(c_parser_context);
|
131
|
+
|
132
|
+
if (saved_loader) {
|
133
|
+
xmlSetExternalEntityLoader(saved_loader);
|
134
|
+
}
|
135
|
+
|
136
|
+
xmlSchemaFreeParserCtxt(c_parser_context);
|
137
|
+
noko__structured_error_func_restore(&handler_state);
|
138
|
+
|
139
|
+
if (NULL == c_schema) {
|
140
|
+
VALUE exception = rb_funcall(cNokogiriXmlSyntaxError, rb_intern("aggregate"), 1, rb_errors);
|
141
|
+
if (RB_TEST(exception)) {
|
142
|
+
rb_exc_raise(exception);
|
143
|
+
} else {
|
144
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
VALUE rb_schema = TypedData_Wrap_Struct(rb_class, &xml_schema_type, c_schema);
|
149
|
+
rb_iv_set(rb_schema, "@errors", rb_errors);
|
150
|
+
rb_iv_set(rb_schema, "@parse_options", rb_parse_options);
|
151
|
+
|
152
|
+
return rb_schema;
|
153
|
+
}
|
154
|
+
|
155
|
+
/*
|
156
|
+
* :call-seq:
|
157
|
+
* from_document(input) → Nokogiri::XML::Schema
|
158
|
+
* from_document(input, parse_options) → Nokogiri::XML::Schema
|
159
|
+
*
|
160
|
+
* Parse an \XSD schema definition from a Document to create a new Nokogiri::XML::Schema
|
161
|
+
*
|
162
|
+
* [Parameters]
|
163
|
+
* - +input+ (XML::Document) A document containing the \XSD schema definition
|
164
|
+
* - +parse_options+ (Nokogiri::XML::ParseOptions)
|
165
|
+
* Defaults to Nokogiri::XML::ParseOptions::DEFAULT_SCHEMA
|
166
|
+
*
|
167
|
+
* [Returns] Nokogiri::XML::Schema
|
168
|
+
*/
|
169
|
+
static VALUE
|
170
|
+
noko_xml_schema_s_from_document(int argc, VALUE *argv, VALUE rb_class)
|
171
|
+
{
|
172
|
+
/* TODO: deprecate this method and put file-or-string logic into .new so that becomes the
|
173
|
+
* preferred entry point, and this can become a private method */
|
174
|
+
VALUE rb_document;
|
175
|
+
VALUE rb_parse_options;
|
176
|
+
VALUE rb_schema;
|
177
|
+
xmlDocPtr c_document;
|
178
|
+
xmlSchemaParserCtxtPtr c_parser_context;
|
179
|
+
int defensive_copy_p = 0;
|
180
|
+
|
181
|
+
rb_scan_args(argc, argv, "11", &rb_document, &rb_parse_options);
|
182
|
+
|
183
|
+
if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlNode)) {
|
184
|
+
rb_raise(rb_eTypeError,
|
185
|
+
"expected parameter to be a Nokogiri::XML::Document, received %"PRIsVALUE,
|
186
|
+
rb_obj_class(rb_document));
|
187
|
+
}
|
188
|
+
|
189
|
+
if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
|
190
|
+
xmlNodePtr deprecated_node_type_arg;
|
191
|
+
NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
|
192
|
+
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
|
193
|
+
c_document = deprecated_node_type_arg->doc;
|
194
|
+
} else {
|
195
|
+
c_document = noko_xml_document_unwrap(rb_document);
|
196
|
+
}
|
197
|
+
|
198
|
+
if (noko_xml_document_has_wrapped_blank_nodes_p(c_document)) {
|
199
|
+
// see https://github.com/sparklemotion/nokogiri/pull/2001
|
200
|
+
c_document = xmlCopyDoc(c_document, 1);
|
201
|
+
defensive_copy_p = 1;
|
202
|
+
}
|
203
|
+
|
204
|
+
c_parser_context = xmlSchemaNewDocParserCtxt(c_document);
|
205
|
+
rb_schema = xml_schema_parse_schema(rb_class, c_parser_context, rb_parse_options);
|
206
|
+
|
207
|
+
if (defensive_copy_p) {
|
208
|
+
xmlFreeDoc(c_document);
|
209
|
+
c_document = NULL;
|
210
|
+
}
|
211
|
+
|
212
|
+
return rb_schema;
|
213
|
+
}
|
214
|
+
|
215
|
+
void
|
216
|
+
noko_init_xml_schema(void)
|
217
|
+
{
|
218
|
+
cNokogiriXmlSchema = rb_define_class_under(mNokogiriXml, "Schema", rb_cObject);
|
219
|
+
|
220
|
+
rb_undef_alloc_func(cNokogiriXmlSchema);
|
221
|
+
|
222
|
+
rb_define_singleton_method(cNokogiriXmlSchema, "from_document", noko_xml_schema_s_from_document, -1);
|
223
|
+
|
224
|
+
rb_define_private_method(cNokogiriXmlSchema, "validate_document", noko_xml_schema__validate_document, 1);
|
225
|
+
rb_define_private_method(cNokogiriXmlSchema, "validate_file", noko_xml_schema__validate_file, 1);
|
226
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSyntaxError;
|
4
|
+
|
5
|
+
void
|
6
|
+
noko__structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state)
|
7
|
+
{
|
8
|
+
/* this method is tightly coupled to the implementation of xmlSetStructuredErrorFunc */
|
9
|
+
handler_state->user_data = xmlStructuredErrorContext;
|
10
|
+
handler_state->handler = xmlStructuredError;
|
11
|
+
}
|
12
|
+
|
13
|
+
void
|
14
|
+
noko__structured_error_func_save_and_set(
|
15
|
+
libxmlStructuredErrorHandlerState *handler_state,
|
16
|
+
void *user_data,
|
17
|
+
xmlStructuredErrorFunc handler
|
18
|
+
)
|
19
|
+
{
|
20
|
+
noko__structured_error_func_save(handler_state);
|
21
|
+
xmlSetStructuredErrorFunc(user_data, handler);
|
22
|
+
}
|
23
|
+
|
24
|
+
void
|
25
|
+
noko__structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state)
|
26
|
+
{
|
27
|
+
xmlSetStructuredErrorFunc(handler_state->user_data, handler_state->handler);
|
28
|
+
}
|
29
|
+
|
30
|
+
void
|
31
|
+
noko__error_array_pusher(void *ctx, xmlErrorConstPtr error)
|
32
|
+
{
|
33
|
+
VALUE list = (VALUE)ctx;
|
34
|
+
Check_Type(list, T_ARRAY);
|
35
|
+
rb_ary_push(list, noko_xml_syntax_error__wrap(error));
|
36
|
+
}
|
37
|
+
|
38
|
+
void
|
39
|
+
noko__error_raise(void *ctx, xmlErrorConstPtr error)
|
40
|
+
{
|
41
|
+
rb_exc_raise(noko_xml_syntax_error__wrap(error));
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE
|
45
|
+
noko_xml_syntax_error__wrap(xmlErrorConstPtr error)
|
46
|
+
{
|
47
|
+
xmlChar *c_path ;
|
48
|
+
VALUE msg, e, klass;
|
49
|
+
|
50
|
+
klass = cNokogiriXmlSyntaxError;
|
51
|
+
|
52
|
+
if (error && error->domain == XML_FROM_XPATH) {
|
53
|
+
klass = cNokogiriXmlXpathSyntaxError;
|
54
|
+
}
|
55
|
+
|
56
|
+
msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
|
57
|
+
|
58
|
+
e = rb_class_new_instance(
|
59
|
+
1,
|
60
|
+
&msg,
|
61
|
+
klass
|
62
|
+
);
|
63
|
+
|
64
|
+
if (error) {
|
65
|
+
c_path = xmlGetNodePath(error->node);
|
66
|
+
|
67
|
+
rb_iv_set(e, "@domain", INT2NUM(error->domain));
|
68
|
+
rb_iv_set(e, "@code", INT2NUM(error->code));
|
69
|
+
rb_iv_set(e, "@level", INT2NUM((short)error->level));
|
70
|
+
rb_iv_set(e, "@file", RBSTR_OR_QNIL(error->file));
|
71
|
+
rb_iv_set(e, "@line", INT2NUM(error->line));
|
72
|
+
rb_iv_set(e, "@path", RBSTR_OR_QNIL(c_path));
|
73
|
+
rb_iv_set(e, "@str1", RBSTR_OR_QNIL(error->str1));
|
74
|
+
rb_iv_set(e, "@str2", RBSTR_OR_QNIL(error->str2));
|
75
|
+
rb_iv_set(e, "@str3", RBSTR_OR_QNIL(error->str3));
|
76
|
+
rb_iv_set(e, "@int1", INT2NUM(error->int1));
|
77
|
+
rb_iv_set(e, "@column", INT2NUM(error->int2));
|
78
|
+
|
79
|
+
xmlFree(c_path);
|
80
|
+
}
|
81
|
+
|
82
|
+
return e;
|
83
|
+
}
|
84
|
+
|
85
|
+
void
|
86
|
+
noko_init_xml_syntax_error(void)
|
87
|
+
{
|
88
|
+
assert(cNokogiriSyntaxError);
|
89
|
+
/*
|
90
|
+
* The XML::SyntaxError is raised on parse errors
|
91
|
+
*/
|
92
|
+
cNokogiriXmlSyntaxError = rb_define_class_under(mNokogiriXml, "SyntaxError", cNokogiriSyntaxError);
|
93
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlText ;
|
4
|
+
|
5
|
+
/*
|
6
|
+
* call-seq:
|
7
|
+
* new(content, document)
|
8
|
+
*
|
9
|
+
* Create a new Text element on the +document+ with +content+
|
10
|
+
*/
|
11
|
+
static VALUE
|
12
|
+
rb_xml_text_s_new(int argc, VALUE *argv, VALUE klass)
|
13
|
+
{
|
14
|
+
xmlDocPtr c_document;
|
15
|
+
xmlNodePtr c_node;
|
16
|
+
VALUE rb_string;
|
17
|
+
VALUE rb_document;
|
18
|
+
VALUE rb_rest;
|
19
|
+
VALUE rb_node;
|
20
|
+
|
21
|
+
rb_scan_args(argc, argv, "2*", &rb_string, &rb_document, &rb_rest);
|
22
|
+
|
23
|
+
Check_Type(rb_string, T_STRING);
|
24
|
+
if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlNode)) {
|
25
|
+
rb_raise(rb_eTypeError,
|
26
|
+
"expected second parameter to be a Nokogiri::XML::Document, received %"PRIsVALUE,
|
27
|
+
rb_obj_class(rb_document));
|
28
|
+
}
|
29
|
+
|
30
|
+
if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
|
31
|
+
xmlNodePtr deprecated_node_type_arg;
|
32
|
+
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
|
33
|
+
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
|
34
|
+
c_document = deprecated_node_type_arg->doc;
|
35
|
+
} else {
|
36
|
+
c_document = noko_xml_document_unwrap(rb_document);
|
37
|
+
}
|
38
|
+
|
39
|
+
c_node = xmlNewDocText(c_document, (xmlChar *)StringValueCStr(rb_string));
|
40
|
+
noko_xml_document_pin_node(c_node);
|
41
|
+
rb_node = noko_xml_node_wrap(klass, c_node) ;
|
42
|
+
rb_obj_call_init(rb_node, argc, argv);
|
43
|
+
|
44
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
45
|
+
|
46
|
+
return rb_node;
|
47
|
+
}
|
48
|
+
|
49
|
+
void
|
50
|
+
noko_init_xml_text(void)
|
51
|
+
{
|
52
|
+
assert(cNokogiriXmlCharacterData);
|
53
|
+
/*
|
54
|
+
* Wraps Text nodes.
|
55
|
+
*/
|
56
|
+
cNokogiriXmlText = rb_define_class_under(mNokogiriXml, "Text", cNokogiriXmlCharacterData);
|
57
|
+
|
58
|
+
rb_define_singleton_method(cNokogiriXmlText, "new", rb_xml_text_s_new, -1);
|
59
|
+
}
|