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_relax_ng.c
CHANGED
@@ -17,16 +17,18 @@ static VALUE validate_document(VALUE self, VALUE document)
|
|
17
17
|
{
|
18
18
|
xmlDocPtr doc;
|
19
19
|
xmlRelaxNGPtr schema;
|
20
|
+
VALUE errors;
|
21
|
+
xmlRelaxNGValidCtxtPtr valid_ctxt;
|
20
22
|
|
21
23
|
Data_Get_Struct(self, xmlRelaxNG, schema);
|
22
24
|
Data_Get_Struct(document, xmlDoc, doc);
|
23
25
|
|
24
|
-
|
26
|
+
errors = rb_ary_new();
|
25
27
|
|
26
|
-
|
28
|
+
valid_ctxt = xmlRelaxNGNewValidCtxt(schema);
|
27
29
|
|
28
30
|
if(NULL == valid_ctxt) {
|
29
|
-
|
31
|
+
/* we have a problem */
|
30
32
|
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
31
33
|
}
|
32
34
|
|
@@ -55,10 +57,12 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
55
57
|
{
|
56
58
|
xmlRelaxNGParserCtxtPtr ctx = xmlRelaxNGNewMemParserCtxt(
|
57
59
|
(const char *)StringValuePtr(content),
|
58
|
-
RSTRING_LEN(content)
|
60
|
+
(int)RSTRING_LEN(content)
|
59
61
|
);
|
60
|
-
|
62
|
+
xmlRelaxNGPtr schema;
|
61
63
|
VALUE errors = rb_ary_new();
|
64
|
+
VALUE rb_schema;
|
65
|
+
|
62
66
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
63
67
|
|
64
68
|
#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
|
@@ -69,7 +73,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
69
73
|
);
|
70
74
|
#endif
|
71
75
|
|
72
|
-
|
76
|
+
schema = xmlRelaxNGParse(ctx);
|
73
77
|
|
74
78
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
75
79
|
xmlRelaxNGFreeParserCtxt(ctx);
|
@@ -84,7 +88,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
84
88
|
return Qnil;
|
85
89
|
}
|
86
90
|
|
87
|
-
|
91
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
88
92
|
rb_iv_set(rb_schema, "@errors", errors);
|
89
93
|
|
90
94
|
return rb_schema;
|
@@ -99,14 +103,19 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
99
103
|
static VALUE from_document(VALUE klass, VALUE document)
|
100
104
|
{
|
101
105
|
xmlDocPtr doc;
|
106
|
+
xmlRelaxNGParserCtxtPtr ctx;
|
107
|
+
xmlRelaxNGPtr schema;
|
108
|
+
VALUE errors;
|
109
|
+
VALUE rb_schema;
|
110
|
+
|
102
111
|
Data_Get_Struct(document, xmlDoc, doc);
|
103
112
|
|
104
|
-
|
113
|
+
/* In case someone passes us a node. ugh. */
|
105
114
|
doc = doc->doc;
|
106
115
|
|
107
|
-
|
116
|
+
ctx = xmlRelaxNGNewDocParserCtxt(doc);
|
108
117
|
|
109
|
-
|
118
|
+
errors = rb_ary_new();
|
110
119
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
111
120
|
|
112
121
|
#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
|
@@ -117,7 +126,7 @@ static VALUE from_document(VALUE klass, VALUE document)
|
|
117
126
|
);
|
118
127
|
#endif
|
119
128
|
|
120
|
-
|
129
|
+
schema = xmlRelaxNGParse(ctx);
|
121
130
|
|
122
131
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
123
132
|
if (! is_2_6_16()) {
|
@@ -138,7 +147,7 @@ static VALUE from_document(VALUE klass, VALUE document)
|
|
138
147
|
xmlRelaxNGFreeParserCtxt(ctx);
|
139
148
|
}
|
140
149
|
|
141
|
-
|
150
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
142
151
|
rb_iv_set(rb_schema, "@errors", errors);
|
143
152
|
|
144
153
|
return rb_schema;
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#include <xml_sax_parser.h>
|
2
2
|
|
3
|
+
int vasprintf (char **strp, const char *fmt, va_list ap);
|
4
|
+
|
3
5
|
static ID id_start_document, id_end_document, id_start_element, id_end_element;
|
4
6
|
static ID id_start_element_namespace, id_end_element_namespace;
|
5
7
|
static ID id_comment, id_characters, id_xmldecl, id_error, id_warning;
|
@@ -16,7 +18,7 @@ static void start_document(void * ctx)
|
|
16
18
|
xmlParserCtxtPtr ctxt = NOKOGIRI_SAX_CTXT(ctx);
|
17
19
|
|
18
20
|
if(NULL != ctxt && ctxt->html != 1) {
|
19
|
-
if(ctxt->standalone != -1) {
|
21
|
+
if(ctxt->standalone != -1) { /* -1 means there was no declaration */
|
20
22
|
VALUE encoding = ctxt->encoding ?
|
21
23
|
NOKOGIRI_STR_NEW2(ctxt->encoding) :
|
22
24
|
Qnil;
|
@@ -92,7 +94,8 @@ static VALUE attributes_as_list(
|
|
92
94
|
/* Each attribute is an array of [localname, prefix, URI, value, end] */
|
93
95
|
int i;
|
94
96
|
for (i = 0; i < nb_attributes * 5; i += 5) {
|
95
|
-
VALUE argv[4];
|
97
|
+
VALUE argv[4], attribute;
|
98
|
+
|
96
99
|
argv[0] = RBSTR_OR_QNIL(attributes[i + 0]); /* localname */
|
97
100
|
argv[1] = RBSTR_OR_QNIL(attributes[i + 1]); /* prefix */
|
98
101
|
argv[2] = RBSTR_OR_QNIL(attributes[i + 2]); /* URI */
|
@@ -101,7 +104,7 @@ static VALUE attributes_as_list(
|
|
101
104
|
argv[3] = NOKOGIRI_STR_NEW((const char*)attributes[i+3],
|
102
105
|
(attributes[i+4] - attributes[i+3]));
|
103
106
|
|
104
|
-
|
107
|
+
attribute = rb_class_new_instance(4, argv, attr_klass);
|
105
108
|
rb_ary_push(list, attribute);
|
106
109
|
}
|
107
110
|
}
|
@@ -15,29 +15,25 @@ typedef struct _nokogiriSAXTuple {
|
|
15
15
|
typedef nokogiriSAXTuple * nokogiriSAXTuplePtr;
|
16
16
|
|
17
17
|
#define NOKOGIRI_SAX_SELF(_ctxt) \
|
18
|
-
(
|
19
|
-
nokogiriSAXTuplePtr _tuple = (nokogiriSAXTuplePtr)(_ctxt); \
|
20
|
-
_tuple->self; \
|
21
|
-
})
|
18
|
+
((nokogiriSAXTuplePtr)(_ctxt))->self
|
22
19
|
|
23
20
|
#define NOKOGIRI_SAX_CTXT(_ctxt) \
|
24
|
-
(
|
25
|
-
nokogiriSAXTuplePtr _tuple = (nokogiriSAXTuplePtr)(_ctxt); \
|
26
|
-
_tuple->ctxt; \
|
27
|
-
})
|
21
|
+
((nokogiriSAXTuplePtr)(_ctxt))->ctxt
|
28
22
|
|
29
23
|
#define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) \
|
30
|
-
(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
nokogiri_sax_tuple_new(_ctxt, _self)
|
25
|
+
|
26
|
+
static inline nokogiriSAXTuplePtr
|
27
|
+
nokogiri_sax_tuple_new(xmlParserCtxtPtr ctxt, VALUE self)
|
28
|
+
{
|
29
|
+
nokogiriSAXTuplePtr tuple = malloc(sizeof(nokogiriSAXTuple));
|
30
|
+
tuple->self = self;
|
31
|
+
tuple->ctxt = ctxt;
|
32
|
+
return tuple;
|
33
|
+
}
|
36
34
|
|
37
35
|
#define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) \
|
38
|
-
(
|
39
|
-
free(_tuple); \
|
40
|
-
})
|
36
|
+
free(_tuple) \
|
41
37
|
|
42
38
|
#endif
|
43
39
|
|
@@ -21,7 +21,7 @@ static void deallocate(xmlParserCtxtPtr ctxt)
|
|
21
21
|
*/
|
22
22
|
static VALUE parse_io(VALUE klass, VALUE io, VALUE encoding)
|
23
23
|
{
|
24
|
-
xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
|
24
|
+
xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
|
25
25
|
|
26
26
|
xmlParserCtxtPtr ctxt = xmlCreateIOParserCtxt(
|
27
27
|
NULL,
|
@@ -55,11 +55,13 @@ static VALUE parse_file(VALUE klass, VALUE filename)
|
|
55
55
|
*/
|
56
56
|
static VALUE parse_memory(VALUE klass, VALUE data)
|
57
57
|
{
|
58
|
+
xmlParserCtxtPtr ctxt;
|
59
|
+
|
58
60
|
if(NIL_P(data)) rb_raise(rb_eArgError, "data cannot be nil");
|
59
61
|
if(!(int)RSTRING_LEN(data))
|
60
62
|
rb_raise(rb_eRuntimeError, "data cannot be empty");
|
61
63
|
|
62
|
-
|
64
|
+
ctxt = xmlCreateMemoryParserCtxt(
|
63
65
|
StringValuePtr(data),
|
64
66
|
(int)RSTRING_LEN(data)
|
65
67
|
);
|
@@ -75,16 +77,16 @@ static VALUE parse_memory(VALUE klass, VALUE data)
|
|
75
77
|
*/
|
76
78
|
static VALUE parse_with(VALUE self, VALUE sax_handler)
|
77
79
|
{
|
80
|
+
xmlParserCtxtPtr ctxt;
|
81
|
+
xmlSAXHandlerPtr sax;
|
82
|
+
|
78
83
|
if(!rb_obj_is_kind_of(sax_handler, cNokogiriXmlSaxParser))
|
79
84
|
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
|
80
85
|
|
81
|
-
xmlParserCtxtPtr ctxt;
|
82
86
|
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
83
|
-
|
84
|
-
xmlSAXHandlerPtr sax;
|
85
87
|
Data_Get_Struct(sax_handler, xmlSAXHandler, sax);
|
86
88
|
|
87
|
-
|
89
|
+
/* Free the sax handler since we'll assign our own */
|
88
90
|
if(ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler)
|
89
91
|
xmlFree(ctxt->sax);
|
90
92
|
|
@@ -24,14 +24,15 @@ static VALUE allocate(VALUE klass)
|
|
24
24
|
static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
25
25
|
{
|
26
26
|
xmlParserCtxtPtr ctx;
|
27
|
-
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
28
|
-
|
29
27
|
const char * chunk = NULL;
|
30
28
|
int size = 0;
|
31
29
|
|
30
|
+
|
31
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
32
|
+
|
32
33
|
if(Qnil != _chunk) {
|
33
34
|
chunk = StringValuePtr(_chunk);
|
34
|
-
size = RSTRING_LEN(_chunk);
|
35
|
+
size = (int)RSTRING_LEN(_chunk);
|
35
36
|
}
|
36
37
|
|
37
38
|
if(xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
|
@@ -53,14 +54,14 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
|
53
54
|
static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
|
54
55
|
{
|
55
56
|
xmlSAXHandlerPtr sax;
|
57
|
+
const char * filename = NULL;
|
58
|
+
xmlParserCtxtPtr ctx;
|
56
59
|
|
57
60
|
Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
|
58
61
|
|
59
|
-
const char * filename = NULL;
|
60
|
-
|
61
62
|
if(_filename != Qnil) filename = StringValuePtr(_filename);
|
62
63
|
|
63
|
-
|
64
|
+
ctx = xmlCreatePushParserCtxt(
|
64
65
|
sax,
|
65
66
|
NULL,
|
66
67
|
NULL,
|
data/ext/nokogiri/xml_schema.c
CHANGED
@@ -17,16 +17,18 @@ static VALUE validate_document(VALUE self, VALUE document)
|
|
17
17
|
{
|
18
18
|
xmlDocPtr doc;
|
19
19
|
xmlSchemaPtr schema;
|
20
|
+
xmlSchemaValidCtxtPtr valid_ctxt;
|
21
|
+
VALUE errors;
|
20
22
|
|
21
23
|
Data_Get_Struct(self, xmlSchema, schema);
|
22
24
|
Data_Get_Struct(document, xmlDoc, doc);
|
23
25
|
|
24
|
-
|
26
|
+
errors = rb_ary_new();
|
25
27
|
|
26
|
-
|
28
|
+
valid_ctxt = xmlSchemaNewValidCtxt(schema);
|
27
29
|
|
28
30
|
if(NULL == valid_ctxt) {
|
29
|
-
|
31
|
+
/* we have a problem */
|
30
32
|
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
31
33
|
}
|
32
34
|
|
@@ -45,6 +47,46 @@ static VALUE validate_document(VALUE self, VALUE document)
|
|
45
47
|
return errors;
|
46
48
|
}
|
47
49
|
|
50
|
+
/*
|
51
|
+
* call-seq:
|
52
|
+
* validate_file(filename)
|
53
|
+
*
|
54
|
+
* Validate a file against this Schema.
|
55
|
+
*/
|
56
|
+
static VALUE validate_file(VALUE self, VALUE rb_filename)
|
57
|
+
{
|
58
|
+
xmlSchemaPtr schema;
|
59
|
+
xmlSchemaValidCtxtPtr valid_ctxt;
|
60
|
+
const char *filename ;
|
61
|
+
VALUE errors;
|
62
|
+
|
63
|
+
Data_Get_Struct(self, xmlSchema, schema);
|
64
|
+
filename = (const char*)StringValuePtr(rb_filename) ;
|
65
|
+
|
66
|
+
errors = rb_ary_new();
|
67
|
+
|
68
|
+
valid_ctxt = xmlSchemaNewValidCtxt(schema);
|
69
|
+
|
70
|
+
if(NULL == valid_ctxt) {
|
71
|
+
/* we have a problem */
|
72
|
+
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
73
|
+
}
|
74
|
+
|
75
|
+
#ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
|
76
|
+
xmlSchemaSetValidStructuredErrors(
|
77
|
+
valid_ctxt,
|
78
|
+
Nokogiri_error_array_pusher,
|
79
|
+
(void *)errors
|
80
|
+
);
|
81
|
+
#endif
|
82
|
+
|
83
|
+
xmlSchemaValidateFile(valid_ctxt, filename, 0);
|
84
|
+
|
85
|
+
xmlSchemaFreeValidCtxt(valid_ctxt);
|
86
|
+
|
87
|
+
return errors;
|
88
|
+
}
|
89
|
+
|
48
90
|
/*
|
49
91
|
* call-seq:
|
50
92
|
* read_memory(string)
|
@@ -53,12 +95,12 @@ static VALUE validate_document(VALUE self, VALUE document)
|
|
53
95
|
*/
|
54
96
|
static VALUE read_memory(VALUE klass, VALUE content)
|
55
97
|
{
|
56
|
-
|
98
|
+
xmlSchemaPtr schema;
|
57
99
|
xmlSchemaParserCtxtPtr ctx = xmlSchemaNewMemParserCtxt(
|
58
100
|
(const char *)StringValuePtr(content),
|
59
|
-
RSTRING_LEN(content)
|
101
|
+
(int)RSTRING_LEN(content)
|
60
102
|
);
|
61
|
-
|
103
|
+
VALUE rb_schema;
|
62
104
|
VALUE errors = rb_ary_new();
|
63
105
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
64
106
|
|
@@ -70,7 +112,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
70
112
|
);
|
71
113
|
#endif
|
72
114
|
|
73
|
-
|
115
|
+
schema = xmlSchemaParse(ctx);
|
74
116
|
|
75
117
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
76
118
|
xmlSchemaFreeParserCtxt(ctx);
|
@@ -85,7 +127,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
85
127
|
return Qnil;
|
86
128
|
}
|
87
129
|
|
88
|
-
|
130
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
89
131
|
rb_iv_set(rb_schema, "@errors", errors);
|
90
132
|
|
91
133
|
return rb_schema;
|
@@ -100,14 +142,19 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
100
142
|
static VALUE from_document(VALUE klass, VALUE document)
|
101
143
|
{
|
102
144
|
xmlDocPtr doc;
|
145
|
+
xmlSchemaParserCtxtPtr ctx;
|
146
|
+
xmlSchemaPtr schema;
|
147
|
+
VALUE errors;
|
148
|
+
VALUE rb_schema;
|
149
|
+
|
103
150
|
Data_Get_Struct(document, xmlDoc, doc);
|
104
151
|
|
105
|
-
|
152
|
+
/* In case someone passes us a node. ugh. */
|
106
153
|
doc = doc->doc;
|
107
154
|
|
108
|
-
|
155
|
+
ctx = xmlSchemaNewDocParserCtxt(doc);
|
109
156
|
|
110
|
-
|
157
|
+
errors = rb_ary_new();
|
111
158
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
112
159
|
|
113
160
|
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
|
@@ -118,7 +165,7 @@ static VALUE from_document(VALUE klass, VALUE document)
|
|
118
165
|
);
|
119
166
|
#endif
|
120
167
|
|
121
|
-
|
168
|
+
schema = xmlSchemaParse(ctx);
|
122
169
|
|
123
170
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
124
171
|
xmlSchemaFreeParserCtxt(ctx);
|
@@ -133,7 +180,7 @@ static VALUE from_document(VALUE klass, VALUE document)
|
|
133
180
|
return Qnil;
|
134
181
|
}
|
135
182
|
|
136
|
-
|
183
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
137
184
|
rb_iv_set(rb_schema, "@errors", errors);
|
138
185
|
|
139
186
|
return rb_schema;
|
@@ -152,5 +199,7 @@ void init_xml_schema()
|
|
152
199
|
|
153
200
|
rb_define_singleton_method(klass, "read_memory", read_memory, 1);
|
154
201
|
rb_define_singleton_method(klass, "from_document", from_document, 1);
|
202
|
+
|
155
203
|
rb_define_private_method(klass, "validate_document", validate_document, 1);
|
204
|
+
rb_define_private_method(klass, "validate_file", validate_file, 1);
|
156
205
|
}
|
@@ -13,25 +13,31 @@ void Nokogiri_error_raise(void * ctx, xmlErrorPtr error)
|
|
13
13
|
|
14
14
|
VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error)
|
15
15
|
{
|
16
|
+
VALUE msg, e;
|
17
|
+
|
16
18
|
if(!klass) klass = cNokogiriXmlSyntaxError;
|
17
19
|
|
18
|
-
|
20
|
+
msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
|
19
21
|
|
20
|
-
|
22
|
+
e = rb_class_new_instance(
|
21
23
|
1,
|
22
24
|
&msg,
|
23
25
|
klass
|
24
26
|
);
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
|
28
|
+
if (error)
|
29
|
+
{
|
30
|
+
rb_iv_set(e, "@domain", INT2NUM(error->domain));
|
31
|
+
rb_iv_set(e, "@code", INT2NUM(error->code));
|
32
|
+
rb_iv_set(e, "@level", INT2NUM((short)error->level));
|
33
|
+
rb_iv_set(e, "@file", RBSTR_OR_QNIL(error->file));
|
34
|
+
rb_iv_set(e, "@line", INT2NUM(error->line));
|
35
|
+
rb_iv_set(e, "@str1", RBSTR_OR_QNIL(error->str1));
|
36
|
+
rb_iv_set(e, "@str2", RBSTR_OR_QNIL(error->str2));
|
37
|
+
rb_iv_set(e, "@str3", RBSTR_OR_QNIL(error->str3));
|
38
|
+
rb_iv_set(e, "@int1", INT2NUM(error->int1));
|
39
|
+
rb_iv_set(e, "@column", INT2NUM(error->int2));
|
40
|
+
}
|
35
41
|
|
36
42
|
return e;
|
37
43
|
}
|
@@ -6,7 +6,7 @@
|
|
6
6
|
void init_xml_syntax_error();
|
7
7
|
VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error);
|
8
8
|
void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error);
|
9
|
-
void Nokogiri_error_raise(void * ctx, xmlErrorPtr error);
|
9
|
+
NORETURN(void Nokogiri_error_raise(void * ctx, xmlErrorPtr error));
|
10
10
|
|
11
11
|
extern VALUE cNokogiriXmlSyntaxError;
|
12
12
|
#endif
|