libxml-ruby 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +53 -0
- data/Rakefile +1 -0
- data/ext/libxml/build.log +4 -0
- data/ext/libxml/cbg.c +86 -86
- data/ext/libxml/libxml.c +878 -876
- data/ext/libxml/ruby_libxml.h +8 -4
- data/ext/libxml/ruby_xml_attr.c +36 -168
- data/ext/libxml/ruby_xml_attr.h +2 -4
- data/ext/libxml/ruby_xml_attr_decl.c +177 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +29 -20
- data/ext/libxml/ruby_xml_document.c +895 -898
- data/ext/libxml/ruby_xml_dtd.c +18 -1
- data/ext/libxml/ruby_xml_dtd.h +1 -0
- data/ext/libxml/ruby_xml_encoding.c +116 -0
- data/ext/libxml/ruby_xml_encoding.h +12 -0
- data/ext/libxml/ruby_xml_error.c +8 -2
- data/ext/libxml/ruby_xml_html_parser.c +53 -74
- data/ext/libxml/ruby_xml_html_parser.h +2 -3
- data/ext/libxml/ruby_xml_html_parser_context.c +145 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +48 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +1 -1
- data/ext/libxml/ruby_xml_io.c +30 -0
- data/ext/libxml/ruby_xml_io.h +9 -0
- data/ext/libxml/ruby_xml_namespace.c +34 -16
- data/ext/libxml/ruby_xml_namespace.h +2 -2
- data/ext/libxml/ruby_xml_namespaces.c +6 -6
- data/ext/libxml/ruby_xml_node.c +1367 -1324
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_parser.c +26 -78
- data/ext/libxml/ruby_xml_parser.h +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +284 -13
- data/ext/libxml/ruby_xml_parser_context.h +1 -2
- data/ext/libxml/ruby_xml_parser_options.c +75 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +277 -183
- data/ext/libxml/ruby_xml_sax_parser.c +60 -57
- data/ext/libxml/ruby_xml_xpath_context.c +43 -8
- data/ext/libxml/ruby_xml_xpath_expression.c +6 -0
- data/ext/libxml/ruby_xml_xpath_object.c +107 -95
- data/ext/libxml/ruby_xml_xpath_object.h +9 -1
- data/ext/libxml/ruby_xml_xpointer.c +107 -107
- data/ext/libxml/version.h +2 -2
- data/ext/vc/libxml_ruby.vcproj +43 -3
- data/lib/libxml.rb +2 -3
- data/lib/libxml/attr.rb +71 -2
- data/lib/libxml/attr_decl.rb +81 -0
- data/lib/libxml/document.rb +78 -14
- data/lib/libxml/html_parser.rb +75 -42
- data/lib/libxml/node.rb +11 -0
- data/lib/libxml/parser.rb +106 -62
- data/lib/libxml/reader.rb +12 -0
- data/lib/libxml/sax_parser.rb +42 -52
- data/lib/libxml/xpath_object.rb +15 -0
- data/test/model/atom.xml +12 -12
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +146 -147
- data/test/model/merge_bug_data.xml +1 -1
- data/test/model/rubynet.xml +1 -0
- data/test/model/shiporder.rng +1 -1
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +30 -30
- data/test/model/xinclude.xml +1 -1
- data/test/{tc_node_attr.rb → tc_attr.rb} +1 -1
- data/test/tc_attr_decl.rb +131 -0
- data/test/tc_deprecated_require.rb +1 -3
- data/test/tc_document.rb +13 -3
- data/test/tc_document_write.rb +5 -5
- data/test/tc_dtd.rb +13 -5
- data/test/tc_html_parser.rb +14 -26
- data/test/tc_node_cdata.rb +1 -3
- data/test/tc_node_comment.rb +2 -4
- data/test/tc_node_edit.rb +2 -3
- data/test/tc_node_text.rb +35 -1
- data/test/tc_node_write.rb +3 -3
- data/test/tc_node_xlink.rb +2 -4
- data/test/tc_parser.rb +163 -70
- data/test/tc_parser_context.rb +103 -42
- data/test/tc_reader.rb +173 -45
- data/test/tc_relaxng.rb +2 -2
- data/test/tc_sax_parser.rb +48 -52
- data/test/tc_schema.rb +2 -2
- data/test/tc_xpath.rb +37 -6
- data/test/tc_xpath_context.rb +7 -1
- data/test/tc_xpath_expression.rb +1 -3
- data/test/tc_xpointer.rb +1 -3
- data/test/test_suite.rb +2 -3
- metadata +20 -13
- data/ext/libxml/ruby_xml_input.c +0 -329
- data/ext/libxml/ruby_xml_input.h +0 -20
- data/lib/libxml/parser_context.rb +0 -17
- data/lib/libxml/parser_options.rb +0 -25
- data/test/model/simple.xml +0 -7
- data/test/tc_input.rb +0 -13
- data/test/tc_well_formed.rb +0 -11
data/ext/libxml/ruby_xml_node.h
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_node.h
|
1
|
+
/* $Id: ruby_xml_node.h 693 2008-12-13 22:53:32Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -9,6 +9,6 @@ extern VALUE cXMLNode;
|
|
9
9
|
|
10
10
|
void ruby_init_xml_node(void);
|
11
11
|
void rxml_node_mark_common(xmlNodePtr xnode);
|
12
|
-
VALUE rxml_node_wrap(
|
12
|
+
VALUE rxml_node_wrap(xmlNodePtr xnode);
|
13
13
|
VALUE check_string_or_symbol(VALUE val);
|
14
14
|
#endif
|
@@ -1,14 +1,10 @@
|
|
1
|
-
/* $Id: ruby_xml_parser.c
|
1
|
+
/* $Id: ruby_xml_parser.c 737 2009-01-23 01:23:08Z walltndr $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
5
5
|
#include <stdarg.h>
|
6
6
|
#include "ruby_libxml.h"
|
7
7
|
|
8
|
-
VALUE cXMLParser;
|
9
|
-
static ID INPUT_ATTR;
|
10
|
-
static ID CONTEXT_ATTR;
|
11
|
-
|
12
8
|
/*
|
13
9
|
* Document-class: LibXML::XML::Parser
|
14
10
|
*
|
@@ -24,71 +20,43 @@ static ID CONTEXT_ATTR;
|
|
24
20
|
*
|
25
21
|
* Using the parser is simple:
|
26
22
|
*
|
27
|
-
* parser = XML::Parser.
|
28
|
-
* parser.file = 'my_file'
|
23
|
+
* parser = XML::Parser.file('my_file')
|
29
24
|
* doc = parser.parse
|
30
25
|
*
|
31
|
-
* You can also parse
|
26
|
+
* You can also parse documents (see XML::Parser.document),
|
27
|
+
* strings (see XML::Parser.string) and io objects (see
|
32
28
|
* XML::Parser.io).
|
33
29
|
*/
|
34
30
|
|
31
|
+
VALUE cXMLParser;
|
32
|
+
static ID CONTEXT_ATTR;
|
33
|
+
|
35
34
|
/*
|
36
35
|
* call-seq:
|
37
|
-
* parser.initialize ->
|
36
|
+
* parser.initialize(context) -> XML::Parser
|
38
37
|
*
|
39
|
-
*
|
38
|
+
* Creates a new XML::Parser from the specified
|
39
|
+
* XML::Parser::Context.
|
40
40
|
*/
|
41
|
-
static VALUE rxml_parser_initialize(VALUE self)
|
41
|
+
static VALUE rxml_parser_initialize(int argc, VALUE *argv, VALUE self)
|
42
42
|
{
|
43
|
-
VALUE
|
44
|
-
rb_iv_set(self, "@input", input);
|
45
|
-
rb_iv_set(self, "@context", Qnil);
|
46
|
-
return self;
|
47
|
-
}
|
43
|
+
VALUE context = Qnil;
|
48
44
|
|
49
|
-
|
50
|
-
{
|
51
|
-
xmlParserCtxtPtr ctxt;
|
52
|
-
int retry_count = 0;
|
53
|
-
VALUE filename = rb_ivar_get(input, FILE_ATTR);
|
45
|
+
rb_scan_args(argc, argv, "01", &context);
|
54
46
|
|
55
|
-
|
56
|
-
if (ctxt == NULL)
|
47
|
+
if (context == Qnil)
|
57
48
|
{
|
58
|
-
|
59
|
-
|
60
|
-
retry_count++;
|
61
|
-
rb_gc();
|
62
|
-
goto retry;
|
63
|
-
}
|
64
|
-
else
|
65
|
-
{
|
66
|
-
rb_raise(rb_eIOError, StringValuePtr(filename));
|
67
|
-
}
|
49
|
+
rb_warn("Passing no parameters to XML::Parser.new is deprecated. Pass an instance of XML::Parser::Context instead.");
|
50
|
+
context = rb_class_new_instance(0, NULL, cXMLParserContext);
|
68
51
|
}
|
69
52
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
static xmlParserCtxtPtr rxml_parser_str_ctxt(VALUE input)
|
74
|
-
{
|
75
|
-
VALUE str = rb_ivar_get(input, STRING_ATTR);
|
76
|
-
return xmlCreateMemoryParserCtxt(StringValuePtr(str), RSTRING_LEN(str));
|
77
|
-
}
|
78
|
-
|
79
|
-
static xmlParserCtxtPtr rxml_parser_io_ctxt(VALUE input)
|
80
|
-
{
|
81
|
-
VALUE io = rb_ivar_get(input, IO_ATTR);
|
82
|
-
VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
|
83
|
-
xmlCharEncoding xmlEncoding = NUM2INT(encoding);
|
84
|
-
|
85
|
-
return xmlCreateIOParserCtxt(NULL, NULL,
|
86
|
-
(xmlInputReadCallback) rxml_read_callback, NULL, (void *) io, xmlEncoding);
|
53
|
+
rb_ivar_set(self, CONTEXT_ATTR, context);
|
54
|
+
return self;
|
87
55
|
}
|
88
56
|
|
89
57
|
/*
|
90
58
|
* call-seq:
|
91
|
-
* parser.parse ->
|
59
|
+
* parser.parse -> XML::Document
|
92
60
|
*
|
93
61
|
* Parse the input XML and create an XML::Document with
|
94
62
|
* it's content. If an error occurs, XML::Parser::ParseError
|
@@ -97,33 +65,14 @@ static xmlParserCtxtPtr rxml_parser_io_ctxt(VALUE input)
|
|
97
65
|
static VALUE rxml_parser_parse(VALUE self)
|
98
66
|
{
|
99
67
|
xmlParserCtxtPtr ctxt;
|
100
|
-
VALUE context;
|
101
|
-
|
102
|
-
|
103
|
-
context = rb_ivar_get(self, CONTEXT_ATTR);
|
104
|
-
if (context != Qnil)
|
105
|
-
rb_raise(rb_eRuntimeError, "You cannot parse a data source twice");
|
106
|
-
|
107
|
-
if (rb_ivar_get(input, FILE_ATTR) != Qnil)
|
108
|
-
ctxt = rxml_parser_filename_ctxt(input);
|
109
|
-
else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
|
110
|
-
ctxt = rxml_parser_str_ctxt(input);
|
111
|
-
/*else if (rb_ivar_get(input, DOCUMENT_ATTR) != Qnil)
|
112
|
-
ctxt = rxml_parser_parse_document(input);*/
|
113
|
-
else if (rb_ivar_get(input, IO_ATTR) != Qnil)
|
114
|
-
ctxt = rxml_parser_io_ctxt(input);
|
115
|
-
else
|
116
|
-
rb_raise(rb_eArgError, "You must specify a parser data source");
|
117
|
-
|
118
|
-
if (!ctxt)
|
119
|
-
rxml_raise(&xmlLastError);
|
120
|
-
|
121
|
-
context = rxml_parser_context_wrap(ctxt);
|
122
|
-
rb_ivar_set(self, CONTEXT_ATTR, context);
|
68
|
+
VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
|
69
|
+
|
70
|
+
Data_Get_Struct(context, xmlParserCtxt, ctxt);
|
123
71
|
|
124
|
-
if (xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed)
|
72
|
+
if ((xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed) && ! ctxt->recovery)
|
125
73
|
{
|
126
|
-
|
74
|
+
if (ctxt->myDoc)
|
75
|
+
xmlFreeDoc(ctxt->myDoc);
|
127
76
|
rxml_raise(&ctxt->lastError);
|
128
77
|
}
|
129
78
|
|
@@ -141,12 +90,11 @@ void ruby_init_parser(void)
|
|
141
90
|
cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
|
142
91
|
|
143
92
|
/* Atributes */
|
144
|
-
INPUT_ATTR = rb_intern("@input");
|
145
93
|
CONTEXT_ATTR = rb_intern("@context");
|
146
94
|
rb_define_attr(cXMLParser, "input", 1, 0);
|
147
95
|
rb_define_attr(cXMLParser, "context", 1, 0);
|
148
96
|
|
149
97
|
/* Instance Methods */
|
150
|
-
rb_define_method(cXMLParser, "initialize", rxml_parser_initialize,
|
98
|
+
rb_define_method(cXMLParser, "initialize", rxml_parser_initialize, -1);
|
151
99
|
rb_define_method(cXMLParser, "parse", rxml_parser_parse, 0);
|
152
100
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_parser_context.c
|
1
|
+
/* $Id: ruby_xml_parser_context.c 750 2009-01-24 21:16:41Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -16,16 +16,164 @@ VALUE cXMLParserContext;
|
|
16
16
|
|
17
17
|
static void rxml_parser_context_free(xmlParserCtxtPtr ctxt)
|
18
18
|
{
|
19
|
-
|
19
|
+
xmlFreeParserCtxt(ctxt);
|
20
|
+
}
|
21
|
+
|
22
|
+
static VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt)
|
23
|
+
{
|
24
|
+
return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free, ctxt);
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
static VALUE rxml_parser_context_alloc(VALUE klass)
|
29
|
+
{
|
30
|
+
xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
|
31
|
+
return Data_Wrap_Struct(klass, NULL, rxml_parser_context_free, ctxt);
|
32
|
+
}
|
33
|
+
|
34
|
+
/* call-seq:
|
35
|
+
* XML::Parser::Context.document(document) -> XML::Parser::Context
|
36
|
+
*
|
37
|
+
* Creates a new parser context based on the specified document.
|
38
|
+
*
|
39
|
+
* Parameters:
|
40
|
+
*
|
41
|
+
* document - An XML::Document instance.
|
42
|
+
*/
|
43
|
+
static VALUE rxml_parser_context_document(VALUE klass, VALUE document)
|
44
|
+
{
|
45
|
+
xmlParserCtxtPtr ctxt;
|
46
|
+
xmlDocPtr xdoc;
|
47
|
+
xmlChar *buffer;
|
48
|
+
int length;
|
49
|
+
|
50
|
+
if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse)
|
51
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Document object");
|
52
|
+
|
53
|
+
Data_Get_Struct(document, xmlDoc, xdoc);
|
54
|
+
xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, xdoc->encoding, 0);
|
55
|
+
|
56
|
+
ctxt = xmlCreateDocParserCtxt(buffer);
|
57
|
+
return rxml_parser_context_wrap(ctxt);
|
58
|
+
}
|
59
|
+
|
60
|
+
/* call-seq:
|
61
|
+
* XML::Parser::Context.file(file) -> XML::Parser::Context
|
62
|
+
*
|
63
|
+
* Creates a new parser context based on the specified file or uri.
|
64
|
+
*
|
65
|
+
* Parameters:
|
66
|
+
*
|
67
|
+
* file - A filename or uri.
|
68
|
+
*/
|
69
|
+
static VALUE rxml_parser_context_file(VALUE klass, VALUE file)
|
70
|
+
{
|
71
|
+
xmlParserCtxtPtr ctxt = xmlCreateURLParserCtxt(StringValuePtr(file), 0);
|
72
|
+
return rxml_parser_context_wrap(ctxt);
|
73
|
+
}
|
74
|
+
|
75
|
+
/* call-seq:
|
76
|
+
* XML::Parser::Context.string(string) -> XML::Parser::Context
|
77
|
+
*
|
78
|
+
* Creates a new parser context based on the specified string.
|
79
|
+
*
|
80
|
+
* Parameters:
|
81
|
+
*
|
82
|
+
* string - A string that contains the data to parse.
|
83
|
+
*/
|
84
|
+
static VALUE rxml_parser_context_string(VALUE klass, VALUE string)
|
85
|
+
{
|
86
|
+
xmlParserCtxtPtr ctxt;
|
87
|
+
Check_Type(string, T_STRING);
|
88
|
+
|
89
|
+
if (RSTRING_LEN(string) == 0)
|
90
|
+
rb_raise(rb_eArgError, "Must specify a string with one or more characters");
|
91
|
+
|
92
|
+
ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string),
|
93
|
+
RSTRING_LEN(string));
|
94
|
+
|
95
|
+
if (!ctxt)
|
96
|
+
rxml_raise(&xmlLastError);
|
97
|
+
|
98
|
+
return rxml_parser_context_wrap(ctxt);
|
99
|
+
}
|
100
|
+
|
101
|
+
/* call-seq:
|
102
|
+
* XML::Parser::Context.io(io) -> XML::Parser::Context
|
103
|
+
*
|
104
|
+
* Creates a new parser context based on the specified io object.
|
105
|
+
*
|
106
|
+
* Parameters:
|
107
|
+
*
|
108
|
+
* io - A ruby IO object.
|
109
|
+
*/
|
110
|
+
static VALUE rxml_parser_context_io(VALUE klass, VALUE io)
|
111
|
+
{
|
112
|
+
xmlParserCtxtPtr ctxt;
|
113
|
+
xmlParserInputBufferPtr input;
|
114
|
+
xmlParserInputPtr stream;
|
115
|
+
|
116
|
+
input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
|
117
|
+
(void*)io, XML_CHAR_ENCODING_NONE);
|
118
|
+
|
119
|
+
ctxt = xmlNewParserCtxt();
|
120
|
+
if (!ctxt)
|
121
|
+
{
|
122
|
+
xmlFreeParserInputBuffer(input);
|
123
|
+
rxml_raise(&xmlLastError);
|
124
|
+
}
|
125
|
+
|
126
|
+
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
|
127
|
+
|
128
|
+
if (!stream)
|
129
|
+
{
|
130
|
+
xmlFreeParserInputBuffer(input);
|
20
131
|
xmlFreeParserCtxt(ctxt);
|
132
|
+
rxml_raise(&xmlLastError);
|
133
|
+
}
|
134
|
+
inputPush(ctxt, stream);
|
135
|
+
return rxml_parser_context_wrap(ctxt);
|
136
|
+
}
|
137
|
+
|
138
|
+
/*
|
139
|
+
* call-seq:
|
140
|
+
* context.base_uri -> "http:://libxml.org"
|
141
|
+
*
|
142
|
+
* Obtain the base url for this parser context.
|
143
|
+
*/
|
144
|
+
static VALUE rxml_parser_context_base_uri_get(VALUE self)
|
145
|
+
{
|
146
|
+
xmlParserCtxtPtr ctxt;
|
147
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
148
|
+
|
149
|
+
if (ctxt->input && ctxt->input->filename)
|
150
|
+
return rb_str_new2(ctxt->input->filename);
|
151
|
+
else
|
152
|
+
return Qnil;
|
21
153
|
}
|
22
154
|
|
23
|
-
|
155
|
+
/*
|
156
|
+
* call-seq:
|
157
|
+
* context.base_uri = "http:://libxml.org"
|
158
|
+
*
|
159
|
+
* Sets the base url for this parser context.
|
160
|
+
*/
|
161
|
+
static VALUE rxml_parser_context_base_uri_set(VALUE self, VALUE url)
|
24
162
|
{
|
25
|
-
|
26
|
-
|
163
|
+
xmlParserCtxtPtr ctxt;
|
164
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
165
|
+
|
166
|
+
Check_Type(url, T_STRING);
|
167
|
+
|
168
|
+
if (ctxt->input && !ctxt->input->filename)
|
169
|
+
{
|
170
|
+
const xmlChar * xurl = StringValuePtr(url);
|
171
|
+
ctxt->input->filename = (char *) xmlStrdup(xurl);
|
172
|
+
}
|
173
|
+
return self;
|
27
174
|
}
|
28
175
|
|
176
|
+
|
29
177
|
/*
|
30
178
|
* call-seq:
|
31
179
|
* context.data_directory -> "dir"
|
@@ -94,7 +242,7 @@ static VALUE rxml_parser_context_docbook_q(VALUE self)
|
|
94
242
|
|
95
243
|
/*
|
96
244
|
* call-seq:
|
97
|
-
* context.encoding ->
|
245
|
+
* context.encoding -> XML::Encoding::UTF_8
|
98
246
|
*
|
99
247
|
* Obtain the character encoding identifier used in
|
100
248
|
* this context.
|
@@ -103,11 +251,36 @@ static VALUE rxml_parser_context_encoding_get(VALUE self)
|
|
103
251
|
{
|
104
252
|
xmlParserCtxtPtr ctxt;
|
105
253
|
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
254
|
+
return INT2NUM(xmlParseCharEncoding(ctxt->encoding));
|
255
|
+
}
|
256
|
+
|
257
|
+
/*
|
258
|
+
* call-seq:
|
259
|
+
* context.encoding = XML::Encoding::UTF_8
|
260
|
+
*
|
261
|
+
* Sets the character encoding for this context.
|
262
|
+
*/
|
263
|
+
static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding)
|
264
|
+
{
|
265
|
+
xmlParserCtxtPtr ctxt;
|
266
|
+
int result;
|
267
|
+
const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding));
|
268
|
+
xmlCharEncodingHandlerPtr hdlr = xmlFindCharEncodingHandler(xencoding);
|
269
|
+
|
270
|
+
if (!hdlr)
|
271
|
+
rb_raise(rb_eRuntimeError, "Unknown encoding: %s", encoding);
|
272
|
+
|
273
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
274
|
+
result = xmlSwitchToEncoding(ctxt, hdlr);
|
106
275
|
|
107
|
-
if (
|
108
|
-
|
109
|
-
|
110
|
-
|
276
|
+
if (result != 0)
|
277
|
+
rxml_raise(&xmlLastError);
|
278
|
+
|
279
|
+
if (ctxt->encoding != NULL)
|
280
|
+
xmlFree((xmlChar *) ctxt->encoding);
|
281
|
+
|
282
|
+
ctxt->encoding = xmlStrdup((const xmlChar *) xencoding);
|
283
|
+
return self;
|
111
284
|
}
|
112
285
|
|
113
286
|
/*
|
@@ -293,7 +466,7 @@ static VALUE rxml_parser_context_node_get(VALUE self)
|
|
293
466
|
if (ctxt->node == NULL)
|
294
467
|
return (Qnil);
|
295
468
|
else
|
296
|
-
return (rxml_node_wrap(
|
469
|
+
return (rxml_node_wrap(ctxt->node));
|
297
470
|
}
|
298
471
|
|
299
472
|
/*
|
@@ -324,6 +497,85 @@ static VALUE rxml_parser_context_num_chars_get(VALUE self)
|
|
324
497
|
return (LONG2NUM(ctxt->nbChars));
|
325
498
|
}
|
326
499
|
|
500
|
+
|
501
|
+
/*
|
502
|
+
* call-seq:
|
503
|
+
* context.options > XML::Parser::Options::NOENT
|
504
|
+
*
|
505
|
+
* Returns the parser options for this context. Multiple
|
506
|
+
* options can be combined by using Bitwise OR (|).
|
507
|
+
*/
|
508
|
+
static VALUE rxml_parser_context_options_get(VALUE self)
|
509
|
+
{
|
510
|
+
xmlParserCtxtPtr ctxt;
|
511
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
512
|
+
|
513
|
+
return INT2NUM(ctxt->options);
|
514
|
+
}
|
515
|
+
|
516
|
+
/*
|
517
|
+
* call-seq:
|
518
|
+
* context.options = XML::Parser::Options::NOENT |
|
519
|
+
XML::Parser::Options::NOCDATA
|
520
|
+
*
|
521
|
+
* Provides control over the execution of a parser. Valid values
|
522
|
+
* are the constants defined on XML::Parser::Options. Multiple
|
523
|
+
* options can be combined by using Bitwise OR (|).
|
524
|
+
*/
|
525
|
+
static VALUE rxml_parser_context_options_set(VALUE self, VALUE options)
|
526
|
+
{
|
527
|
+
int result;
|
528
|
+
xmlParserCtxtPtr ctxt;
|
529
|
+
Check_Type(options, T_FIXNUM);
|
530
|
+
|
531
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
532
|
+
result = xmlCtxtUseOptions(ctxt, NUM2INT(options));
|
533
|
+
|
534
|
+
return self;
|
535
|
+
}
|
536
|
+
|
537
|
+
/*
|
538
|
+
* call-seq:
|
539
|
+
* context.recovery? -> (true|false)
|
540
|
+
*
|
541
|
+
* Determine whether recovery mode is enabled in this
|
542
|
+
* context.
|
543
|
+
*/
|
544
|
+
static VALUE rxml_parser_context_recovery_q(VALUE self)
|
545
|
+
{
|
546
|
+
xmlParserCtxtPtr ctxt;
|
547
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
548
|
+
|
549
|
+
if (ctxt->recovery)
|
550
|
+
return (Qtrue);
|
551
|
+
else
|
552
|
+
return (Qfalse);
|
553
|
+
}
|
554
|
+
|
555
|
+
/*
|
556
|
+
* call-seq:
|
557
|
+
* context.recovery = true|false
|
558
|
+
*
|
559
|
+
* Control whether recovery mode is enabled in this
|
560
|
+
* context.
|
561
|
+
*/
|
562
|
+
static VALUE rxml_parser_context_recovery_set(VALUE self, VALUE bool)
|
563
|
+
{
|
564
|
+
xmlParserCtxtPtr ctxt;
|
565
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
566
|
+
|
567
|
+
if (TYPE(bool) == T_FALSE)
|
568
|
+
{
|
569
|
+
ctxt->recovery = 0;
|
570
|
+
return (Qfalse);
|
571
|
+
}
|
572
|
+
else
|
573
|
+
{
|
574
|
+
ctxt->recovery = 1;
|
575
|
+
return (Qtrue);
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
327
579
|
/*
|
328
580
|
* call-seq:
|
329
581
|
* context.replace_entities? -> (true|false)
|
@@ -362,7 +614,7 @@ static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE bool)
|
|
362
614
|
else
|
363
615
|
{
|
364
616
|
ctxt->replaceEntities = 1;
|
365
|
-
return (
|
617
|
+
return (Qtrue);
|
366
618
|
}
|
367
619
|
}
|
368
620
|
|
@@ -589,16 +841,31 @@ static VALUE rxml_parser_context_well_formed_q(VALUE self)
|
|
589
841
|
return (Qfalse);
|
590
842
|
}
|
591
843
|
|
844
|
+
// Rdoc needs to know
|
845
|
+
#ifdef RDOC_NEVER_DEFINED
|
846
|
+
mLibXML = rb_define_module("LibXML");
|
847
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
848
|
+
cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
|
849
|
+
#endif
|
850
|
+
|
592
851
|
void ruby_init_xml_parser_context(void)
|
593
852
|
{
|
594
853
|
cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
|
595
|
-
|
854
|
+
rb_define_alloc_func(cXMLParserContext, rxml_parser_context_alloc);
|
855
|
+
|
856
|
+
rb_define_singleton_method(cXMLParserContext, "document", rxml_parser_context_document, 1);
|
857
|
+
rb_define_singleton_method(cXMLParserContext, "file", rxml_parser_context_file, 1);
|
858
|
+
rb_define_singleton_method(cXMLParserContext, "io", rxml_parser_context_io, 1);
|
859
|
+
rb_define_singleton_method(cXMLParserContext, "string", rxml_parser_context_string, 1);
|
596
860
|
|
861
|
+
rb_define_method(cXMLParserContext, "base_uri", rxml_parser_context_base_uri_get, 0);
|
862
|
+
rb_define_method(cXMLParserContext, "base_uri=", rxml_parser_context_base_uri_set, 1);
|
597
863
|
rb_define_method(cXMLParserContext, "data_directory", rxml_parser_context_data_directory_get, 0);
|
598
864
|
rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0);
|
599
865
|
rb_define_method(cXMLParserContext, "disable_sax?", rxml_parser_context_disable_sax_q, 0);
|
600
866
|
rb_define_method(cXMLParserContext, "docbook?", rxml_parser_context_docbook_q, 0);
|
601
867
|
rb_define_method(cXMLParserContext, "encoding", rxml_parser_context_encoding_get, 0);
|
868
|
+
rb_define_method(cXMLParserContext, "encoding=", rxml_parser_context_encoding_set, 1);
|
602
869
|
rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0);
|
603
870
|
rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0);
|
604
871
|
rb_define_method(cXMLParserContext, "io_max_num_streams", rxml_parser_context_io_max_num_streams_get, 0);
|
@@ -612,6 +879,10 @@ void ruby_init_xml_parser_context(void)
|
|
612
879
|
rb_define_method(cXMLParserContext, "node_depth", rxml_parser_context_node_depth_get, 0);
|
613
880
|
rb_define_method(cXMLParserContext, "node_depth_max", rxml_parser_context_node_depth_max_get, 0);
|
614
881
|
rb_define_method(cXMLParserContext, "num_chars", rxml_parser_context_num_chars_get, 0);
|
882
|
+
rb_define_method(cXMLParserContext, "options", rxml_parser_context_options_get, 0);
|
883
|
+
rb_define_method(cXMLParserContext, "options=", rxml_parser_context_options_set, 1);
|
884
|
+
rb_define_method(cXMLParserContext, "recovery?", rxml_parser_context_recovery_q, 0);
|
885
|
+
rb_define_method(cXMLParserContext, "recovery=", rxml_parser_context_recovery_set, 1);
|
615
886
|
rb_define_method(cXMLParserContext, "replace_entities?", rxml_parser_context_replace_entities_q, 0);
|
616
887
|
rb_define_method(cXMLParserContext, "replace_entities=", rxml_parser_context_replace_entities_set, 1);
|
617
888
|
rb_define_method(cXMLParserContext, "space_depth", rxml_parser_context_space_depth_get, 0);
|