nokogiri 1.1.1 → 1.2.0
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/History.ja.txt +34 -0
- data/History.txt +36 -0
- data/Manifest.txt +21 -0
- data/README.ja.txt +1 -1
- data/README.txt +1 -1
- data/Rakefile +27 -89
- data/ext/nokogiri/extconf.rb +48 -63
- data/ext/nokogiri/html_document.c +90 -29
- data/ext/nokogiri/html_sax_parser.c +23 -2
- data/ext/nokogiri/native.c +18 -8
- data/ext/nokogiri/native.h +22 -0
- data/ext/nokogiri/xml_attr.c +83 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_cdata.c +1 -1
- data/ext/nokogiri/xml_document.c +84 -18
- data/ext/nokogiri/xml_document_fragment.c +38 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +2 -22
- data/ext/nokogiri/xml_entity_reference.c +41 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +10 -3
- data/ext/nokogiri/xml_io.h +1 -0
- data/ext/nokogiri/xml_node.c +116 -66
- data/ext/nokogiri/xml_node_set.c +5 -1
- data/ext/nokogiri/xml_processing_instruction.c +44 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +20 -4
- data/ext/nokogiri/xml_sax_parser.c +51 -15
- data/ext/nokogiri/xml_sax_push_parser.c +85 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +12 -8
- data/ext/nokogiri/xml_syntax_error.h +2 -1
- data/ext/nokogiri/xml_xpath_context.c +11 -2
- data/ext/nokogiri/xslt_stylesheet.c +1 -6
- data/lib/nokogiri.rb +10 -13
- data/lib/nokogiri/css.rb +1 -1
- data/lib/nokogiri/css/generated_parser.rb +287 -295
- data/lib/nokogiri/css/generated_tokenizer.rb +36 -51
- data/lib/nokogiri/css/node.rb +1 -3
- data/lib/nokogiri/css/parser.rb +21 -12
- data/lib/nokogiri/css/parser.y +55 -44
- data/lib/nokogiri/css/syntax_error.rb +2 -1
- data/lib/nokogiri/css/tokenizer.rex +23 -32
- data/lib/nokogiri/decorators/hpricot/node_set.rb +1 -1
- data/lib/nokogiri/html.rb +10 -4
- data/lib/nokogiri/html/document.rb +6 -2
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +2 -1
- data/lib/nokogiri/xml.rb +3 -1
- data/lib/nokogiri/xml/attr.rb +3 -4
- data/lib/nokogiri/xml/cdata.rb +1 -1
- data/lib/nokogiri/xml/document.rb +4 -7
- data/lib/nokogiri/xml/document_fragment.rb +9 -0
- data/lib/nokogiri/xml/dtd.rb +3 -0
- data/lib/nokogiri/xml/node.rb +144 -40
- data/lib/nokogiri/xml/node/save_options.rb +32 -0
- data/lib/nokogiri/xml/node_set.rb +11 -20
- data/lib/nokogiri/xml/processing_instruction.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +5 -0
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +47 -0
- data/lib/nokogiri/xml/syntax_error.rb +3 -1
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- data/tasks/test.rb +136 -0
- data/test/css/test_parser.rb +4 -0
- data/test/css/test_tokenizer.rb +30 -17
- data/test/css/test_xpath_visitor.rb +11 -0
- data/test/helper.rb +11 -0
- data/test/hpricot/test_builder.rb +2 -9
- data/test/hpricot/test_parser.rb +4 -4
- data/test/html/test_builder.rb +7 -7
- data/test/html/test_document.rb +90 -4
- data/test/html/test_node.rb +1 -0
- data/test/test_css_cache.rb +1 -3
- data/test/test_reader.rb +19 -1
- data/test/test_xslt_transforms.rb +1 -1
- data/test/xml/node/test_save_options.rb +20 -0
- data/test/xml/sax/test_parser.rb +17 -0
- data/test/xml/sax/test_push_parser.rb +67 -0
- data/test/xml/test_attr.rb +16 -0
- data/test/xml/test_cdata.rb +1 -1
- data/test/xml/test_document.rb +45 -0
- data/test/xml/test_document_fragment.rb +18 -0
- data/test/xml/test_dtd.rb +2 -4
- data/test/xml/test_entity_reference.rb +16 -0
- data/test/xml/test_node.rb +149 -80
- data/test/xml/test_processing_instruction.rb +24 -0
- metadata +28 -2
data/ext/nokogiri/xml_node_set.c
CHANGED
@@ -110,7 +110,11 @@ VALUE Nokogiri_wrap_xml_node_set(xmlNodeSetPtr node_set)
|
|
110
110
|
VALUE cNokogiriXmlNodeSet ;
|
111
111
|
void init_xml_node_set(void)
|
112
112
|
{
|
113
|
-
VALUE
|
113
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
114
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
115
|
+
VALUE klass = rb_define_class_under(xml, "NodeSet", rb_cObject);
|
116
|
+
cNokogiriXmlNodeSet = klass;
|
117
|
+
|
114
118
|
rb_define_alloc_func(klass, allocate);
|
115
119
|
rb_define_method(klass, "length", length, 0);
|
116
120
|
rb_define_method(klass, "[]", index_at, 1);
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#include <xml_processing_instruction.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* new(document, name, content)
|
6
|
+
*
|
7
|
+
* Create a new ProcessingInstruction element on the +document+ with +name+
|
8
|
+
* and +content+
|
9
|
+
*/
|
10
|
+
static VALUE new(VALUE klass, VALUE doc, VALUE name, VALUE content)
|
11
|
+
{
|
12
|
+
xmlDocPtr xml_doc;
|
13
|
+
Data_Get_Struct(doc, xmlDoc, xml_doc);
|
14
|
+
|
15
|
+
xmlNodePtr node = xmlNewDocPI(
|
16
|
+
xml_doc,
|
17
|
+
(const xmlChar *)StringValuePtr(name),
|
18
|
+
(const xmlChar *)StringValuePtr(content)
|
19
|
+
);
|
20
|
+
|
21
|
+
VALUE rb_node = Nokogiri_wrap_xml_node(node);
|
22
|
+
|
23
|
+
if(rb_block_given_p()) rb_yield(rb_node);
|
24
|
+
|
25
|
+
return rb_node;
|
26
|
+
}
|
27
|
+
|
28
|
+
VALUE cNokogiriXmlProcessingInstruction;
|
29
|
+
void init_xml_processing_instruction()
|
30
|
+
{
|
31
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
32
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
33
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
34
|
+
|
35
|
+
/*
|
36
|
+
* ProcessingInstruction represents a ProcessingInstruction node in an xml
|
37
|
+
* document.
|
38
|
+
*/
|
39
|
+
VALUE klass = rb_define_class_under(xml, "ProcessingInstruction", node);
|
40
|
+
|
41
|
+
cNokogiriXmlProcessingInstruction = klass;
|
42
|
+
|
43
|
+
rb_define_singleton_method(klass, "new", new, 3);
|
44
|
+
}
|
data/ext/nokogiri/xml_reader.c
CHANGED
@@ -382,11 +382,24 @@ static VALUE read_more(VALUE self)
|
|
382
382
|
xmlTextReaderPtr reader;
|
383
383
|
Data_Get_Struct(self, xmlTextReader, reader);
|
384
384
|
|
385
|
+
VALUE error_list = rb_funcall(self, rb_intern("errors"), 0);
|
386
|
+
|
387
|
+
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
385
388
|
int ret = xmlTextReaderRead(reader);
|
389
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
390
|
+
|
386
391
|
if(ret == 1) return self;
|
387
392
|
if(ret == 0) return Qnil;
|
388
393
|
|
389
|
-
|
394
|
+
xmlErrorPtr error = xmlGetLastError();
|
395
|
+
if(error)
|
396
|
+
rb_funcall(rb_mKernel, rb_intern("raise"), 1,
|
397
|
+
Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error)
|
398
|
+
);
|
399
|
+
else
|
400
|
+
rb_raise(rb_eRuntimeError, "Error pulling: %d", ret);
|
401
|
+
|
402
|
+
return Qnil;
|
390
403
|
}
|
391
404
|
|
392
405
|
/*
|
@@ -407,12 +420,12 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
|
407
420
|
|
408
421
|
rb_buffer = StringValue(rb_buffer) ;
|
409
422
|
if (RTEST(rb_url)) c_url = StringValuePtr(rb_url);
|
410
|
-
if (RTEST(encoding)) c_encoding = StringValuePtr(
|
423
|
+
if (RTEST(encoding)) c_encoding = StringValuePtr(encoding);
|
411
424
|
if (RTEST(rb_options)) c_options = NUM2INT(rb_options);
|
412
425
|
|
413
426
|
xmlTextReaderPtr reader = xmlReaderForMemory(
|
414
427
|
StringValuePtr(rb_buffer),
|
415
|
-
|
428
|
+
RSTRING_LEN(rb_buffer),
|
416
429
|
c_url,
|
417
430
|
c_encoding,
|
418
431
|
c_options
|
@@ -423,7 +436,10 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
|
423
436
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
424
437
|
}
|
425
438
|
|
426
|
-
|
439
|
+
VALUE rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
|
440
|
+
rb_funcall(rb_reader, rb_intern("initialize"), 0);
|
441
|
+
|
442
|
+
return rb_reader;
|
427
443
|
}
|
428
444
|
|
429
445
|
VALUE cNokogiriXmlReader;
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#define _GNU_SOURCE
|
2
1
|
#include <stdio.h>
|
3
2
|
#include <xml_sax_parser.h>
|
4
3
|
|
@@ -15,7 +14,7 @@ static VALUE parse_memory(VALUE self, VALUE data)
|
|
15
14
|
xmlSAXUserParseMemory( handler,
|
16
15
|
(void *)self,
|
17
16
|
StringValuePtr(data),
|
18
|
-
|
17
|
+
RSTRING_LEN(data)
|
19
18
|
);
|
20
19
|
return data;
|
21
20
|
}
|
@@ -46,6 +45,12 @@ static VALUE native_parse_io(VALUE self, VALUE io, VALUE encoding)
|
|
46
45
|
return io;
|
47
46
|
}
|
48
47
|
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* native_parse_file(data)
|
51
|
+
*
|
52
|
+
* Parse the document stored in +data+
|
53
|
+
*/
|
49
54
|
static VALUE native_parse_file(VALUE self, VALUE data)
|
50
55
|
{
|
51
56
|
xmlSAXHandlerPtr handler;
|
@@ -116,7 +121,43 @@ static void comment_func(void * ctx, const xmlChar * value)
|
|
116
121
|
rb_funcall(doc, rb_intern("comment"), 1, str);
|
117
122
|
}
|
118
123
|
|
119
|
-
#
|
124
|
+
#ifdef XP_WIN
|
125
|
+
/*
|
126
|
+
* I srsly hate windows. it doesn't have vasprintf.
|
127
|
+
* This is stolen from here:
|
128
|
+
* http://eleves.ec-lille.fr/~couprieg/index.php?2008/06/17/39-first-issues-when-porting-an-application-on-windows-ce
|
129
|
+
* and slightly modified
|
130
|
+
*/
|
131
|
+
static inline int vasprintf(char **strp, const char *fmt, va_list ap) {
|
132
|
+
int n;
|
133
|
+
size_t size = 4096;
|
134
|
+
char *res, *np;
|
135
|
+
|
136
|
+
if ( (res = (char *) malloc(size)) == NULL )
|
137
|
+
return -1;
|
138
|
+
|
139
|
+
while (1) {
|
140
|
+
n = vsnprintf (res, size, fmt, ap);
|
141
|
+
/* If that worked, return the string. */
|
142
|
+
if (n > -1 && n < size) {
|
143
|
+
*strp = res;
|
144
|
+
return n;
|
145
|
+
}
|
146
|
+
|
147
|
+
/* Else try again with more space. */
|
148
|
+
if (n == -1)
|
149
|
+
size *= 2; /* twice the old size */
|
150
|
+
|
151
|
+
if ( (np = (char *) realloc(res, size)) == NULL ) {
|
152
|
+
free(res);
|
153
|
+
return -1;
|
154
|
+
} else {
|
155
|
+
res = np;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
#endif
|
160
|
+
|
120
161
|
static void warning_func(void * ctx, const char *msg, ...)
|
121
162
|
{
|
122
163
|
VALUE self = (VALUE)ctx;
|
@@ -131,9 +172,7 @@ static void warning_func(void * ctx, const char *msg, ...)
|
|
131
172
|
rb_funcall(doc, rb_intern("warning"), 1, rb_str_new2(message));
|
132
173
|
free(message);
|
133
174
|
}
|
134
|
-
#endif
|
135
175
|
|
136
|
-
#ifndef XP_WIN
|
137
176
|
static void error_func(void * ctx, const char *msg, ...)
|
138
177
|
{
|
139
178
|
VALUE self = (VALUE)ctx;
|
@@ -148,7 +187,6 @@ static void error_func(void * ctx, const char *msg, ...)
|
|
148
187
|
rb_funcall(doc, rb_intern("error"), 1, rb_str_new2(message));
|
149
188
|
free(message);
|
150
189
|
}
|
151
|
-
#endif
|
152
190
|
|
153
191
|
static void cdata_block(void * ctx, const xmlChar * value, int len)
|
154
192
|
{
|
@@ -175,15 +213,8 @@ static VALUE allocate(VALUE klass)
|
|
175
213
|
handler->endElement = end_element;
|
176
214
|
handler->characters = characters_func;
|
177
215
|
handler->comment = comment_func;
|
178
|
-
#ifndef XP_WIN
|
179
|
-
/*
|
180
|
-
* The va*functions aren't in ming, and I don't want to deal with
|
181
|
-
* it right now.....
|
182
|
-
*
|
183
|
-
*/
|
184
216
|
handler->warning = warning_func;
|
185
217
|
handler->error = error_func;
|
186
|
-
#endif
|
187
218
|
handler->cdataBlock = cdata_block;
|
188
219
|
|
189
220
|
return Data_Wrap_Struct(klass, NULL, deallocate, handler);
|
@@ -192,8 +223,13 @@ static VALUE allocate(VALUE klass)
|
|
192
223
|
VALUE cNokogiriXmlSaxParser ;
|
193
224
|
void init_xml_sax_parser()
|
194
225
|
{
|
195
|
-
VALUE
|
196
|
-
|
226
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
227
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
228
|
+
VALUE sax = rb_define_module_under(xml, "SAX");
|
229
|
+
VALUE klass = rb_define_class_under(sax, "Parser", rb_cObject);
|
230
|
+
|
231
|
+
cNokogiriXmlSaxParser = klass;
|
232
|
+
|
197
233
|
rb_define_alloc_func(klass, allocate);
|
198
234
|
rb_define_method(klass, "parse_memory", parse_memory, 1);
|
199
235
|
rb_define_private_method(klass, "native_parse_file", native_parse_file, 1);
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#include <xml_sax_push_parser.h>
|
2
|
+
|
3
|
+
static void deallocate(xmlParserCtxtPtr ctx)
|
4
|
+
{
|
5
|
+
NOKOGIRI_DEBUG_START(handler);
|
6
|
+
if(ctx != NULL) xmlFreeParserCtxt(ctx);
|
7
|
+
NOKOGIRI_DEBUG_END(handler);
|
8
|
+
}
|
9
|
+
|
10
|
+
static VALUE allocate(VALUE klass)
|
11
|
+
{
|
12
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, NULL);
|
13
|
+
}
|
14
|
+
|
15
|
+
/*
|
16
|
+
* call-seq:
|
17
|
+
* native_write(chunk, last_chunk)
|
18
|
+
*
|
19
|
+
* Write +chunk+ to PushParser. +last_chunk+ triggers the end_document handle
|
20
|
+
*/
|
21
|
+
static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
22
|
+
{
|
23
|
+
xmlParserCtxtPtr ctx;
|
24
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
25
|
+
|
26
|
+
const char * chunk = NULL;
|
27
|
+
int last_chunk = 0;
|
28
|
+
int size = 0;
|
29
|
+
|
30
|
+
if(Qnil != _chunk) {
|
31
|
+
chunk = StringValuePtr(_chunk);
|
32
|
+
size = RSTRING_LEN(_chunk);
|
33
|
+
}
|
34
|
+
if(Qtrue == _last_chunk) last_chunk = 1;
|
35
|
+
|
36
|
+
if(xmlParseChunk(ctx, chunk, size, last_chunk))
|
37
|
+
rb_raise(rb_eRuntimeError, "Couldn't parse chunk");
|
38
|
+
|
39
|
+
return self;
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* initialize_native(xml_sax, filename)
|
45
|
+
*
|
46
|
+
* Initialize the push parser with +xml_sax+ using +filename+
|
47
|
+
*/
|
48
|
+
static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
|
49
|
+
{
|
50
|
+
xmlSAXHandlerPtr sax;
|
51
|
+
|
52
|
+
Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
|
53
|
+
|
54
|
+
const char * filename = NULL;
|
55
|
+
|
56
|
+
if(_filename != Qnil) filename = StringValuePtr(_filename);
|
57
|
+
|
58
|
+
xmlParserCtxtPtr ctx = xmlCreatePushParserCtxt(
|
59
|
+
sax,
|
60
|
+
(void *)self,
|
61
|
+
NULL,
|
62
|
+
0,
|
63
|
+
filename
|
64
|
+
);
|
65
|
+
if(ctx == NULL)
|
66
|
+
rb_raise(rb_eRuntimeError, "Could not create a parser context");
|
67
|
+
|
68
|
+
DATA_PTR(self) = ctx;
|
69
|
+
return self;
|
70
|
+
}
|
71
|
+
|
72
|
+
VALUE cNokogiriXmlSaxPushParser ;
|
73
|
+
void init_xml_sax_push_parser()
|
74
|
+
{
|
75
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
76
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
77
|
+
VALUE sax = rb_define_module_under(xml, "SAX");
|
78
|
+
VALUE klass = rb_define_class_under(sax, "PushParser", rb_cObject);
|
79
|
+
|
80
|
+
cNokogiriXmlSaxPushParser = klass;
|
81
|
+
|
82
|
+
rb_define_alloc_func(klass, allocate);
|
83
|
+
rb_define_private_method(klass, "initialize_native", initialize_native, 2);
|
84
|
+
rb_define_private_method(klass, "native_write", native_write, 2);
|
85
|
+
}
|
@@ -160,17 +160,20 @@ static VALUE message(VALUE self)
|
|
160
160
|
return rb_str_new2(error->message);
|
161
161
|
}
|
162
162
|
|
163
|
-
void
|
163
|
+
void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error)
|
164
164
|
{
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
VALUE list = (VALUE)ctx;
|
166
|
+
rb_ary_push(list, Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
|
167
|
+
}
|
168
|
+
|
169
|
+
VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error)
|
170
|
+
{
|
171
|
+
if(!klass) klass = cNokogiriXmlSyntaxError;
|
172
|
+
|
168
173
|
xmlErrorPtr ptr = calloc(1, sizeof(xmlError));
|
169
174
|
xmlCopyError(error, ptr);
|
170
175
|
|
171
|
-
|
172
|
-
VALUE block = rb_funcall(mNokogiri, rb_intern("error_handler"), 0);
|
173
|
-
rb_funcall(block, rb_intern("call"), 1, err);
|
176
|
+
return Data_Wrap_Struct(klass, NULL, dealloc, ptr);
|
174
177
|
}
|
175
178
|
|
176
179
|
VALUE cNokogiriXmlSyntaxError;
|
@@ -182,7 +185,8 @@ void init_xml_syntax_error()
|
|
182
185
|
/*
|
183
186
|
* The XML::SyntaxError is raised on parse errors
|
184
187
|
*/
|
185
|
-
VALUE
|
188
|
+
VALUE syntax_error_mommy = rb_define_class_under(nokogiri, "SyntaxError", rb_eStandardError);
|
189
|
+
VALUE klass = rb_define_class_under(xml, "SyntaxError", syntax_error_mommy);
|
186
190
|
cNokogiriXmlSyntaxError = klass;
|
187
191
|
|
188
192
|
rb_define_method(klass, "message", message, 0);
|
@@ -4,7 +4,8 @@
|
|
4
4
|
#include <native.h>
|
5
5
|
|
6
6
|
void init_xml_syntax_error();
|
7
|
-
|
7
|
+
VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error);
|
8
|
+
void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error);
|
8
9
|
|
9
10
|
extern VALUE cNokogiriXmlSyntaxError;
|
10
11
|
#endif
|
@@ -139,6 +139,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
139
139
|
VALUE search_path, xpath_handler;
|
140
140
|
xmlXPathContextPtr ctx;
|
141
141
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
142
|
+
VALUE error_list = rb_ary_new();
|
142
143
|
|
143
144
|
if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1)
|
144
145
|
xpath_handler = Qnil;
|
@@ -151,11 +152,19 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
151
152
|
xmlXPathRegisterFuncLookup(ctx, lookup, (void *)xpath_handler);
|
152
153
|
}
|
153
154
|
|
155
|
+
xmlResetLastError();
|
156
|
+
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
154
157
|
xmlXPathObjectPtr xpath = xmlXPathEvalExpression(query, ctx);
|
158
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
159
|
+
|
155
160
|
if(xpath == NULL) {
|
156
161
|
VALUE xpath = rb_const_get(mNokogiriXml, rb_intern("XPath"));
|
157
|
-
VALUE
|
158
|
-
|
162
|
+
VALUE klass = rb_const_get(xpath, rb_intern("SyntaxError"));
|
163
|
+
|
164
|
+
xmlErrorPtr error = xmlGetLastError();
|
165
|
+
rb_funcall(rb_mKernel, rb_intern("raise"), 1,
|
166
|
+
Nokogiri_wrap_xml_syntax_error(klass, error)
|
167
|
+
);
|
159
168
|
}
|
160
169
|
|
161
170
|
VALUE xpath_object = Nokogiri_wrap_xml_xpath(xpath);
|
@@ -105,16 +105,11 @@ static VALUE apply_to(int argc, VALUE* argv, VALUE self)
|
|
105
105
|
VALUE cNokogiriXsltStylesheet ;
|
106
106
|
void init_xslt_stylesheet()
|
107
107
|
{
|
108
|
-
/*
|
109
|
-
* HACK. This is so that rdoc will work with this C file.
|
110
|
-
*/
|
111
|
-
/*
|
112
108
|
VALUE nokogiri = rb_define_module("Nokogiri");
|
113
109
|
VALUE xslt = rb_define_module_under(nokogiri, "XSLT");
|
114
110
|
VALUE klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
|
115
|
-
*/
|
116
111
|
|
117
|
-
|
112
|
+
cNokogiriXsltStylesheet = klass;
|
118
113
|
|
119
114
|
rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
|
120
115
|
rb_define_method(klass, "serialize", serialize, 1);
|
data/lib/nokogiri.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
+
# Modify the PATH on windows so that the external DLLs will get loaded.
|
2
|
+
ENV['PATH'] = [File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
|
4
|
+
), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /mswin/i
|
5
|
+
|
6
|
+
require 'nokogiri/native' unless RUBY_PLATFORM =~ /java/
|
7
|
+
|
1
8
|
require 'nokogiri/version'
|
9
|
+
require 'nokogiri/syntax_error'
|
2
10
|
require 'nokogiri/xml'
|
3
11
|
require 'nokogiri/xslt'
|
4
12
|
require 'nokogiri/html'
|
@@ -7,17 +15,8 @@ require 'nokogiri/css'
|
|
7
15
|
require 'nokogiri/html/builder'
|
8
16
|
require 'nokogiri/hpricot'
|
9
17
|
|
10
|
-
# Modify the PATH on windows so that the external DLLs will get loaded.
|
11
|
-
ENV['PATH'] = [File.expand_path(
|
12
|
-
File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
|
13
|
-
), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /mswin/i
|
14
|
-
|
15
|
-
require 'nokogiri/native' unless RUBY_PLATFORM =~ /java/
|
16
|
-
|
17
18
|
module Nokogiri
|
18
19
|
class << self
|
19
|
-
attr_accessor :error_handler
|
20
|
-
|
21
20
|
###
|
22
21
|
# Parse an HTML or XML document. +string+ contains the document.
|
23
22
|
def parse string, url = nil, encoding = nil, options = nil
|
@@ -33,7 +32,7 @@ module Nokogiri
|
|
33
32
|
|
34
33
|
def make input = nil, opts = {}, &blk
|
35
34
|
if input
|
36
|
-
Nokogiri::
|
35
|
+
Nokogiri::HTML.fragment(input).children.first
|
37
36
|
else
|
38
37
|
Nokogiri(&blk)
|
39
38
|
end
|
@@ -58,14 +57,12 @@ module Nokogiri
|
|
58
57
|
Nokogiri(*args, &block).slop!
|
59
58
|
end
|
60
59
|
end
|
61
|
-
|
62
|
-
self.error_handler = lambda { |syntax_error| }
|
63
60
|
end
|
64
61
|
|
65
62
|
def Nokogiri(*args, &block)
|
66
63
|
if block_given?
|
67
64
|
builder = Nokogiri::HTML::Builder.new(&block)
|
68
|
-
return builder.doc
|
65
|
+
return builder.doc.root
|
69
66
|
else
|
70
67
|
Nokogiri.parse(*args)
|
71
68
|
end
|