nokogiri 1.4.1-x86-mingw32 → 1.4.2.1-x86-mingw32
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 +25 -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/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css/generated_parser.rb +72 -62
- data/lib/nokogiri/css/generated_tokenizer.rb +23 -23
- 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 +151 -79
- data/ext/nokogiri/iconv.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/xml_xpath.c +0 -53
- data/ext/nokogiri/xml_xpath.h +0 -11
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/nokogiri/xml/fragment_handler.rb +0 -79
data/ext/nokogiri/xml_node_set.c
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#include <xml_node_set.h>
|
2
2
|
#include <libxml/xpathInternals.h>
|
3
3
|
|
4
|
+
static ID decorate ;
|
5
|
+
|
4
6
|
/*
|
5
7
|
* call-seq:
|
6
8
|
* dup
|
@@ -10,11 +12,13 @@
|
|
10
12
|
static VALUE duplicate(VALUE self)
|
11
13
|
{
|
12
14
|
xmlNodeSetPtr node_set;
|
15
|
+
xmlNodeSetPtr dupl;
|
16
|
+
|
13
17
|
Data_Get_Struct(self, xmlNodeSet, node_set);
|
14
18
|
|
15
|
-
|
19
|
+
dupl = xmlXPathNodeSetMerge(NULL, node_set);
|
16
20
|
|
17
|
-
return Nokogiri_wrap_xml_node_set(dupl);
|
21
|
+
return Nokogiri_wrap_xml_node_set(dupl, rb_iv_get(self, "@document"));
|
18
22
|
}
|
19
23
|
|
20
24
|
/*
|
@@ -98,7 +102,7 @@ static VALUE intersection(VALUE self, VALUE rb_other)
|
|
98
102
|
Data_Get_Struct(self, xmlNodeSet, node_set);
|
99
103
|
Data_Get_Struct(rb_other, xmlNodeSet, other);
|
100
104
|
|
101
|
-
return Nokogiri_wrap_xml_node_set(xmlXPathIntersection(node_set, other));
|
105
|
+
return Nokogiri_wrap_xml_node_set(xmlXPathIntersection(node_set, other), rb_iv_get(self, "@document"));
|
102
106
|
}
|
103
107
|
|
104
108
|
|
@@ -145,11 +149,7 @@ static VALUE set_union(VALUE self, VALUE rb_other)
|
|
145
149
|
new = xmlXPathNodeSetMerge(NULL, node_set);
|
146
150
|
new = xmlXPathNodeSetMerge(new, other);
|
147
151
|
|
148
|
-
|
149
|
-
|
150
|
-
rb_iv_set(new_set, "@document", rb_iv_get(self, "@document"));
|
151
|
-
|
152
|
-
return new_set;
|
152
|
+
return Nokogiri_wrap_xml_node_set(new, rb_iv_get(self, "@document"));
|
153
153
|
}
|
154
154
|
|
155
155
|
/*
|
@@ -177,7 +177,7 @@ static VALUE minus(VALUE self, VALUE rb_other)
|
|
177
177
|
xmlXPathNodeSetDel(new, other->nodeTab[j]);
|
178
178
|
}
|
179
179
|
|
180
|
-
return Nokogiri_wrap_xml_node_set(new);
|
180
|
+
return Nokogiri_wrap_xml_node_set(new, rb_iv_get(self, "@document"));
|
181
181
|
}
|
182
182
|
|
183
183
|
|
@@ -186,7 +186,7 @@ static VALUE index_at(VALUE self, long offset)
|
|
186
186
|
xmlNodeSetPtr node_set;
|
187
187
|
Data_Get_Struct(self, xmlNodeSet, node_set);
|
188
188
|
|
189
|
-
if(offset >= node_set->nodeNr || abs(offset) > node_set->nodeNr) return Qnil;
|
189
|
+
if(offset >= node_set->nodeNr || abs((int)offset) > node_set->nodeNr) return Qnil;
|
190
190
|
if(offset < 0) offset = offset + node_set->nodeNr;
|
191
191
|
|
192
192
|
if (XML_NAMESPACE_DECL == node_set->nodeTab[offset]->type)
|
@@ -196,7 +196,7 @@ static VALUE index_at(VALUE self, long offset)
|
|
196
196
|
|
197
197
|
static VALUE subseq(VALUE self, long beg, long len)
|
198
198
|
{
|
199
|
-
|
199
|
+
long j;
|
200
200
|
xmlNodeSetPtr node_set;
|
201
201
|
xmlNodeSetPtr new_set ;
|
202
202
|
|
@@ -205,11 +205,15 @@ static VALUE subseq(VALUE self, long beg, long len)
|
|
205
205
|
if (beg > node_set->nodeNr) return Qnil ;
|
206
206
|
if (beg < 0 || len < 0) return Qnil ;
|
207
207
|
|
208
|
+
if ((beg + len) > node_set->nodeNr) {
|
209
|
+
len = node_set->nodeNr - beg ;
|
210
|
+
}
|
211
|
+
|
208
212
|
new_set = xmlXPathNodeSetCreate(NULL);
|
209
213
|
for (j = beg ; j < beg+len ; ++j) {
|
210
|
-
|
214
|
+
xmlXPathNodeSetAddUnique(new_set, node_set->nodeTab[j]);
|
211
215
|
}
|
212
|
-
return Nokogiri_wrap_xml_node_set(new_set);
|
216
|
+
return Nokogiri_wrap_xml_node_set(new_set, rb_iv_get(self, "@document"));
|
213
217
|
}
|
214
218
|
|
215
219
|
/*
|
@@ -240,8 +244,6 @@ static VALUE slice(int argc, VALUE *argv, VALUE self)
|
|
240
244
|
if (beg < 0) {
|
241
245
|
beg += node_set->nodeNr ;
|
242
246
|
}
|
243
|
-
if (len > node_set->nodeNr) len = node_set->nodeNr;
|
244
|
-
|
245
247
|
return subseq(self, beg, len);
|
246
248
|
}
|
247
249
|
|
@@ -277,10 +279,13 @@ static VALUE slice(int argc, VALUE *argv, VALUE self)
|
|
277
279
|
static VALUE to_array(VALUE self, VALUE rb_node)
|
278
280
|
{
|
279
281
|
xmlNodeSetPtr set;
|
282
|
+
VALUE *elts;
|
283
|
+
VALUE list;
|
284
|
+
int i;
|
285
|
+
|
280
286
|
Data_Get_Struct(self, xmlNodeSet, set);
|
281
287
|
|
282
|
-
|
283
|
-
int i;
|
288
|
+
elts = calloc((size_t)set->nodeNr, sizeof(VALUE *));
|
284
289
|
for(i = 0; i < set->nodeNr; i++) {
|
285
290
|
if (XML_NAMESPACE_DECL == set->nodeTab[i]->type) {
|
286
291
|
elts[i] = Nokogiri_wrap_xml_namespace2(rb_iv_get(self, "@document"), (xmlNsPtr)(set->nodeTab[i]));
|
@@ -298,9 +303,9 @@ static VALUE to_array(VALUE self, VALUE rb_node)
|
|
298
303
|
}
|
299
304
|
}
|
300
305
|
|
301
|
-
|
306
|
+
list = rb_ary_new4((long)set->nodeNr, elts);
|
302
307
|
|
303
|
-
|
308
|
+
/*free(elts); */
|
304
309
|
|
305
310
|
return list;
|
306
311
|
}
|
@@ -373,12 +378,18 @@ static void deallocate(xmlNodeSetPtr node_set)
|
|
373
378
|
|
374
379
|
static VALUE allocate(VALUE klass)
|
375
380
|
{
|
376
|
-
return Nokogiri_wrap_xml_node_set(xmlXPathNodeSetCreate(NULL));
|
381
|
+
return Nokogiri_wrap_xml_node_set(xmlXPathNodeSetCreate(NULL), Qnil);
|
377
382
|
}
|
378
383
|
|
379
|
-
VALUE Nokogiri_wrap_xml_node_set(xmlNodeSetPtr node_set)
|
384
|
+
VALUE Nokogiri_wrap_xml_node_set(xmlNodeSetPtr node_set, VALUE document)
|
380
385
|
{
|
381
|
-
|
386
|
+
VALUE new_set ;
|
387
|
+
new_set = Data_Wrap_Struct(cNokogiriXmlNodeSet, 0, deallocate, node_set);
|
388
|
+
if (document != Qnil) {
|
389
|
+
rb_iv_set(new_set, "@document", document);
|
390
|
+
rb_funcall(document, decorate, 1, new_set);
|
391
|
+
}
|
392
|
+
return new_set ;
|
382
393
|
}
|
383
394
|
|
384
395
|
VALUE cNokogiriXmlNodeSet ;
|
@@ -402,4 +413,6 @@ void init_xml_node_set(void)
|
|
402
413
|
rb_define_method(klass, "delete", delete, 1);
|
403
414
|
rb_define_method(klass, "&", intersection, 1);
|
404
415
|
rb_define_method(klass, "include?", include_eh, 1);
|
416
|
+
|
417
|
+
decorate = rb_intern("decorate");
|
405
418
|
}
|
data/ext/nokogiri/xml_node_set.h
CHANGED
@@ -10,16 +10,18 @@
|
|
10
10
|
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
11
11
|
{
|
12
12
|
xmlDocPtr xml_doc;
|
13
|
+
xmlNodePtr node;
|
13
14
|
VALUE document;
|
14
15
|
VALUE name;
|
15
16
|
VALUE content;
|
16
17
|
VALUE rest;
|
18
|
+
VALUE rb_node;
|
17
19
|
|
18
20
|
rb_scan_args(argc, argv, "3*", &document, &name, &content, &rest);
|
19
21
|
|
20
22
|
Data_Get_Struct(document, xmlDoc, xml_doc);
|
21
23
|
|
22
|
-
|
24
|
+
node = xmlNewDocPI(
|
23
25
|
xml_doc,
|
24
26
|
(const xmlChar *)StringValuePtr(name),
|
25
27
|
(const xmlChar *)StringValuePtr(content)
|
@@ -27,7 +29,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
27
29
|
|
28
30
|
NOKOGIRI_ROOT_NODE(node);
|
29
31
|
|
30
|
-
|
32
|
+
rb_node = Nokogiri_wrap_xml_node(klass, node);
|
31
33
|
rb_obj_call_init(rb_node, argc, argv);
|
32
34
|
|
33
35
|
if(rb_block_given_p()) rb_yield(rb_node);
|
data/ext/nokogiri/xml_reader.c
CHANGED
@@ -74,8 +74,10 @@ static void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
|
74
74
|
static VALUE default_eh(VALUE self)
|
75
75
|
{
|
76
76
|
xmlTextReaderPtr reader;
|
77
|
+
int eh;
|
78
|
+
|
77
79
|
Data_Get_Struct(self, xmlTextReader, reader);
|
78
|
-
|
80
|
+
eh = xmlTextReaderIsDefault(reader);
|
79
81
|
if(eh == 0) return Qfalse;
|
80
82
|
if(eh == 1) return Qtrue;
|
81
83
|
|
@@ -91,8 +93,10 @@ static VALUE default_eh(VALUE self)
|
|
91
93
|
static VALUE value_eh(VALUE self)
|
92
94
|
{
|
93
95
|
xmlTextReaderPtr reader;
|
96
|
+
int eh;
|
97
|
+
|
94
98
|
Data_Get_Struct(self, xmlTextReader, reader);
|
95
|
-
|
99
|
+
eh = xmlTextReaderHasValue(reader);
|
96
100
|
if(eh == 0) return Qfalse;
|
97
101
|
if(eh == 1) return Qtrue;
|
98
102
|
|
@@ -108,8 +112,10 @@ static VALUE value_eh(VALUE self)
|
|
108
112
|
static VALUE attributes_eh(VALUE self)
|
109
113
|
{
|
110
114
|
xmlTextReaderPtr reader;
|
115
|
+
int eh;
|
116
|
+
|
111
117
|
Data_Get_Struct(self, xmlTextReader, reader);
|
112
|
-
|
118
|
+
eh = has_attributes(reader);
|
113
119
|
if(eh == 0) return Qfalse;
|
114
120
|
if(eh == 1) return Qtrue;
|
115
121
|
|
@@ -125,6 +131,7 @@ static VALUE attributes_eh(VALUE self)
|
|
125
131
|
static VALUE namespaces(VALUE self)
|
126
132
|
{
|
127
133
|
xmlTextReaderPtr reader;
|
134
|
+
xmlNodePtr ptr;
|
128
135
|
VALUE attr ;
|
129
136
|
|
130
137
|
Data_Get_Struct(self, xmlTextReader, reader);
|
@@ -134,7 +141,7 @@ static VALUE namespaces(VALUE self)
|
|
134
141
|
if (! has_attributes(reader))
|
135
142
|
return attr ;
|
136
143
|
|
137
|
-
|
144
|
+
ptr = xmlTextReaderExpand(reader);
|
138
145
|
if(ptr == NULL) return Qnil;
|
139
146
|
|
140
147
|
Nokogiri_xml_node_namespaces(ptr, attr);
|
@@ -151,6 +158,7 @@ static VALUE namespaces(VALUE self)
|
|
151
158
|
static VALUE attribute_nodes(VALUE self)
|
152
159
|
{
|
153
160
|
xmlTextReaderPtr reader;
|
161
|
+
xmlNodePtr ptr;
|
154
162
|
VALUE attr ;
|
155
163
|
|
156
164
|
Data_Get_Struct(self, xmlTextReader, reader);
|
@@ -160,7 +168,7 @@ static VALUE attribute_nodes(VALUE self)
|
|
160
168
|
if (! has_attributes(reader))
|
161
169
|
return attr ;
|
162
170
|
|
163
|
-
|
171
|
+
ptr = xmlTextReaderExpand(reader);
|
164
172
|
if(ptr == NULL) return Qnil;
|
165
173
|
|
166
174
|
Nokogiri_xml_node_properties(ptr, attr);
|
@@ -177,18 +185,21 @@ static VALUE attribute_nodes(VALUE self)
|
|
177
185
|
static VALUE attribute_at(VALUE self, VALUE index)
|
178
186
|
{
|
179
187
|
xmlTextReaderPtr reader;
|
188
|
+
xmlChar *value;
|
189
|
+
VALUE rb_value;
|
190
|
+
|
180
191
|
Data_Get_Struct(self, xmlTextReader, reader);
|
181
192
|
|
182
193
|
if(NIL_P(index)) return Qnil;
|
183
194
|
index = rb_Integer(index);
|
184
195
|
|
185
|
-
|
196
|
+
value = xmlTextReaderGetAttributeNo(
|
186
197
|
reader,
|
187
|
-
NUM2INT(index)
|
198
|
+
(int)NUM2INT(index)
|
188
199
|
);
|
189
200
|
if(value == NULL) return Qnil;
|
190
201
|
|
191
|
-
|
202
|
+
rb_value = NOKOGIRI_STR_NEW2(value);
|
192
203
|
xmlFree(value);
|
193
204
|
return rb_value;
|
194
205
|
}
|
@@ -203,6 +214,8 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
203
214
|
{
|
204
215
|
xmlTextReaderPtr reader;
|
205
216
|
xmlChar *value ;
|
217
|
+
VALUE rb_value;
|
218
|
+
|
206
219
|
Data_Get_Struct(self, xmlTextReader, reader);
|
207
220
|
|
208
221
|
if(NIL_P(name)) return Qnil;
|
@@ -224,7 +237,7 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
224
237
|
}
|
225
238
|
if(value == NULL) return Qnil;
|
226
239
|
|
227
|
-
|
240
|
+
rb_value = NOKOGIRI_STR_NEW2(value);
|
228
241
|
xmlFree(value);
|
229
242
|
return rb_value;
|
230
243
|
}
|
@@ -238,8 +251,10 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
238
251
|
static VALUE attribute_count(VALUE self)
|
239
252
|
{
|
240
253
|
xmlTextReaderPtr reader;
|
254
|
+
int count;
|
255
|
+
|
241
256
|
Data_Get_Struct(self, xmlTextReader, reader);
|
242
|
-
|
257
|
+
count = xmlTextReaderAttributeCount(reader);
|
243
258
|
if(count == -1) return Qnil;
|
244
259
|
|
245
260
|
return INT2NUM((long)count);
|
@@ -254,8 +269,10 @@ static VALUE attribute_count(VALUE self)
|
|
254
269
|
static VALUE depth(VALUE self)
|
255
270
|
{
|
256
271
|
xmlTextReaderPtr reader;
|
272
|
+
int depth;
|
273
|
+
|
257
274
|
Data_Get_Struct(self, xmlTextReader, reader);
|
258
|
-
|
275
|
+
depth = xmlTextReaderDepth(reader);
|
259
276
|
if(depth == -1) return Qnil;
|
260
277
|
|
261
278
|
return INT2NUM((long)depth);
|
@@ -270,8 +287,10 @@ static VALUE depth(VALUE self)
|
|
270
287
|
static VALUE xml_version(VALUE self)
|
271
288
|
{
|
272
289
|
xmlTextReaderPtr reader;
|
290
|
+
const char *version;
|
291
|
+
|
273
292
|
Data_Get_Struct(self, xmlTextReader, reader);
|
274
|
-
|
293
|
+
version = (const char *)xmlTextReaderConstXmlVersion(reader);
|
275
294
|
if(version == NULL) return Qnil;
|
276
295
|
|
277
296
|
return NOKOGIRI_STR_NEW2(version);
|
@@ -286,8 +305,10 @@ static VALUE xml_version(VALUE self)
|
|
286
305
|
static VALUE lang(VALUE self)
|
287
306
|
{
|
288
307
|
xmlTextReaderPtr reader;
|
308
|
+
const char *lang;
|
309
|
+
|
289
310
|
Data_Get_Struct(self, xmlTextReader, reader);
|
290
|
-
|
311
|
+
lang = (const char *)xmlTextReaderConstXmlLang(reader);
|
291
312
|
if(lang == NULL) return Qnil;
|
292
313
|
|
293
314
|
return NOKOGIRI_STR_NEW2(lang);
|
@@ -297,13 +318,15 @@ static VALUE lang(VALUE self)
|
|
297
318
|
* call-seq:
|
298
319
|
* value
|
299
320
|
*
|
300
|
-
* Get the text value of the node if present
|
321
|
+
* Get the text value of the node if present. Returns a utf-8 encoded string.
|
301
322
|
*/
|
302
323
|
static VALUE value(VALUE self)
|
303
324
|
{
|
304
325
|
xmlTextReaderPtr reader;
|
326
|
+
const char *value;
|
327
|
+
|
305
328
|
Data_Get_Struct(self, xmlTextReader, reader);
|
306
|
-
|
329
|
+
value = (const char *)xmlTextReaderConstValue(reader);
|
307
330
|
if(value == NULL) return Qnil;
|
308
331
|
|
309
332
|
return NOKOGIRI_STR_NEW2(value);
|
@@ -318,8 +341,10 @@ static VALUE value(VALUE self)
|
|
318
341
|
static VALUE prefix(VALUE self)
|
319
342
|
{
|
320
343
|
xmlTextReaderPtr reader;
|
344
|
+
const char *prefix;
|
345
|
+
|
321
346
|
Data_Get_Struct(self, xmlTextReader, reader);
|
322
|
-
|
347
|
+
prefix = (const char *)xmlTextReaderConstPrefix(reader);
|
323
348
|
if(prefix == NULL) return Qnil;
|
324
349
|
|
325
350
|
return NOKOGIRI_STR_NEW2(prefix);
|
@@ -334,8 +359,10 @@ static VALUE prefix(VALUE self)
|
|
334
359
|
static VALUE namespace_uri(VALUE self)
|
335
360
|
{
|
336
361
|
xmlTextReaderPtr reader;
|
362
|
+
const char *uri;
|
363
|
+
|
337
364
|
Data_Get_Struct(self, xmlTextReader, reader);
|
338
|
-
|
365
|
+
uri = (const char *)xmlTextReaderConstNamespaceUri(reader);
|
339
366
|
if(uri == NULL) return Qnil;
|
340
367
|
|
341
368
|
return NOKOGIRI_STR_NEW2(uri);
|
@@ -350,8 +377,10 @@ static VALUE namespace_uri(VALUE self)
|
|
350
377
|
static VALUE local_name(VALUE self)
|
351
378
|
{
|
352
379
|
xmlTextReaderPtr reader;
|
380
|
+
const char *name;
|
381
|
+
|
353
382
|
Data_Get_Struct(self, xmlTextReader, reader);
|
354
|
-
|
383
|
+
name = (const char *)xmlTextReaderConstLocalName(reader);
|
355
384
|
if(name == NULL) return Qnil;
|
356
385
|
|
357
386
|
return NOKOGIRI_STR_NEW2(name);
|
@@ -361,18 +390,38 @@ static VALUE local_name(VALUE self)
|
|
361
390
|
* call-seq:
|
362
391
|
* name
|
363
392
|
*
|
364
|
-
* Get the name of the node
|
393
|
+
* Get the name of the node. Returns a utf-8 encoded string.
|
365
394
|
*/
|
366
395
|
static VALUE name(VALUE self)
|
367
396
|
{
|
368
397
|
xmlTextReaderPtr reader;
|
398
|
+
const char *name;
|
399
|
+
|
369
400
|
Data_Get_Struct(self, xmlTextReader, reader);
|
370
|
-
|
401
|
+
name = (const char *)xmlTextReaderConstName(reader);
|
371
402
|
if(name == NULL) return Qnil;
|
372
403
|
|
373
404
|
return NOKOGIRI_STR_NEW2(name);
|
374
405
|
}
|
375
406
|
|
407
|
+
/*
|
408
|
+
* call-seq:
|
409
|
+
* base_uri
|
410
|
+
*
|
411
|
+
* Get the xml:base of the node
|
412
|
+
*/
|
413
|
+
static VALUE base_uri(VALUE self)
|
414
|
+
{
|
415
|
+
xmlTextReaderPtr reader;
|
416
|
+
const char * base_uri;
|
417
|
+
|
418
|
+
Data_Get_Struct(self, xmlTextReader, reader);
|
419
|
+
base_uri = (const char *)xmlTextReaderBaseUri(reader);
|
420
|
+
if (base_uri == NULL) return Qnil;
|
421
|
+
|
422
|
+
return NOKOGIRI_STR_NEW2(base_uri);
|
423
|
+
}
|
424
|
+
|
376
425
|
/*
|
377
426
|
* call-seq:
|
378
427
|
* state
|
@@ -408,18 +457,22 @@ static VALUE node_type(VALUE self)
|
|
408
457
|
static VALUE read_more(VALUE self)
|
409
458
|
{
|
410
459
|
xmlTextReaderPtr reader;
|
460
|
+
xmlErrorPtr error;
|
461
|
+
VALUE error_list;
|
462
|
+
int ret;
|
463
|
+
|
411
464
|
Data_Get_Struct(self, xmlTextReader, reader);
|
412
465
|
|
413
|
-
|
466
|
+
error_list = rb_funcall(self, rb_intern("errors"), 0);
|
414
467
|
|
415
468
|
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
416
|
-
|
469
|
+
ret = xmlTextReaderRead(reader);
|
417
470
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
418
471
|
|
419
472
|
if(ret == 1) return self;
|
420
473
|
if(ret == 0) return Qnil;
|
421
474
|
|
422
|
-
|
475
|
+
error = xmlGetLastError();
|
423
476
|
if(error)
|
424
477
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
|
425
478
|
else
|
@@ -433,18 +486,25 @@ static VALUE read_more(VALUE self)
|
|
433
486
|
* inner_xml
|
434
487
|
*
|
435
488
|
* Read the contents of the current node, including child nodes and markup.
|
489
|
+
* Returns a utf-8 encoded string.
|
436
490
|
*/
|
437
491
|
static VALUE inner_xml(VALUE self)
|
438
492
|
{
|
439
493
|
xmlTextReaderPtr reader;
|
494
|
+
xmlChar* value;
|
495
|
+
VALUE str;
|
496
|
+
|
440
497
|
Data_Get_Struct(self, xmlTextReader, reader);
|
441
498
|
|
442
|
-
|
499
|
+
value = xmlTextReaderReadInnerXml(reader);
|
443
500
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
501
|
+
str = Qnil;
|
502
|
+
if(value) {
|
503
|
+
str = NOKOGIRI_STR_NEW2((char*)value);
|
504
|
+
xmlFree(value);
|
505
|
+
}
|
506
|
+
|
507
|
+
return str;
|
448
508
|
}
|
449
509
|
|
450
510
|
/*
|
@@ -452,18 +512,23 @@ static VALUE inner_xml(VALUE self)
|
|
452
512
|
* outer_xml
|
453
513
|
*
|
454
514
|
* Read the current node and its contents, including child nodes and markup.
|
515
|
+
* Returns a utf-8 encoded string.
|
455
516
|
*/
|
456
517
|
static VALUE outer_xml(VALUE self)
|
457
518
|
{
|
458
519
|
xmlTextReaderPtr reader;
|
459
|
-
|
520
|
+
xmlChar *value;
|
521
|
+
VALUE str = Qnil;
|
460
522
|
|
461
|
-
|
523
|
+
Data_Get_Struct(self, xmlTextReader, reader);
|
462
524
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
525
|
+
value = xmlTextReaderReadOuterXml(reader);
|
526
|
+
|
527
|
+
if(value) {
|
528
|
+
str = NOKOGIRI_STR_NEW2((char*)value);
|
529
|
+
xmlFree(value);
|
530
|
+
}
|
531
|
+
return str;
|
467
532
|
}
|
468
533
|
|
469
534
|
/*
|
@@ -475,21 +540,22 @@ static VALUE outer_xml(VALUE self)
|
|
475
540
|
static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
476
541
|
{
|
477
542
|
VALUE rb_buffer, rb_url, encoding, rb_options;
|
478
|
-
|
543
|
+
xmlTextReaderPtr reader;
|
479
544
|
const char * c_url = NULL;
|
480
545
|
const char * c_encoding = NULL;
|
481
|
-
int c_options = 0;
|
546
|
+
int c_options = 0;
|
547
|
+
VALUE rb_reader, args[3];
|
482
548
|
|
483
549
|
rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options);
|
484
550
|
|
485
551
|
if (!RTEST(rb_buffer)) rb_raise(rb_eArgError, "string cannot be nil");
|
486
552
|
if (RTEST(rb_url)) c_url = StringValuePtr(rb_url);
|
487
553
|
if (RTEST(encoding)) c_encoding = StringValuePtr(encoding);
|
488
|
-
if (RTEST(rb_options)) c_options = NUM2INT(rb_options);
|
554
|
+
if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
|
489
555
|
|
490
|
-
|
556
|
+
reader = xmlReaderForMemory(
|
491
557
|
StringValuePtr(rb_buffer),
|
492
|
-
RSTRING_LEN(rb_buffer),
|
558
|
+
(int)RSTRING_LEN(rb_buffer),
|
493
559
|
c_url,
|
494
560
|
c_encoding,
|
495
561
|
c_options
|
@@ -500,8 +566,10 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
|
500
566
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
501
567
|
}
|
502
568
|
|
503
|
-
|
504
|
-
|
569
|
+
rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
|
570
|
+
args[0] = rb_buffer;
|
571
|
+
args[1] = rb_url;
|
572
|
+
args[2] = encoding;
|
505
573
|
rb_obj_call_init(rb_reader, 3, args);
|
506
574
|
|
507
575
|
return rb_reader;
|
@@ -516,19 +584,20 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
|
516
584
|
static VALUE from_io(int argc, VALUE *argv, VALUE klass)
|
517
585
|
{
|
518
586
|
VALUE rb_io, rb_url, encoding, rb_options;
|
519
|
-
|
587
|
+
xmlTextReaderPtr reader;
|
520
588
|
const char * c_url = NULL;
|
521
589
|
const char * c_encoding = NULL;
|
522
|
-
int c_options = 0;
|
590
|
+
int c_options = 0;
|
591
|
+
VALUE rb_reader, args[3];
|
523
592
|
|
524
593
|
rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options);
|
525
594
|
|
526
595
|
if (!RTEST(rb_io)) rb_raise(rb_eArgError, "io cannot be nil");
|
527
596
|
if (RTEST(rb_url)) c_url = StringValuePtr(rb_url);
|
528
597
|
if (RTEST(encoding)) c_encoding = StringValuePtr(encoding);
|
529
|
-
if (RTEST(rb_options)) c_options = NUM2INT(rb_options);
|
598
|
+
if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
|
530
599
|
|
531
|
-
|
600
|
+
reader = xmlReaderForIO(
|
532
601
|
(xmlInputReadCallback)io_read_callback,
|
533
602
|
(xmlInputCloseCallback)io_close_callback,
|
534
603
|
(void *)rb_io,
|
@@ -542,8 +611,10 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
|
|
542
611
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
543
612
|
}
|
544
613
|
|
545
|
-
|
546
|
-
|
614
|
+
rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
|
615
|
+
args[0] = rb_io;
|
616
|
+
args[1] = rb_url;
|
617
|
+
args[2] = encoding;
|
547
618
|
rb_obj_call_init(rb_reader, 3, args);
|
548
619
|
|
549
620
|
return rb_reader;
|
@@ -588,6 +659,7 @@ void init_xml_reader()
|
|
588
659
|
rb_define_method(klass, "attributes?", attributes_eh, 0);
|
589
660
|
rb_define_method(klass, "value?", value_eh, 0);
|
590
661
|
rb_define_method(klass, "default?", default_eh, 0);
|
662
|
+
rb_define_method(klass, "base_uri", base_uri, 0);
|
591
663
|
|
592
664
|
rb_define_private_method(klass, "attr_nodes", attribute_nodes, 0);
|
593
665
|
}
|