nokogiri 1.4.1 → 1.4.2
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.
- data/CHANGELOG.ja.rdoc +45 -0
- data/CHANGELOG.rdoc +53 -1
- data/Manifest.txt +3 -3
- data/README.ja.rdoc +1 -1
- data/README.rdoc +11 -5
- data/Rakefile +13 -79
- data/ext/nokogiri/extconf.rb +22 -74
- data/ext/nokogiri/html_document.c +17 -8
- data/ext/nokogiri/html_element_description.c +20 -16
- data/ext/nokogiri/html_entity_lookup.c +2 -2
- data/ext/nokogiri/html_sax_parser_context.c +10 -8
- data/ext/nokogiri/nokogiri.c +0 -1
- data/ext/nokogiri/nokogiri.h +33 -28
- data/ext/nokogiri/xml_attr.c +7 -5
- data/ext/nokogiri/xml_attribute_decl.c +5 -2
- data/ext/nokogiri/xml_cdata.c +4 -2
- data/ext/nokogiri/xml_comment.c +4 -2
- data/ext/nokogiri/xml_document.c +93 -15
- data/ext/nokogiri/xml_document.h +0 -1
- data/ext/nokogiri/xml_document_fragment.c +4 -2
- data/ext/nokogiri/xml_dtd.c +18 -8
- data/ext/nokogiri/xml_element_content.c +2 -2
- data/ext/nokogiri/xml_entity_decl.c +15 -2
- data/ext/nokogiri/xml_entity_reference.c +4 -2
- data/ext/nokogiri/xml_io.c +1 -1
- data/ext/nokogiri/xml_namespace.c +5 -3
- data/ext/nokogiri/xml_node.c +353 -114
- data/ext/nokogiri/xml_node_set.c +35 -22
- data/ext/nokogiri/xml_node_set.h +1 -1
- data/ext/nokogiri/xml_processing_instruction.c +4 -2
- data/ext/nokogiri/xml_reader.c +119 -47
- data/ext/nokogiri/xml_relax_ng.c +21 -12
- data/ext/nokogiri/xml_sax_parser.c +6 -3
- data/ext/nokogiri/xml_sax_parser.h +13 -17
- data/ext/nokogiri/xml_sax_parser_context.c +8 -6
- data/ext/nokogiri/xml_sax_push_parser.c +7 -6
- data/ext/nokogiri/xml_schema.c +62 -13
- data/ext/nokogiri/xml_syntax_error.c +18 -12
- data/ext/nokogiri/xml_syntax_error.h +1 -1
- data/ext/nokogiri/xml_text.c +4 -2
- data/ext/nokogiri/xml_xpath_context.c +60 -23
- data/ext/nokogiri/xslt_stylesheet.c +14 -3
- data/lib/nokogiri.rb +17 -0
- data/lib/nokogiri/css/generated_parser.rb +72 -62
- data/lib/nokogiri/css/generated_tokenizer.rb +23 -24
- data/lib/nokogiri/css/parser.y +3 -1
- data/lib/nokogiri/css/tokenizer.rex +3 -3
- data/lib/nokogiri/css/xpath_visitor.rb +8 -3
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +3 -3
- data/lib/nokogiri/ffi/libxml.rb +16 -2
- data/lib/nokogiri/ffi/structs/common_node.rb +15 -3
- data/lib/nokogiri/ffi/structs/xml_document.rb +13 -4
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +3 -2
- data/lib/nokogiri/ffi/weak_bucket.rb +40 -0
- data/lib/nokogiri/ffi/xml/document.rb +27 -0
- data/lib/nokogiri/ffi/xml/entity_decl.rb +9 -0
- data/lib/nokogiri/ffi/xml/node.rb +142 -61
- data/lib/nokogiri/ffi/xml/node_set.rb +15 -12
- data/lib/nokogiri/ffi/xml/reader.rb +5 -0
- data/lib/nokogiri/ffi/xml/schema.rb +17 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +4 -4
- data/lib/nokogiri/ffi/xml/xpath.rb +0 -10
- data/lib/nokogiri/ffi/xml/xpath_context.rb +22 -9
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +3 -0
- data/lib/nokogiri/html/document.rb +5 -3
- data/lib/nokogiri/html/document_fragment.rb +28 -7
- data/lib/nokogiri/version.rb +6 -2
- data/lib/nokogiri/version_warning.rb +6 -3
- data/lib/nokogiri/xml.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +35 -22
- data/lib/nokogiri/xml/document.rb +44 -12
- data/lib/nokogiri/xml/document_fragment.rb +16 -12
- data/lib/nokogiri/xml/entity_decl.rb +4 -0
- data/lib/nokogiri/xml/node.rb +152 -95
- data/lib/nokogiri/xml/node_set.rb +2 -1
- data/lib/nokogiri/xml/sax/push_parser.rb +1 -1
- data/lib/nokogiri/xml/schema.rb +1 -5
- data/lib/nokogiri/xml/syntax_error.rb +4 -0
- data/lib/nokogiri/xml/text.rb +9 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +3 -0
- data/tasks/cross_compile.rb +158 -0
- data/tasks/test.rb +0 -6
- data/test/css/test_xpath_visitor.rb +9 -0
- data/test/helper.rb +49 -11
- data/test/html/sax/test_parser.rb +11 -1
- data/test/html/test_document.rb +8 -0
- data/test/html/test_document_fragment.rb +14 -2
- data/test/html/test_element_description.rb +5 -1
- data/test/html/test_node.rb +5 -66
- data/test/test_reader.rb +28 -0
- data/test/test_xslt_transforms.rb +14 -0
- data/test/xml/test_builder.rb +43 -0
- data/test/xml/test_cdata.rb +12 -0
- data/test/xml/test_document.rb +74 -39
- data/test/xml/test_document_fragment.rb +36 -0
- data/test/xml/test_entity_decl.rb +37 -0
- data/test/xml/test_node.rb +192 -65
- data/test/xml/test_node_reparenting.rb +253 -236
- data/test/xml/test_node_set.rb +67 -0
- data/test/xml/test_text.rb +8 -0
- data/test/xml/test_xpath.rb +32 -0
- metadata +103 -48
- data.tar.gz.sig +0 -0
- data/ext/nokogiri/xml_xpath.c +0 -53
- data/ext/nokogiri/xml_xpath.h +0 -11
- data/lib/nokogiri/xml/fragment_handler.rb +0 -79
- metadata.gz.sig +0 -0
data/ext/nokogiri/xml_document.c
CHANGED
@@ -6,6 +6,9 @@ static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
|
6
6
|
case XML_ATTRIBUTE_NODE:
|
7
7
|
xmlFreePropList((xmlAttrPtr)node);
|
8
8
|
break;
|
9
|
+
case XML_NAMESPACE_DECL:
|
10
|
+
xmlFree(node);
|
11
|
+
break;
|
9
12
|
default:
|
10
13
|
if(node->parent == NULL) {
|
11
14
|
xmlAddChild((xmlNodePtr)doc, node);
|
@@ -16,11 +19,13 @@ static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
|
16
19
|
|
17
20
|
static void dealloc(xmlDocPtr doc)
|
18
21
|
{
|
19
|
-
|
22
|
+
xmlDeregisterNodeFunc func;
|
23
|
+
st_table *node_hash;
|
20
24
|
|
21
|
-
|
25
|
+
NOKOGIRI_DEBUG_START(doc);
|
26
|
+
func = xmlDeregisterNodeDefault(NULL);
|
22
27
|
|
23
|
-
|
28
|
+
node_hash = DOC_UNLINKED_NODE_HASH(doc);
|
24
29
|
|
25
30
|
st_foreach(node_hash, dealloc_node_i, (st_data_t)doc);
|
26
31
|
st_free_table(node_hash);
|
@@ -30,7 +35,6 @@ static void dealloc(xmlDocPtr doc)
|
|
30
35
|
xmlFreeDoc(doc);
|
31
36
|
|
32
37
|
xmlDeregisterNodeDefault(func);
|
33
|
-
|
34
38
|
NOKOGIRI_DEBUG_END(doc);
|
35
39
|
}
|
36
40
|
|
@@ -70,11 +74,25 @@ static VALUE set_root(VALUE self, VALUE root)
|
|
70
74
|
{
|
71
75
|
xmlDocPtr doc;
|
72
76
|
xmlNodePtr new_root;
|
77
|
+
xmlNodePtr old_root;
|
73
78
|
|
74
79
|
Data_Get_Struct(self, xmlDoc, doc);
|
80
|
+
|
81
|
+
old_root = NULL;
|
82
|
+
|
83
|
+
if(NIL_P(root)) {
|
84
|
+
old_root = xmlDocGetRootElement(doc);
|
85
|
+
|
86
|
+
if(old_root) {
|
87
|
+
xmlUnlinkNode(old_root);
|
88
|
+
NOKOGIRI_ROOT_NODE(old_root);
|
89
|
+
}
|
90
|
+
|
91
|
+
return root;
|
92
|
+
}
|
93
|
+
|
75
94
|
Data_Get_Struct(root, xmlNode, new_root);
|
76
95
|
|
77
|
-
xmlNodePtr old_root = NULL;
|
78
96
|
|
79
97
|
/* If the new root's document is not the same as the current document,
|
80
98
|
* then we need to dup the node in to this document. */
|
@@ -99,9 +117,11 @@ static VALUE set_root(VALUE self, VALUE root)
|
|
99
117
|
static VALUE root(VALUE self)
|
100
118
|
{
|
101
119
|
xmlDocPtr doc;
|
120
|
+
xmlNodePtr root;
|
121
|
+
|
102
122
|
Data_Get_Struct(self, xmlDoc, doc);
|
103
123
|
|
104
|
-
|
124
|
+
root = xmlDocGetRootElement(doc);
|
105
125
|
|
106
126
|
if(!root) return Qnil;
|
107
127
|
return Nokogiri_wrap_xml_node(Qnil, root) ;
|
@@ -168,11 +188,13 @@ static VALUE read_io( VALUE klass,
|
|
168
188
|
const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url);
|
169
189
|
const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
|
170
190
|
VALUE error_list = rb_ary_new();
|
191
|
+
VALUE document;
|
192
|
+
xmlDocPtr doc;
|
171
193
|
|
172
194
|
xmlResetLastError();
|
173
195
|
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
174
196
|
|
175
|
-
|
197
|
+
doc = xmlReadIO(
|
176
198
|
(xmlInputReadCallback)io_read_callback,
|
177
199
|
(xmlInputCloseCallback)io_close_callback,
|
178
200
|
(void *)io,
|
@@ -183,9 +205,11 @@ static VALUE read_io( VALUE klass,
|
|
183
205
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
184
206
|
|
185
207
|
if(doc == NULL) {
|
208
|
+
xmlErrorPtr error;
|
209
|
+
|
186
210
|
xmlFreeDoc(doc);
|
187
211
|
|
188
|
-
|
212
|
+
error = xmlGetLastError();
|
189
213
|
if(error)
|
190
214
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
|
191
215
|
else
|
@@ -194,7 +218,7 @@ static VALUE read_io( VALUE klass,
|
|
194
218
|
return Qnil;
|
195
219
|
}
|
196
220
|
|
197
|
-
|
221
|
+
document = Nokogiri_wrap_xml_document(klass, doc);
|
198
222
|
rb_iv_set(document, "@errors", error_list);
|
199
223
|
return document;
|
200
224
|
}
|
@@ -214,18 +238,22 @@ static VALUE read_memory( VALUE klass,
|
|
214
238
|
const char * c_buffer = StringValuePtr(string);
|
215
239
|
const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url);
|
216
240
|
const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
|
217
|
-
int len = RSTRING_LEN(string);
|
241
|
+
int len = (int)RSTRING_LEN(string);
|
218
242
|
VALUE error_list = rb_ary_new();
|
243
|
+
VALUE document;
|
244
|
+
xmlDocPtr doc;
|
219
245
|
|
220
246
|
xmlResetLastError();
|
221
247
|
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
222
|
-
|
248
|
+
doc = xmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
|
223
249
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
224
250
|
|
225
251
|
if(doc == NULL) {
|
252
|
+
xmlErrorPtr error;
|
253
|
+
|
226
254
|
xmlFreeDoc(doc);
|
227
255
|
|
228
|
-
|
256
|
+
error = xmlGetLastError();
|
229
257
|
if(error)
|
230
258
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
|
231
259
|
else
|
@@ -234,7 +262,7 @@ static VALUE read_memory( VALUE klass,
|
|
234
262
|
return Qnil;
|
235
263
|
}
|
236
264
|
|
237
|
-
|
265
|
+
document = Nokogiri_wrap_xml_document(klass, doc);
|
238
266
|
rb_iv_set(document, "@errors", error_list);
|
239
267
|
return document;
|
240
268
|
}
|
@@ -248,12 +276,12 @@ static VALUE read_memory( VALUE klass,
|
|
248
276
|
*/
|
249
277
|
static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
|
250
278
|
{
|
279
|
+
xmlDocPtr doc, dup;
|
251
280
|
VALUE level;
|
252
281
|
|
253
282
|
if(rb_scan_args(argc, argv, "01", &level) == 0)
|
254
283
|
level = INT2NUM((long)1);
|
255
284
|
|
256
|
-
xmlDocPtr doc, dup;
|
257
285
|
Data_Get_Struct(self, xmlDoc, doc);
|
258
286
|
|
259
287
|
dup = xmlCopyDoc(doc, (int)NUM2INT(level));
|
@@ -271,13 +299,14 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
|
|
271
299
|
*/
|
272
300
|
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
273
301
|
{
|
302
|
+
xmlDocPtr doc;
|
274
303
|
VALUE version, rest, rb_doc ;
|
275
304
|
|
276
305
|
rb_scan_args(argc, argv, "0*", &rest);
|
277
306
|
version = rb_ary_entry(rest, (long)0);
|
278
307
|
if (NIL_P(version)) version = rb_str_new2("1.0");
|
279
308
|
|
280
|
-
|
309
|
+
doc = xmlNewDoc((xmlChar *)StringValuePtr(version));
|
281
310
|
rb_doc = Nokogiri_wrap_xml_document(klass, doc);
|
282
311
|
rb_obj_call_init(rb_doc, argc, argv);
|
283
312
|
return rb_doc ;
|
@@ -329,6 +358,54 @@ VALUE remove_namespaces_bang(VALUE self)
|
|
329
358
|
return self;
|
330
359
|
}
|
331
360
|
|
361
|
+
/* call-seq: doc.create_entity(name, type, external_id, system_id, content)
|
362
|
+
*
|
363
|
+
* Create a new entity named +name+.
|
364
|
+
*
|
365
|
+
* +type+ is an integer representing the type of entity to be created, and it
|
366
|
+
* defaults to Nokogiri::XML::EntityDecl::INTERNAL_GENERAL. See
|
367
|
+
* the constants on Nokogiri::XML::EntityDecl for more information.
|
368
|
+
*
|
369
|
+
* +external_id+, +system_id+, and +content+ set the External ID, System ID,
|
370
|
+
* and content respectively. All of these parameters are optional.
|
371
|
+
*/
|
372
|
+
static VALUE create_entity(int argc, VALUE *argv, VALUE self)
|
373
|
+
{
|
374
|
+
VALUE name;
|
375
|
+
VALUE type;
|
376
|
+
VALUE external_id;
|
377
|
+
VALUE system_id;
|
378
|
+
VALUE content;
|
379
|
+
xmlEntityPtr ptr;
|
380
|
+
xmlDocPtr doc ;
|
381
|
+
|
382
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
383
|
+
|
384
|
+
rb_scan_args(argc, argv, "14", &name, &type, &external_id, &system_id,
|
385
|
+
&content);
|
386
|
+
|
387
|
+
xmlResetLastError();
|
388
|
+
ptr = xmlAddDocEntity(
|
389
|
+
doc,
|
390
|
+
(xmlChar *)(NIL_P(name) ? NULL : StringValuePtr(name)),
|
391
|
+
(int) (NIL_P(type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)),
|
392
|
+
(xmlChar *)(NIL_P(external_id) ? NULL : StringValuePtr(external_id)),
|
393
|
+
(xmlChar *)(NIL_P(system_id) ? NULL : StringValuePtr(system_id)),
|
394
|
+
(xmlChar *)(NIL_P(content) ? NULL : StringValuePtr(content))
|
395
|
+
);
|
396
|
+
|
397
|
+
if(NULL == ptr) {
|
398
|
+
xmlErrorPtr error = xmlGetLastError();
|
399
|
+
if(error)
|
400
|
+
rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
|
401
|
+
else
|
402
|
+
rb_raise(rb_eRuntimeError, "Could not create entity");
|
403
|
+
|
404
|
+
return Qnil;
|
405
|
+
}
|
406
|
+
|
407
|
+
return Nokogiri_wrap_xml_node(cNokogiriXmlEntityDecl, (xmlNodePtr)ptr);
|
408
|
+
}
|
332
409
|
|
333
410
|
VALUE cNokogiriXmlDocument ;
|
334
411
|
void init_xml_document()
|
@@ -355,6 +432,7 @@ void init_xml_document()
|
|
355
432
|
rb_define_method(klass, "version", version, 0);
|
356
433
|
rb_define_method(klass, "dup", duplicate_node, -1);
|
357
434
|
rb_define_method(klass, "url", url, 0);
|
435
|
+
rb_define_method(klass, "create_entity", create_entity, -1);
|
358
436
|
rb_define_method(klass, "remove_namespaces!", remove_namespaces_bang, 0);
|
359
437
|
}
|
360
438
|
|
data/ext/nokogiri/xml_document.h
CHANGED
@@ -9,18 +9,20 @@
|
|
9
9
|
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
10
10
|
{
|
11
11
|
xmlDocPtr xml_doc;
|
12
|
+
xmlNodePtr node;
|
12
13
|
VALUE document;
|
13
14
|
VALUE rest;
|
15
|
+
VALUE rb_node;
|
14
16
|
|
15
17
|
rb_scan_args(argc, argv, "1*", &document, &rest);
|
16
18
|
|
17
19
|
Data_Get_Struct(document, xmlDoc, xml_doc);
|
18
20
|
|
19
|
-
|
21
|
+
node = xmlNewDocFragment(xml_doc->doc);
|
20
22
|
|
21
23
|
NOKOGIRI_ROOT_NODE(node);
|
22
24
|
|
23
|
-
|
25
|
+
rb_node = Nokogiri_wrap_xml_node(klass, node);
|
24
26
|
rb_obj_call_init(rb_node, argc, argv);
|
25
27
|
|
26
28
|
if(rb_block_given_p()) rb_yield(rb_node);
|
data/ext/nokogiri/xml_dtd.c
CHANGED
@@ -6,13 +6,13 @@ static void notation_copier(void *payload, void *data, xmlChar *name)
|
|
6
6
|
VALUE klass = rb_const_get(mNokogiriXml, rb_intern("Notation"));
|
7
7
|
|
8
8
|
xmlNotationPtr c_notation = (xmlNotationPtr)payload;
|
9
|
-
|
9
|
+
VALUE notation;
|
10
10
|
VALUE argv[3];
|
11
11
|
argv[0] = (c_notation->name ? NOKOGIRI_STR_NEW2(c_notation->name) : Qnil);
|
12
12
|
argv[1] = (c_notation->PublicID ? NOKOGIRI_STR_NEW2(c_notation->PublicID) : Qnil);
|
13
13
|
argv[2] = (c_notation->SystemID ? NOKOGIRI_STR_NEW2(c_notation->SystemID) : Qnil);
|
14
14
|
|
15
|
-
|
15
|
+
notation = rb_class_new_instance(3, argv, klass);
|
16
16
|
|
17
17
|
rb_hash_aset(hash, NOKOGIRI_STR_NEW2(name),notation);
|
18
18
|
}
|
@@ -36,11 +36,13 @@ static void element_copier(void *_payload, void *data, xmlChar *name)
|
|
36
36
|
static VALUE entities(VALUE self)
|
37
37
|
{
|
38
38
|
xmlDtdPtr dtd;
|
39
|
+
VALUE hash;
|
40
|
+
|
39
41
|
Data_Get_Struct(self, xmlDtd, dtd);
|
40
42
|
|
41
43
|
if(!dtd->entities) return Qnil;
|
42
44
|
|
43
|
-
|
45
|
+
hash = rb_hash_new();
|
44
46
|
|
45
47
|
xmlHashScan((xmlHashTablePtr)dtd->entities, element_copier, (void *)hash);
|
46
48
|
|
@@ -56,11 +58,13 @@ static VALUE entities(VALUE self)
|
|
56
58
|
static VALUE notations(VALUE self)
|
57
59
|
{
|
58
60
|
xmlDtdPtr dtd;
|
61
|
+
VALUE hash;
|
62
|
+
|
59
63
|
Data_Get_Struct(self, xmlDtd, dtd);
|
60
64
|
|
61
65
|
if(!dtd->notations) return Qnil;
|
62
66
|
|
63
|
-
|
67
|
+
hash = rb_hash_new();
|
64
68
|
|
65
69
|
xmlHashScan((xmlHashTablePtr)dtd->notations, notation_copier, (void *)hash);
|
66
70
|
|
@@ -76,11 +80,13 @@ static VALUE notations(VALUE self)
|
|
76
80
|
static VALUE attributes(VALUE self)
|
77
81
|
{
|
78
82
|
xmlDtdPtr dtd;
|
83
|
+
VALUE hash;
|
84
|
+
|
79
85
|
Data_Get_Struct(self, xmlDtd, dtd);
|
80
86
|
|
81
87
|
if(!dtd->attributes) return Qnil;
|
82
88
|
|
83
|
-
|
89
|
+
hash = rb_hash_new();
|
84
90
|
|
85
91
|
xmlHashScan((xmlHashTablePtr)dtd->attributes, element_copier, (void *)hash);
|
86
92
|
|
@@ -96,11 +102,13 @@ static VALUE attributes(VALUE self)
|
|
96
102
|
static VALUE elements(VALUE self)
|
97
103
|
{
|
98
104
|
xmlDtdPtr dtd;
|
105
|
+
VALUE hash;
|
106
|
+
|
99
107
|
Data_Get_Struct(self, xmlDtd, dtd);
|
100
108
|
|
101
109
|
if(!dtd->elements) return Qnil;
|
102
110
|
|
103
|
-
|
111
|
+
hash = rb_hash_new();
|
104
112
|
|
105
113
|
xmlHashScan((xmlHashTablePtr)dtd->elements, element_copier, (void *)hash);
|
106
114
|
|
@@ -117,12 +125,14 @@ static VALUE validate(VALUE self, VALUE document)
|
|
117
125
|
{
|
118
126
|
xmlDocPtr doc;
|
119
127
|
xmlDtdPtr dtd;
|
128
|
+
xmlValidCtxtPtr ctxt;
|
129
|
+
VALUE error_list;
|
120
130
|
|
121
131
|
Data_Get_Struct(self, xmlDtd, dtd);
|
122
132
|
Data_Get_Struct(document, xmlDoc, doc);
|
123
|
-
|
133
|
+
error_list = rb_ary_new();
|
124
134
|
|
125
|
-
|
135
|
+
ctxt = xmlNewValidCtxt();
|
126
136
|
|
127
137
|
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
128
138
|
|
@@ -97,8 +97,8 @@ VALUE Nokogiri_wrap_element_content(VALUE doc, xmlElementContentPtr element)
|
|
97
97
|
{
|
98
98
|
VALUE elem = Data_Wrap_Struct(cNokogiriXmlElementContent, 0, 0, element);
|
99
99
|
|
100
|
-
|
101
|
-
|
100
|
+
/* Setting the document is necessary so that this does not get GC'd until */
|
101
|
+
/* the document is GC'd */
|
102
102
|
rb_iv_set(elem, "@document", doc);
|
103
103
|
|
104
104
|
return elem;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#include <xml_entity_decl.h>
|
1
|
+
#include <xml_entity_decl.h>
|
2
2
|
|
3
3
|
/*
|
4
4
|
* call-seq:
|
@@ -34,7 +34,7 @@ static VALUE get_content(VALUE self)
|
|
34
34
|
|
35
35
|
/*
|
36
36
|
* call-seq:
|
37
|
-
*
|
37
|
+
* entity_type
|
38
38
|
*
|
39
39
|
* Get the entity type
|
40
40
|
*/
|
@@ -94,4 +94,17 @@ void init_xml_entity_decl()
|
|
94
94
|
rb_define_method(klass, "entity_type", entity_type, 0);
|
95
95
|
rb_define_method(klass, "external_id", external_id, 0);
|
96
96
|
rb_define_method(klass, "system_id", system_id, 0);
|
97
|
+
|
98
|
+
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_GENERAL"),
|
99
|
+
INT2NUM(XML_INTERNAL_GENERAL_ENTITY));
|
100
|
+
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_GENERAL_PARSED"),
|
101
|
+
INT2NUM(XML_EXTERNAL_GENERAL_PARSED_ENTITY));
|
102
|
+
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_GENERAL_UNPARSED"),
|
103
|
+
INT2NUM(XML_EXTERNAL_GENERAL_UNPARSED_ENTITY));
|
104
|
+
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_PARAMETER"),
|
105
|
+
INT2NUM(XML_INTERNAL_PARAMETER_ENTITY));
|
106
|
+
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_PARAMETER"),
|
107
|
+
INT2NUM(XML_EXTERNAL_PARAMETER_ENTITY));
|
108
|
+
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_PREDEFINED"),
|
109
|
+
INT2NUM(XML_INTERNAL_PREDEFINED_ENTITY));
|
97
110
|
}
|
@@ -9,22 +9,24 @@
|
|
9
9
|
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
10
10
|
{
|
11
11
|
xmlDocPtr xml_doc;
|
12
|
+
xmlNodePtr node;
|
12
13
|
VALUE document;
|
13
14
|
VALUE name;
|
14
15
|
VALUE rest;
|
16
|
+
VALUE rb_node;
|
15
17
|
|
16
18
|
rb_scan_args(argc, argv, "2*", &document, &name, &rest);
|
17
19
|
|
18
20
|
Data_Get_Struct(document, xmlDoc, xml_doc);
|
19
21
|
|
20
|
-
|
22
|
+
node = xmlNewReference(
|
21
23
|
xml_doc,
|
22
24
|
(const xmlChar *)StringValuePtr(name)
|
23
25
|
);
|
24
26
|
|
25
27
|
NOKOGIRI_ROOT_NODE(node);
|
26
28
|
|
27
|
-
|
29
|
+
rb_node = Nokogiri_wrap_xml_node(klass, node);
|
28
30
|
rb_obj_call_init(rb_node, argc, argv);
|
29
31
|
|
30
32
|
if(rb_block_given_p()) rb_yield(rb_node);
|
data/ext/nokogiri/xml_io.c
CHANGED
@@ -10,7 +10,7 @@ int io_read_callback(void * ctx, char * buffer, int len) {
|
|
10
10
|
|
11
11
|
memcpy(buffer, StringValuePtr(string), (unsigned int)RSTRING_LEN(string));
|
12
12
|
|
13
|
-
return RSTRING_LEN(string);
|
13
|
+
return (int)RSTRING_LEN(string);
|
14
14
|
}
|
15
15
|
|
16
16
|
int io_write_callback(void * ctx, char * buffer, int len) {
|
@@ -42,16 +42,18 @@ static VALUE href(VALUE self)
|
|
42
42
|
|
43
43
|
VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node)
|
44
44
|
{
|
45
|
+
VALUE ns, document, node_cache;
|
46
|
+
|
45
47
|
assert(doc->_private);
|
46
48
|
|
47
49
|
if(node->_private)
|
48
50
|
return (VALUE)node->_private;
|
49
51
|
|
50
|
-
|
52
|
+
ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);
|
51
53
|
|
52
|
-
|
54
|
+
document = DOC_RUBY_OBJECT(doc);
|
53
55
|
|
54
|
-
|
56
|
+
node_cache = rb_iv_get(document, "@node_cache");
|
55
57
|
rb_ary_push(node_cache, ns);
|
56
58
|
|
57
59
|
rb_iv_set(ns, "@document", DOC_RUBY_OBJECT(doc));
|