libxml-ruby 4.1.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +14 -0
  3. data/ext/libxml/ruby_libxml.h +43 -44
  4. data/ext/libxml/ruby_xml.c +0 -343
  5. data/ext/libxml/ruby_xml.h +9 -10
  6. data/ext/libxml/ruby_xml_attributes.h +2 -0
  7. data/ext/libxml/ruby_xml_document.c +6 -6
  8. data/ext/libxml/ruby_xml_document.h +11 -11
  9. data/ext/libxml/ruby_xml_dtd.c +3 -3
  10. data/ext/libxml/ruby_xml_encoding.h +20 -18
  11. data/ext/libxml/ruby_xml_error.c +9 -6
  12. data/ext/libxml/ruby_xml_error.h +2 -2
  13. data/ext/libxml/ruby_xml_html_parser_context.c +35 -21
  14. data/ext/libxml/ruby_xml_namespace.c +0 -3
  15. data/ext/libxml/ruby_xml_node.c +1394 -1398
  16. data/ext/libxml/ruby_xml_parser.h +1 -1
  17. data/ext/libxml/ruby_xml_parser_context.c +47 -39
  18. data/ext/libxml/ruby_xml_parser_options.c +9 -1
  19. data/ext/libxml/ruby_xml_parser_options.h +1 -1
  20. data/ext/libxml/ruby_xml_reader.c +15 -16
  21. data/ext/libxml/ruby_xml_sax2_handler.c +1 -1
  22. data/ext/libxml/ruby_xml_sax_parser.c +1 -9
  23. data/ext/libxml/ruby_xml_schema.c +4 -4
  24. data/ext/libxml/ruby_xml_version.h +5 -5
  25. data/ext/libxml/ruby_xml_writer.c +8 -8
  26. data/ext/libxml/ruby_xml_xpath.c +1 -1
  27. data/ext/libxml/ruby_xml_xpath_context.c +2 -2
  28. data/ext/libxml/ruby_xml_xpath_expression.c +1 -1
  29. data/lib/libxml/document.rb +13 -13
  30. data/lib/libxml/html_parser.rb +23 -23
  31. data/lib/libxml/parser.rb +26 -24
  32. data/test/test.rb +5 -0
  33. data/test/test_document_write.rb +1 -4
  34. data/test/test_dtd.rb +1 -4
  35. data/test/test_encoding.rb +1 -4
  36. data/test/test_helper.rb +9 -2
  37. data/test/test_html_parser.rb +162 -162
  38. data/test/test_namespace.rb +1 -3
  39. data/test/test_node.rb +1 -3
  40. data/test/test_node_write.rb +1 -4
  41. data/test/test_parser.rb +26 -17
  42. data/test/test_reader.rb +4 -4
  43. data/test/test_sax_parser.rb +1 -1
  44. data/test/test_xml.rb +0 -99
  45. metadata +4 -3
@@ -5,6 +5,6 @@
5
5
 
6
6
  extern VALUE cXMLParser;
7
7
 
8
- void rxml_init_parser();
8
+ void rxml_init_parser(void);
9
9
 
10
10
  #endif
@@ -39,31 +39,33 @@ static VALUE rxml_parser_context_alloc(VALUE klass)
39
39
  *
40
40
  * Parameters:
41
41
  *
42
- * document - An XML::Document instance.
42
+ * document - An XML::Document instance
43
+ * options - A or'ed together list of LibXML::XML::Parser::Options values
43
44
  */
44
- static VALUE rxml_parser_context_document(VALUE klass, VALUE document)
45
+ static VALUE rxml_parser_context_document(int argc, VALUE* argv, VALUE klass)
45
46
  {
46
- xmlParserCtxtPtr ctxt;
47
- xmlDocPtr xdoc;
48
- xmlChar *buffer;
49
- int length;
47
+ VALUE document, options;
48
+ rb_scan_args(argc, argv, "11", &document, &options);
50
49
 
51
50
  if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse)
52
51
  rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
53
52
 
53
+ xmlDocPtr xdoc;
54
+ xmlChar *buffer;
55
+ int length;
54
56
  Data_Get_Struct(document, xmlDoc, xdoc);
55
57
  xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0);
56
58
 
57
- ctxt = xmlCreateDocParserCtxt(buffer);
59
+ xmlParserCtxtPtr ctxt = xmlCreateDocParserCtxt(buffer);
58
60
 
59
61
  if (!ctxt)
60
- rxml_raise(&xmlLastError);
62
+ rxml_raise(xmlGetLastError());
61
63
 
62
64
  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
63
65
  xmlCtxtUseOptionsInternal (called below) initialize slightly different
64
66
  context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
65
67
  sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
66
- xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
68
+ xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));
67
69
 
68
70
  return rxml_parser_context_wrap(ctxt);
69
71
  }
@@ -75,20 +77,24 @@ static VALUE rxml_parser_context_document(VALUE klass, VALUE document)
75
77
  *
76
78
  * Parameters:
77
79
  *
78
- * file - A filename or uri.
80
+ * file - A filename or uri
81
+ * options - A or'ed together list of LibXML::XML::Parser::Options values
79
82
  */
80
- static VALUE rxml_parser_context_file(VALUE klass, VALUE file)
83
+ static VALUE rxml_parser_context_file(int argc, VALUE* argv, VALUE klass)
81
84
  {
85
+ VALUE file, options;
86
+ rb_scan_args(argc, argv, "11", &file, &options);
87
+
82
88
  xmlParserCtxtPtr ctxt = xmlCreateURLParserCtxt(StringValuePtr(file), 0);
83
89
 
84
90
  if (!ctxt)
85
- rxml_raise(&xmlLastError);
91
+ rxml_raise(xmlGetLastError());
86
92
 
87
93
  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
88
94
  xmlCtxtUseOptionsInternal (called below) initialize slightly different
89
95
  context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
90
96
  sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
91
- xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
97
+ xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));
92
98
 
93
99
  return rxml_parser_context_wrap(ctxt);
94
100
  }
@@ -100,26 +106,29 @@ static VALUE rxml_parser_context_file(VALUE klass, VALUE file)
100
106
  *
101
107
  * Parameters:
102
108
  *
103
- * string - A string that contains the data to parse.
109
+ * string - A string that contains the data to parse
110
+ * options - A or'ed together list of LibXML::XML::Parser::Options values
104
111
  */
105
- static VALUE rxml_parser_context_string(VALUE klass, VALUE string)
112
+ static VALUE rxml_parser_context_string(int argc, VALUE* argv, VALUE klass)
106
113
  {
107
- xmlParserCtxtPtr ctxt;
114
+ VALUE string, options;
115
+ rb_scan_args(argc, argv, "11", &string, &options);
116
+
108
117
  Check_Type(string, T_STRING);
109
118
 
110
119
  if (RSTRING_LEN(string) == 0)
111
120
  rb_raise(rb_eArgError, "Must specify a string with one or more characters");
112
121
 
113
- ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string), (int)RSTRING_LEN(string));
122
+ xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string), (int)RSTRING_LEN(string));
114
123
 
115
124
  if (!ctxt)
116
- rxml_raise(&xmlLastError);
125
+ rxml_raise(xmlGetLastError());
117
126
 
118
127
  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
119
128
  xmlCtxtUseOptionsInternal (called below) initialize slightly different
120
129
  context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
121
130
  sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
122
- xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
131
+ xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));
123
132
 
124
133
  return rxml_parser_context_wrap(ctxt);
125
134
  }
@@ -131,45 +140,44 @@ static VALUE rxml_parser_context_string(VALUE klass, VALUE string)
131
140
  *
132
141
  * Parameters:
133
142
  *
134
- * io - A ruby IO object.
143
+ * io - A ruby IO object
144
+ * options - A or'ed together list of LibXML::XML::Parser::Options values
135
145
  */
136
- static VALUE rxml_parser_context_io(VALUE klass, VALUE io)
146
+ static VALUE rxml_parser_context_io(int argc, VALUE* argv, VALUE klass)
137
147
  {
138
- VALUE result;
139
- xmlParserCtxtPtr ctxt;
140
- xmlParserInputBufferPtr input;
141
- xmlParserInputPtr stream;
148
+ VALUE io, options;
149
+ rb_scan_args(argc, argv, "11", &io, &options);
142
150
 
143
151
  if (NIL_P(io))
144
152
  rb_raise(rb_eTypeError, "Must pass in an IO object");
145
153
 
146
- input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
154
+ xmlParserInputBufferPtr input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
147
155
  (void*)io, XML_CHAR_ENCODING_NONE);
148
-
149
- ctxt = xmlNewParserCtxt();
156
+
157
+ xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
150
158
 
151
159
  if (!ctxt)
152
160
  {
153
161
  xmlFreeParserInputBuffer(input);
154
- rxml_raise(&xmlLastError);
162
+ rxml_raise(xmlGetLastError());
155
163
  }
156
164
 
157
165
  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
158
166
  xmlCtxtUseOptionsInternal (called below) initialize slightly different
159
167
  context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
160
168
  sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
161
- xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
169
+ xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));
162
170
 
163
- stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
171
+ xmlParserInputPtr stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
164
172
 
165
173
  if (!stream)
166
174
  {
167
175
  xmlFreeParserInputBuffer(input);
168
176
  xmlFreeParserCtxt(ctxt);
169
- rxml_raise(&xmlLastError);
177
+ rxml_raise(xmlGetLastError());
170
178
  }
171
179
  inputPush(ctxt, stream);
172
- result = rxml_parser_context_wrap(ctxt);
180
+ VALUE result = rxml_parser_context_wrap(ctxt);
173
181
 
174
182
  /* Attach io object to parser so it won't get freed.*/
175
183
  rb_ivar_set(result, IO_ATTR, io);
@@ -303,7 +311,7 @@ static VALUE rxml_parser_context_disable_cdata_set(VALUE self, VALUE value)
303
311
  if (value)
304
312
  ctxt->sax->cdataBlock = NULL;
305
313
  else
306
- ctxt->sax->cdataBlock = xmlDefaultSAXHandler.cdataBlock;
314
+ ctxt->sax->cdataBlock = xmlSAX2CDataBlock;
307
315
 
308
316
  return value;
309
317
  }
@@ -377,7 +385,7 @@ static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding)
377
385
  result = xmlSwitchToEncoding(ctxt, hdlr);
378
386
 
379
387
  if (result != 0)
380
- rxml_raise(&xmlLastError);
388
+ rxml_raise(xmlGetLastError());
381
389
 
382
390
  if (ctxt->encoding != NULL)
383
391
  xmlFree((xmlChar *) ctxt->encoding);
@@ -950,10 +958,10 @@ void rxml_init_parser_context(void)
950
958
  cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
951
959
  rb_define_alloc_func(cXMLParserContext, rxml_parser_context_alloc);
952
960
 
953
- rb_define_singleton_method(cXMLParserContext, "document", rxml_parser_context_document, 1);
954
- rb_define_singleton_method(cXMLParserContext, "file", rxml_parser_context_file, 1);
955
- rb_define_singleton_method(cXMLParserContext, "io", rxml_parser_context_io, 1);
956
- rb_define_singleton_method(cXMLParserContext, "string", rxml_parser_context_string, 1);
961
+ rb_define_singleton_method(cXMLParserContext, "document", rxml_parser_context_document, -1);
962
+ rb_define_singleton_method(cXMLParserContext, "file", rxml_parser_context_file, -1);
963
+ rb_define_singleton_method(cXMLParserContext, "io", rxml_parser_context_io, -1);
964
+ rb_define_singleton_method(cXMLParserContext, "string", rxml_parser_context_string, -1);
957
965
 
958
966
  rb_define_method(cXMLParserContext, "base_uri", rxml_parser_context_base_uri_get, 0);
959
967
  rb_define_method(cXMLParserContext, "base_uri=", rxml_parser_context_base_uri_set, 1);
@@ -55,7 +55,7 @@ void rxml_init_parser_options(void)
55
55
  /* compact small text nodes */
56
56
  rb_define_const(mXMLParserOptions, "COMPACT", INT2NUM(XML_PARSE_COMPACT));
57
57
  /* parse using XML-1.0 before update 5 */
58
- rb_define_const(mXMLParserOptions, "PARSE_OLD10", INT2NUM(XML_PARSE_OLD10));
58
+ rb_define_const(mXMLParserOptions, "OLD10", INT2NUM(XML_PARSE_OLD10));
59
59
  /* do not fixup XINCLUDE xml:base uris */
60
60
  rb_define_const(mXMLParserOptions, "NOBASEFIX", INT2NUM(XML_PARSE_NOBASEFIX));
61
61
  #endif
@@ -63,4 +63,12 @@ void rxml_init_parser_options(void)
63
63
  /* relax any hardcoded limit from the parser */
64
64
  rb_define_const(mXMLParserOptions, "HUGE", INT2NUM(XML_PARSE_HUGE));
65
65
  #endif
66
+ #if LIBXML_VERSION >= 21106
67
+ /* parse using SAX2 interface before 2.7.0 */
68
+ rb_define_const(mXMLParserOptions, "OLDSAX", INT2NUM(XML_PARSE_OLDSAX));
69
+ /* ignore internal document encoding hint */
70
+ rb_define_const(mXMLParserOptions, "IGNORE_ENC", INT2NUM(XML_PARSE_IGNORE_ENC));
71
+ /* Store big lines numbers in text PSVI field */
72
+ rb_define_const(mXMLParserOptions, "BIG_LINES", INT2NUM(XML_PARSE_BIG_LINES));
73
+ #endif
66
74
  }
@@ -5,6 +5,6 @@
5
5
 
6
6
  extern VALUE mXMLParserOptions;
7
7
 
8
- void rxml_init_parser_options();
8
+ void rxml_init_parser_options(void);
9
9
 
10
10
  #endif
@@ -4,6 +4,8 @@
4
4
  #include "ruby_libxml.h"
5
5
  #include "ruby_xml_reader.h"
6
6
 
7
+ #include <errno.h>
8
+
7
9
  #include <libxml/xmlreader.h>
8
10
  #include <libxml/xmlschemas.h>
9
11
 
@@ -98,7 +100,7 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
98
100
  xreader = xmlReaderWalker(xdoc);
99
101
 
100
102
  if (xreader == NULL)
101
- rxml_raise(&xmlLastError);
103
+ rxml_raise(xmlGetLastError());
102
104
 
103
105
  return rxml_reader_wrap(xreader);
104
106
  }
@@ -122,34 +124,31 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
122
124
  */
123
125
  static VALUE rxml_reader_file(int argc, VALUE *argv, VALUE klass)
124
126
  {
125
- xmlTextReaderPtr xreader;
126
127
  VALUE path;
127
128
  VALUE options;
128
129
 
129
- const char *xencoding = NULL;
130
- int xoptions = 0;
131
-
132
130
  rb_scan_args(argc, argv, "11", &path, &options);
133
131
  Check_Type(path, T_STRING);
134
132
 
133
+ const char* xencoding = NULL;
134
+ int xoptions = 0;
135
+
135
136
  if (!NIL_P(options))
136
137
  {
137
- VALUE encoding = Qnil;
138
- VALUE parserOptions = Qnil;
139
-
140
138
  Check_Type(options, T_HASH);
141
139
 
142
- encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
140
+ VALUE encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
143
141
  xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding));
144
142
 
145
- parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
143
+ VALUE parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
146
144
  xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions);
147
145
  }
148
146
 
149
- xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
147
+ xmlTextReaderPtr xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
150
148
 
149
+ // Unfortunately libxml2 does not set xmlLastError and just returns a null reader
151
150
  if (xreader == NULL)
152
- rxml_raise(&xmlLastError);
151
+ rb_syserr_fail(ENOENT, StringValueCStr(path));
153
152
 
154
153
  return rxml_reader_wrap(xreader);
155
154
  }
@@ -207,7 +206,7 @@ static VALUE rxml_reader_io(int argc, VALUE *argv, VALUE klass)
207
206
  xbaseurl, xencoding, xoptions);
208
207
 
209
208
  if (xreader == NULL)
210
- rxml_raise(&xmlLastError);
209
+ rxml_raise(xmlGetLastError());
211
210
 
212
211
  result = rxml_reader_wrap(xreader);
213
212
 
@@ -269,7 +268,7 @@ static VALUE rxml_reader_string(int argc, VALUE *argv, VALUE klass)
269
268
  xbaseurl, xencoding, xoptions);
270
269
 
271
270
  if (xreader == NULL)
272
- rxml_raise(&xmlLastError);
271
+ rxml_raise(xmlGetLastError());
273
272
 
274
273
  return rxml_reader_wrap(xreader);
275
274
  }
@@ -472,7 +471,7 @@ static VALUE rxml_reader_read(VALUE self)
472
471
  switch(result)
473
472
  {
474
473
  case -1:
475
- rxml_raise(&xmlLastError);
474
+ rxml_raise(xmlGetLastError());
476
475
  return Qnil;
477
476
  break;
478
477
  case 0:
@@ -1048,7 +1047,7 @@ static VALUE
1048
1047
  rxml_reader_byte_consumed(VALUE self)
1049
1048
  {
1050
1049
  xmlTextReaderPtr xreader = rxml_text_reader_get(self);
1051
- return INT2NUM(xmlTextReaderByteConsumed(xreader));
1050
+ return LONG2NUM(xmlTextReaderByteConsumed(xreader));
1052
1051
  }
1053
1052
  #endif
1054
1053
 
@@ -243,7 +243,7 @@ static void start_element_ns_callback(void *ctx,
243
243
  namespaces);
244
244
  }
245
245
 
246
- static void structured_error_callback(void *ctx, xmlErrorPtr xerror)
246
+ static void structured_error_callback(void *ctx, const xmlError *xerror)
247
247
  {
248
248
  /* Older versions of Libxml will pass a NULL context from the sax parser. Fixed on
249
249
  Feb 23, 2011. See:
@@ -74,23 +74,15 @@ static VALUE rxml_sax_parser_initialize(int argc, VALUE *argv, VALUE self)
74
74
  */
75
75
  static VALUE rxml_sax_parser_parse(VALUE self)
76
76
  {
77
- int status;
78
77
  VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
79
78
  xmlParserCtxtPtr ctxt;
80
79
  Data_Get_Struct(context, xmlParserCtxt, ctxt);
81
80
 
82
81
  ctxt->sax2 = 1;
83
82
  ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR);
84
-
85
- if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
86
- xmlFree(ctxt->sax);
87
-
88
- ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(rxml_sax_handler));
89
- if (ctxt->sax == NULL)
90
- rb_fatal("Not enough memory.");
91
83
  memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler));
92
84
 
93
- status = xmlParseDocument(ctxt);
85
+ int status = xmlParseDocument(ctxt);
94
86
 
95
87
  /* Now check the parsing result*/
96
88
  if (status == -1 || !ctxt->wellFormed)
@@ -143,7 +143,7 @@ static VALUE rxml_schema_init(VALUE class, xmlSchemaParserCtxtPtr xparser)
143
143
  xmlSchemaFreeParserCtxt(xparser);
144
144
 
145
145
  if (!xschema)
146
- rxml_raise(&xmlLastError);
146
+ rxml_raise(xmlGetLastError());
147
147
 
148
148
  return rxml_wrap_schema(xschema);
149
149
  }
@@ -163,7 +163,7 @@ static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
163
163
  xmlResetLastError();
164
164
  xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
165
165
  if (!xparser)
166
- rxml_raise(&xmlLastError);
166
+ rxml_raise(xmlGetLastError());
167
167
 
168
168
  return rxml_schema_init(class, xparser);
169
169
  }
@@ -184,7 +184,7 @@ static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
184
184
  xmlResetLastError();
185
185
  xparser = xmlSchemaNewDocParserCtxt(xdoc);
186
186
  if (!xparser)
187
- rxml_raise(&xmlLastError);
187
+ rxml_raise(xmlGetLastError());
188
188
 
189
189
  return rxml_schema_init(class, xparser);
190
190
  }
@@ -204,7 +204,7 @@ static VALUE rxml_schema_init_from_string(VALUE class, VALUE schema_str)
204
204
  xmlResetLastError();
205
205
  xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), (int)strlen(StringValuePtr(schema_str)));
206
206
  if (!xparser)
207
- rxml_raise(&xmlLastError);
207
+ rxml_raise(xmlGetLastError());
208
208
 
209
209
  return rxml_schema_init(class, xparser);
210
210
  }
@@ -1,9 +1,9 @@
1
1
  /* Don't nuke this block! It is used for automatically updating the
2
2
  * versions below. VERSION = string formatting, VERNUM = numbered
3
3
  * version for inline testing: increment both or none at all.*/
4
- #define RUBY_LIBXML_VERSION "4.1.2"
5
- #define RUBY_LIBXML_VERNUM 400
6
- #define RUBY_LIBXML_VER_MAJ 4
7
- #define RUBY_LIBXML_VER_MIN 1
8
- #define RUBY_LIBXML_VER_MIC 2
4
+ #define RUBY_LIBXML_VERSION "5.0.0"
5
+ #define RUBY_LIBXML_VERNUM 500
6
+ #define RUBY_LIBXML_VER_MAJ 5
7
+ #define RUBY_LIBXML_VER_MIN 0
8
+ #define RUBY_LIBXML_VER_MIC 0
9
9
  #define RUBY_LIBXML_VER_PATCH 0
@@ -116,11 +116,11 @@ static VALUE rxml_writer_io(VALUE klass, VALUE io)
116
116
  xmlCharEncodingHandlerPtr encodingHdlr = xmlFindCharEncodingHandler(rwo->encoding->name);
117
117
  if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void*)rwo, encodingHdlr)))
118
118
  {
119
- rxml_raise(&xmlLastError);
119
+ rxml_raise(xmlGetLastError());
120
120
  }
121
121
  if (NULL == (rwo->writer = xmlNewTextWriter(out)))
122
122
  {
123
- rxml_raise(&xmlLastError);
123
+ rxml_raise(xmlGetLastError());
124
124
  }
125
125
 
126
126
  return rxml_writer_wrap(rwo);
@@ -145,7 +145,7 @@ static VALUE rxml_writer_file(VALUE klass, VALUE filename)
145
145
  rwo->output_type = RXMLW_OUTPUT_NONE;
146
146
  if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
147
147
  {
148
- rxml_raise(&xmlLastError);
148
+ rxml_raise(xmlGetLastError());
149
149
  }
150
150
 
151
151
  return rxml_writer_wrap(rwo);
@@ -167,12 +167,12 @@ static VALUE rxml_writer_string(VALUE klass)
167
167
  rwo->output_type = RXMLW_OUTPUT_STRING;
168
168
  if (NULL == (rwo->buffer = xmlBufferCreate()))
169
169
  {
170
- rxml_raise(&xmlLastError);
170
+ rxml_raise(xmlGetLastError());
171
171
  }
172
172
  if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
173
173
  {
174
174
  xmlBufferFree(rwo->buffer);
175
- rxml_raise(&xmlLastError);
175
+ rxml_raise(xmlGetLastError());
176
176
  }
177
177
 
178
178
  return rxml_writer_wrap(rwo);
@@ -196,7 +196,7 @@ static VALUE rxml_writer_doc(VALUE klass)
196
196
  rwo->output_type = RXMLW_OUTPUT_DOC;
197
197
  if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
198
198
  {
199
- rxml_raise(&xmlLastError);
199
+ rxml_raise(xmlGetLastError());
200
200
  }
201
201
  rwo->output = rxml_document_wrap(doc);
202
202
 
@@ -224,7 +224,7 @@ static VALUE rxml_writer_flush(int argc, VALUE* argv, VALUE self)
224
224
  rwo = rxml_textwriter_get(self);
225
225
  if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
226
226
  {
227
- rxml_raise(&xmlLastError);
227
+ rxml_raise(xmlGetLastError());
228
228
  }
229
229
 
230
230
  if (NULL != rwo->buffer)
@@ -260,7 +260,7 @@ static VALUE rxml_writer_result(VALUE self)
260
260
 
261
261
  if (bytesWritten == -1)
262
262
  {
263
- rxml_raise(&xmlLastError);
263
+ rxml_raise(xmlGetLastError());
264
264
  }
265
265
 
266
266
  switch (rwo->output_type)
@@ -89,7 +89,7 @@ VALUE rxml_xpath_to_value(xmlXPathContextPtr xctxt, xmlXPathObjectPtr xobject)
89
89
  /* xmlLastError is different than xctxt->lastError. Use
90
90
  xmlLastError since it has the message set while xctxt->lastError
91
91
  does not. */
92
- xmlErrorPtr xerror = xmlGetLastError();
92
+ const xmlError *xerror = xmlGetLastError();
93
93
  rxml_raise(xerror);
94
94
  }
95
95
 
@@ -320,7 +320,7 @@ rxml_xpath_context_enable_cache(int argc, VALUE *argv, VALUE self)
320
320
  }
321
321
 
322
322
  if (xmlXPathContextSetCache(xctxt, 1, value, 0) == -1)
323
- rxml_raise(&xmlLastError);
323
+ rxml_raise(xmlGetLastError());
324
324
 
325
325
  return self;
326
326
  }
@@ -338,7 +338,7 @@ rxml_xpath_context_disable_cache(VALUE self)
338
338
  Data_Get_Struct(self, xmlXPathContext, xctxt);
339
339
 
340
340
  if (xmlXPathContextSetCache(xctxt, 0, 0, 0) == -1)
341
- rxml_raise(&xmlLastError);
341
+ rxml_raise(xmlGetLastError());
342
342
 
343
343
  return self;
344
344
  }
@@ -64,7 +64,7 @@ static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression)
64
64
 
65
65
  if (compexpr == NULL)
66
66
  {
67
- xmlErrorPtr xerror = xmlGetLastError();
67
+ const xmlError *xerror = xmlGetLastError();
68
68
  rxml_raise(xerror);
69
69
  }
70
70
 
@@ -17,21 +17,21 @@ module LibXML
17
17
 
18
18
  # call-seq:
19
19
  # XML::Document.file(path) -> XML::Document
20
- # XML::Document.file(path, :encoding => XML::Encoding::UTF_8,
21
- # :options => XML::Parser::Options::NOENT) -> XML::Document
20
+ # XML::Document.file(path, encoding: XML::Encoding::UTF_8,
21
+ # options: XML::Parser::Options::NOENT) -> XML::Document
22
22
  #
23
23
  # Creates a new document from the specified file or uri.
24
24
  #
25
- # You may provide an optional hash table to control how the
26
- # parsing is performed. Valid options are:
25
+ # Parameters:
27
26
  #
27
+ # path - Path to file
28
28
  # encoding - The document encoding, defaults to nil. Valid values
29
29
  # are the encoding constants defined on XML::Encoding.
30
30
  # options - Parser options. Valid values are the constants defined on
31
31
  # XML::Parser::Options. Mutliple options can be combined
32
32
  # by using Bitwise OR (|).
33
- def self.file(value, options = {})
34
- Parser.file(value, options).parse
33
+ def self.file(path, encoding: nil, options: nil)
34
+ Parser.file(path, encoding: encoding, options: options).parse
35
35
  end
36
36
 
37
37
  # call-seq:
@@ -57,23 +57,23 @@ module LibXML
57
57
 
58
58
  # call-seq:
59
59
  # XML::Document.string(string) -> XML::Document
60
- # XML::Document.string(string, :encoding => XML::Encoding::UTF_8,
61
- # :options => XML::Parser::Options::NOENT
62
- # :base_uri="http://libxml.org") -> XML::Document
60
+ # XML::Document.string(string, encoding: XML::Encoding::UTF_8,
61
+ # options: XML::Parser::Options::NOENT
62
+ # base_uri: "http://libxml.org") -> XML::Document
63
63
  #
64
64
  # Creates a new document from the specified string.
65
65
  #
66
- # You may provide an optional hash table to control how the
67
- # parsing is performed. Valid options are:
66
+ # Parameters:
68
67
  #
68
+ # string - String to parse
69
69
  # base_uri - The base url for the parsed document.
70
70
  # encoding - The document encoding, defaults to nil. Valid values
71
71
  # are the encoding constants defined on XML::Encoding.
72
72
  # options - Parser options. Valid values are the constants defined on
73
73
  # XML::Parser::Options. Mutliple options can be combined
74
74
  # by using Bitwise OR (|).
75
- def self.string(value, options = {})
76
- Parser.string(value, options).parse
75
+ def self.string(value, base_uri: nil, encoding: nil, options: nil)
76
+ Parser.string(value, base_uri: base_uri, encoding: encoding, options: options).parse
77
77
  end
78
78
 
79
79
  # Returns a new XML::XPathContext for the document.