libxml-ruby 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY +6 -1
- data/README.rdoc +52 -36
- data/ext/libxml/ruby_xml_document.c +0 -4
- data/ext/libxml/ruby_xml_encoding.c +1 -13
- data/ext/libxml/ruby_xml_encoding.h +0 -3
- data/ext/libxml/ruby_xml_io.c +14 -18
- data/ext/libxml/ruby_xml_io.h +1 -1
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +189 -192
- data/test/test.xml +2 -0
- data/test/test_document.rb +109 -109
- data/test/test_parser_context.rb +2 -2
- data/test/test_writer.rb +48 -25
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8b07d4dd732e06fdc8d4ffefcc9f9ea4a2a70faf8504bfdc1ef064e466656f9
|
4
|
+
data.tar.gz: 31fb804f2d87c2b3db049eb24eb2086bbaadc8a3850314060bc066fa87b078f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21126d00b18029300b5d49d32d4534071453d1dfb76e51fbc86d311e47779e606885fe792ca3bc58aab98bafe8dc3e4153cefce5f9bdb41db47755fba00ed44f
|
7
|
+
data.tar.gz: f510878992373c898082dfd6291bf6fb4d1b8d096095d08ec2a2550ca99f3b0bcc22b53d230f314e05a3e3fed17e8caf3fea9cc49f5fa682b6c39d44ece876db
|
data/HISTORY
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
= Release History
|
2
2
|
|
3
|
+
== 3.2.1 / 2020-11-05
|
4
|
+
|
5
|
+
* Fix incorrect handling of encodings when using XMLWriter.io (Charlie Savage)
|
6
|
+
* Clean up README (Richard Michael)
|
7
|
+
|
3
8
|
== 3.2.0 / 2020-05-09 Charlie Savage
|
4
9
|
|
5
10
|
* Fix crash when creating an empty DTD
|
6
11
|
* Modernize tests to use Bundler to load gem
|
7
|
-
* Add libxml-ruby.rb file so gem loads in
|
12
|
+
* Add libxml-ruby.rb file so gem loads in expected way.
|
8
13
|
* Add support for xmlSaveNoEmptyTags.
|
9
14
|
* Clean up extconf.rb file
|
10
15
|
|
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ We think libxml-ruby is the best XML library for Ruby because:
|
|
12
12
|
|
13
13
|
== Requirements
|
14
14
|
libxml-ruby requires Ruby 1.8.7 or higher. It depends on libxml2 to
|
15
|
-
function
|
15
|
+
function properly. libxml2, in turn, depends on:
|
16
16
|
|
17
17
|
* libm (math routines: very standard)
|
18
18
|
* libz (zlib)
|
@@ -21,25 +21,41 @@ function propoerly. libxml2, in turn, depends on:
|
|
21
21
|
If you are running Linux or Unix you'll need a C compiler so the
|
22
22
|
extension can be compiled when it is installed. If you are running
|
23
23
|
Windows, then install the x64-mingw32 gem or build it yourself using
|
24
|
-
Devkit
|
25
|
-
msys2
|
24
|
+
Devkit[http://rubyinstaller.org/add-ons/devkit/] or
|
25
|
+
msys2[https://msys2.github.io/].
|
26
26
|
|
27
|
-
==
|
28
|
-
The easiest way to install libxml-ruby is via
|
27
|
+
== Installation
|
28
|
+
The easiest way to install libxml-ruby is via RubyGems. To install:
|
29
29
|
|
30
30
|
<tt>gem install libxml-ruby</tt>
|
31
31
|
|
32
|
+
If the extension compile process cannot find libxml2, you may need to indicate
|
33
|
+
the location of the libxml2 configuration utility as it is used to find the
|
34
|
+
required header and include files. (If you need to indicate a location for the
|
35
|
+
libxml2 library or header files different than reported by <tt>xml2-config</tt>,
|
36
|
+
see the additional configuration options.)
|
37
|
+
|
38
|
+
This may be done with RubyGems:
|
39
|
+
|
40
|
+
<tt>gem install libxml-ruby -- --with-xml2-dir=/path/to/xml2-config</tt>
|
41
|
+
|
42
|
+
Or bundler:
|
43
|
+
|
44
|
+
<tt>bundle config build.libxml-ruby --with-xml2-config=/path/to/xml2-config</tt>
|
45
|
+
|
46
|
+
<tt>bundle install libxml-ruby</tt>
|
47
|
+
|
32
48
|
If you are running Windows, then install the libxml-ruby-x64-mingw32 gem.
|
33
|
-
|
49
|
+
The gem includes prebuilt extensions for Ruby 2.3. These
|
34
50
|
extensions are built using MinGW64 and libxml2 version 2.9.3,
|
35
51
|
iconv version 1.14 and zlib version 1.2.8. Note these binaries
|
36
|
-
are available in the lib
|
37
|
-
|
52
|
+
are available in the <tt>lib\\libs</tt> directory. To use them, put them
|
53
|
+
on your <tt>PATH</tt>.
|
38
54
|
|
39
55
|
The gem also includes a Microsoft VC++ 2012 solution and XCode 5 project - these
|
40
56
|
are very useful for debugging.
|
41
57
|
|
42
|
-
libxml-ruby's source codes lives on
|
58
|
+
libxml-ruby's source codes lives on GitHub[https://github.com/xml4r/libxml-ruby].
|
43
59
|
|
44
60
|
== Getting Started
|
45
61
|
Using libxml is easy. First decide what parser you want to use:
|
@@ -60,7 +76,7 @@ Beyond the basics of parsing and processing XML and HTML documents,
|
|
60
76
|
libxml provides a wealth of additional functionality.
|
61
77
|
|
62
78
|
Most commonly, you'll want to use its LibXML::XML::XPath support, which makes
|
63
|
-
it easy to find data inside
|
79
|
+
it easy to find data inside an XML document. Although not as popular,
|
64
80
|
LibXML::XML::XPointer provides another API for finding data inside an XML document.
|
65
81
|
|
66
82
|
Often times you'll need to validate data before processing it. For example,
|
@@ -72,17 +88,16 @@ This can be done using libxml's powerful set of validators:
|
|
72
88
|
* Relax Schemas (LibXML::XML::RelaxNG)
|
73
89
|
* XML Schema (LibXML::XML::Schema)
|
74
90
|
|
75
|
-
Finally, if you'd like to use XSL Transformations to process data,
|
76
|
-
|
77
|
-
https://github.com/xml4r/libxslt-ruby.
|
91
|
+
Finally, if you'd like to use XSL Transformations to process data, then install
|
92
|
+
the {libxslt gem}[https://github.com/xml4r/libxslt-rubygem].
|
78
93
|
|
79
94
|
== Usage
|
80
|
-
For information about using libxml-ruby please refer to its
|
81
|
-
http://xml4r.github.
|
82
|
-
available
|
95
|
+
For information about using libxml-ruby please refer to its
|
96
|
+
documentation[http://xml4r.github.io/libxml-ruby]. Some tutorials are also
|
97
|
+
available[https://github.com/xml4r/libxml-ruby/wiki].
|
83
98
|
|
84
99
|
All libxml classes are in the LibXML::XML module. The easiest
|
85
|
-
way to use libxml is to require 'xml'
|
100
|
+
way to use libxml is to <tt>require 'xml'</tt>. This will mixin
|
86
101
|
the LibXML module into the global namespace, allowing you to
|
87
102
|
write code like this:
|
88
103
|
|
@@ -131,10 +146,11 @@ Once you have build the shared libary, you can then run tests using rake:
|
|
131
146
|
+Travis build status: {<img src="https://travis-ci.org/xml4r/libxml-ruby.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/xml4r/libxml-ruby]
|
132
147
|
|
133
148
|
== Performance
|
149
|
+
|
134
150
|
In addition to being feature rich and conformation, the main reason
|
135
|
-
people use libxml-ruby is for performance. Here are the results
|
151
|
+
people use libxml-ruby is for performance. Here are the results
|
136
152
|
of a couple simple benchmarks recently blogged about on the
|
137
|
-
Web (you can find them in the benchmark directory of the
|
153
|
+
Web (you can find them in the benchmark directory of the
|
138
154
|
libxml distribution).
|
139
155
|
|
140
156
|
From http://depixelate.com/2008/4/23/ruby-xml-parsing-benchmarks
|
@@ -156,46 +172,46 @@ From https://svn.concord.org/svn/projects/trunk/common/ruby/xml_benchmarks/
|
|
156
172
|
Documentation is available via rdoc, and is installed automatically with the
|
157
173
|
gem.
|
158
174
|
|
159
|
-
libxml-ruby's online
|
160
|
-
|
175
|
+
libxml-ruby's {online
|
176
|
+
documentation}[https://xml4r.github.io/libxml-ruby/rdoc/index.html] is generated
|
177
|
+
using Hanna, which is a development gem dependency.
|
161
178
|
|
162
179
|
Note that older versions of Rdoc, which ship with Ruby 1.8.x, will report
|
163
180
|
a number of errors. To avoid them, install Rdoc 2.1 or higher. Once you have
|
164
181
|
installed the gem, you'll have to disable the version of Rdoc that Ruby 1.8.x
|
165
|
-
includes. An easy way to do that is rename the directory
|
166
|
-
ruby/lib/ruby/1.8/
|
182
|
+
includes. An easy way to do that is rename the directory
|
183
|
+
<tt>ruby/lib/ruby/1.8/rdoc</tt> to
|
184
|
+
<tt>ruby/lib/ruby/1.8/rdoc_old</tt>.
|
167
185
|
|
168
186
|
== Support
|
169
|
-
|
170
|
-
|
171
|
-
Git Hub at https://github.com/xml4r/libxml-ruby/issues
|
187
|
+
If you have any questions about using libxml-ruby, please report an issue
|
188
|
+
on GitHub[https://github.com/xml4r/libxml-ruby/issues].
|
172
189
|
|
173
190
|
== Memory Management
|
174
191
|
libxml-ruby automatically manages memory associated with the
|
175
192
|
underlying libxml2 library. The bindings create a one-to-one mapping between
|
176
|
-
|
177
|
-
have a parent and do not belong to a document).
|
193
|
+
Ruby objects and libxml documents and libxml parent nodes (ie, nodes that do not
|
194
|
+
have a parent and do not belong to a document). In these cases,
|
178
195
|
the bindings manage the memory. They do this by installing a free
|
179
196
|
function and storing a back pointer to the Ruby object from the xmlnode
|
180
197
|
using the _private member on libxml structures. When the Ruby object
|
181
198
|
goes out of scope, the underlying libxml structure is freed. Libxml
|
182
|
-
itself then frees all child
|
199
|
+
itself then frees all child nodes (recursively).
|
183
200
|
|
184
201
|
For all other nodes (the vast majority), the bindings create temporary
|
185
202
|
Ruby objects that get freed once they go out of scope. Thus there can be
|
186
|
-
more than one
|
187
|
-
this from
|
188
|
-
overriden to check if two
|
203
|
+
more than one Ruby object pointing to the same xml node. To mostly hide
|
204
|
+
this from a programmer on the Ruby side, the <tt>#eql?</tt> and <tt>#==</tt> methods are
|
205
|
+
overriden to check if two Ruby objects wrap the same xmlnode. If they do,
|
189
206
|
then the methods return true. During the mark phase, each of these temporary
|
190
207
|
objects marks its owning document, thereby keeping the Ruby document object
|
191
208
|
alive and thus the xmldoc tree.
|
192
209
|
|
193
210
|
In the sweep phase of the garbage collector, or when a program ends,
|
194
|
-
there is no order to how Ruby objects are freed.
|
195
|
-
object is almost always freed before any
|
196
|
-
However, this is ok because those
|
211
|
+
there is no order to how Ruby objects are freed. In fact, the Ruby document
|
212
|
+
object is almost always freed before any Ruby objects that wrap child nodes.
|
213
|
+
However, this is ok because those Ruby objects do not have a free function
|
197
214
|
and are no longer in scope (since if they were the document would not be freed).
|
198
215
|
|
199
216
|
== License
|
200
217
|
See LICENSE for license information.
|
201
|
-
|
@@ -483,7 +483,6 @@ static VALUE rxml_document_encoding_get(VALUE self)
|
|
483
483
|
* Returns the Ruby encoding specified by this document
|
484
484
|
* (available on Ruby 1.9.x and higher).
|
485
485
|
*/
|
486
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
487
486
|
static VALUE rxml_document_rb_encoding_get(VALUE self)
|
488
487
|
{
|
489
488
|
xmlDocPtr xdoc;
|
@@ -493,7 +492,6 @@ static VALUE rxml_document_rb_encoding_get(VALUE self)
|
|
493
492
|
rbencoding = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlParseCharEncoding((const char*)xdoc->encoding));
|
494
493
|
return rb_enc_from_encoding(rbencoding);
|
495
494
|
}
|
496
|
-
#endif
|
497
495
|
|
498
496
|
/*
|
499
497
|
* call-seq:
|
@@ -1097,9 +1095,7 @@ void rxml_init_document(void)
|
|
1097
1095
|
rb_define_method(cXMLDocument, "compression?", rxml_document_compression_q, 0);
|
1098
1096
|
rb_define_method(cXMLDocument, "debug", rxml_document_debug, 0);
|
1099
1097
|
rb_define_method(cXMLDocument, "encoding", rxml_document_encoding_get, 0);
|
1100
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
1101
1098
|
rb_define_method(cXMLDocument, "rb_encoding", rxml_document_rb_encoding_get, 0);
|
1102
|
-
#endif
|
1103
1099
|
rb_define_method(cXMLDocument, "encoding=", rxml_document_encoding_set, 1);
|
1104
1100
|
rb_define_method(cXMLDocument, "import", rxml_document_import, 1);
|
1105
1101
|
rb_define_method(cXMLDocument, "last", rxml_document_last_get, 0);
|
@@ -74,7 +74,6 @@ static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding)
|
|
74
74
|
return rxml_new_cstr(xencoding, xencoding);
|
75
75
|
}
|
76
76
|
|
77
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
78
77
|
/*
|
79
78
|
* Converts an xmlCharEncoding enum value into a Ruby Encoding object (available
|
80
79
|
* on Ruby 1.9.* and higher).
|
@@ -179,26 +178,17 @@ rb_encoding* rxml_figure_encoding(const xmlChar* xencoding)
|
|
179
178
|
}
|
180
179
|
return result;
|
181
180
|
}
|
182
|
-
#endif
|
183
181
|
|
184
182
|
VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding)
|
185
183
|
{
|
186
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
187
184
|
rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
|
188
185
|
return rb_external_str_new_with_enc((const char*)xstr, strlen((const char*)xstr), rbencoding);
|
189
|
-
#else
|
190
|
-
return rb_str_new2((const char*)xstr);
|
191
|
-
#endif
|
192
186
|
}
|
193
187
|
|
194
188
|
VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding)
|
195
189
|
{
|
196
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
197
190
|
rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
|
198
191
|
return rb_external_str_new_with_enc((const char*)xstr, length, rbencoding);
|
199
|
-
#else
|
200
|
-
return rb_str_new((const char*)xstr, length);
|
201
|
-
#endif
|
202
192
|
}
|
203
193
|
|
204
194
|
void rxml_init_encoding(void)
|
@@ -207,9 +197,7 @@ void rxml_init_encoding(void)
|
|
207
197
|
rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1);
|
208
198
|
rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1);
|
209
199
|
|
210
|
-
|
211
|
-
// rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2);
|
212
|
-
#endif
|
200
|
+
rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2);
|
213
201
|
|
214
202
|
/* -1: No char encoding detected. */
|
215
203
|
rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR));
|
@@ -7,13 +7,10 @@ extern VALUE mXMLEncoding;
|
|
7
7
|
|
8
8
|
void rxml_init_encoding();
|
9
9
|
|
10
|
-
// Ruby 1.8/1.9 encoding compatibility
|
11
10
|
VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding);
|
12
11
|
VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding);
|
13
12
|
|
14
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
15
13
|
rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding);
|
16
14
|
rb_encoding* rxml_figure_encoding(const xmlChar* xencoding);
|
17
|
-
#endif
|
18
15
|
|
19
16
|
#endif
|
data/ext/libxml/ruby_xml_io.c
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
/* Please see the LICENSE file for copyright and distribution information */
|
2
2
|
|
3
3
|
#include "ruby_libxml.h"
|
4
|
+
#include <ruby/io.h>
|
4
5
|
|
5
6
|
static ID READ_METHOD;
|
6
|
-
#ifdef HAVE_RB_IO_BUFWRITE
|
7
|
-
#include <ruby/io.h>
|
8
|
-
#else
|
9
7
|
static ID WRITE_METHOD;
|
10
|
-
#endif /* !HAVE_RB_IO_BUFWRITE */
|
11
8
|
|
12
9
|
/* This method is called by libxml when it wants to read
|
13
10
|
more data from a stream. We go with the duck typing
|
@@ -27,25 +24,24 @@ int rxml_read_callback(void *context, char *buffer, int len)
|
|
27
24
|
return (int)size;
|
28
25
|
}
|
29
26
|
|
30
|
-
int rxml_write_callback(
|
27
|
+
int rxml_write_callback(VALUE io, const char *buffer, int len)
|
31
28
|
{
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
29
|
+
if (rb_io_check_io(io) == Qnil)
|
30
|
+
{
|
31
|
+
// Could be StringIO
|
32
|
+
VALUE written, string;
|
33
|
+
string = rb_external_str_new_with_enc(buffer, strlen(buffer), rb_enc_get(io));
|
34
|
+
written = rb_funcall(io, WRITE_METHOD, 1, string);
|
35
|
+
return NUM2INT(written);
|
36
|
+
}
|
37
|
+
else
|
38
|
+
{
|
39
|
+
return (int)rb_io_bufwrite(io, buffer, (size_t)len);
|
40
|
+
}
|
43
41
|
}
|
44
42
|
|
45
43
|
void rxml_init_io(void)
|
46
44
|
{
|
47
45
|
READ_METHOD = rb_intern("read");
|
48
|
-
#ifndef HAVE_RB_IO_BUFWRITE
|
49
46
|
WRITE_METHOD = rb_intern("write");
|
50
|
-
#endif /* !HAVE_RB_IO_BUFWRITE */
|
51
47
|
}
|
data/ext/libxml/ruby_xml_io.h
CHANGED
@@ -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 "3.2.
|
5
|
-
#define RUBY_LIBXML_VERNUM
|
4
|
+
#define RUBY_LIBXML_VERSION "3.2.1"
|
5
|
+
#define RUBY_LIBXML_VERNUM 321
|
6
6
|
#define RUBY_LIBXML_VER_MAJ 3
|
7
7
|
#define RUBY_LIBXML_VER_MIN 2
|
8
|
-
#define RUBY_LIBXML_VER_MIC
|
8
|
+
#define RUBY_LIBXML_VER_MIC 1
|
9
9
|
#define RUBY_LIBXML_VER_PATCH 0
|
@@ -19,57 +19,29 @@ static VALUE sEncoding, sStandalone;
|
|
19
19
|
#include <libxml/xmlwriter.h>
|
20
20
|
|
21
21
|
|
22
|
-
typedef enum
|
22
|
+
typedef enum
|
23
|
+
{
|
23
24
|
RXMLW_OUTPUT_NONE,
|
24
25
|
RXMLW_OUTPUT_IO,
|
25
26
|
RXMLW_OUTPUT_DOC,
|
26
27
|
RXMLW_OUTPUT_STRING
|
27
28
|
} rxmlw_output_type;
|
28
29
|
|
29
|
-
typedef struct
|
30
|
+
typedef struct
|
31
|
+
{
|
30
32
|
VALUE output;
|
31
|
-
|
32
|
-
rb_encoding *encoding;
|
33
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
33
|
+
rb_encoding* encoding;
|
34
34
|
xmlBufferPtr buffer;
|
35
35
|
xmlTextWriterPtr writer;
|
36
36
|
rxmlw_output_type output_type;
|
37
37
|
int closed;
|
38
38
|
} rxml_writer_object;
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \
|
43
|
-
rb_external_str_new_with_enc(string, string_len, rb_utf8_encoding())
|
44
|
-
|
45
|
-
#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \
|
46
|
-
rb_str_conv_enc(string, rb_enc_get(string), rb_utf8_encoding())
|
47
|
-
// rb_str_export_to_enc(string, rb_utf8_encoding())
|
48
|
-
|
49
|
-
#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \
|
50
|
-
do { \
|
51
|
-
if (orig != utf8) { \
|
52
|
-
rb_str_free(utf8); \
|
53
|
-
} \
|
54
|
-
} while (0);
|
55
|
-
|
56
|
-
#else
|
57
|
-
|
58
|
-
#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \
|
59
|
-
rb_str_new(string, string_len)
|
60
|
-
|
61
|
-
#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \
|
62
|
-
string
|
63
|
-
|
64
|
-
#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \
|
65
|
-
/* NOP */
|
66
|
-
|
67
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
68
|
-
|
69
|
-
static void rxml_writer_free(rxml_writer_object *rwo)
|
40
|
+
static void rxml_writer_free(rxml_writer_object* rwo)
|
70
41
|
{
|
71
42
|
#if 0 /* seems to be done by xmlFreeTextWriter */
|
72
|
-
if (NULL != rwo->buffer)
|
43
|
+
if (NULL != rwo->buffer)
|
44
|
+
{
|
73
45
|
xmlBufferFree(rwo->buffer);
|
74
46
|
}
|
75
47
|
#endif
|
@@ -79,36 +51,40 @@ static void rxml_writer_free(rxml_writer_object *rwo)
|
|
79
51
|
xfree(rwo);
|
80
52
|
}
|
81
53
|
|
82
|
-
static void rxml_writer_mark(rxml_writer_object
|
54
|
+
static void rxml_writer_mark(rxml_writer_object* rwo)
|
83
55
|
{
|
84
|
-
if (!NIL_P(rwo->output))
|
56
|
+
if (!NIL_P(rwo->output))
|
57
|
+
{
|
85
58
|
rb_gc_mark(rwo->output);
|
86
59
|
}
|
87
60
|
}
|
88
61
|
|
89
|
-
static VALUE rxml_writer_wrap(rxml_writer_object
|
62
|
+
static VALUE rxml_writer_wrap(rxml_writer_object* rwo)
|
90
63
|
{
|
91
64
|
return Data_Wrap_Struct(cXMLWriter, rxml_writer_mark, rxml_writer_free, rwo);
|
92
65
|
}
|
93
66
|
|
94
|
-
static rxml_writer_object
|
67
|
+
static rxml_writer_object* rxml_textwriter_get(VALUE obj)
|
95
68
|
{
|
96
|
-
rxml_writer_object
|
69
|
+
rxml_writer_object* rwo;
|
97
70
|
|
98
71
|
Data_Get_Struct(obj, rxml_writer_object, rwo);
|
99
72
|
|
100
73
|
return rwo;
|
101
74
|
}
|
102
75
|
|
103
|
-
int rxml_writer_write_callback(void
|
76
|
+
int rxml_writer_write_callback(void* context, const char* buffer, int len)
|
104
77
|
{
|
105
|
-
|
78
|
+
rxml_writer_object* rwo = context;
|
106
79
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
80
|
+
if (rwo->closed)
|
81
|
+
{
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
else
|
85
|
+
{
|
86
|
+
return rxml_write_callback(rwo->output, buffer, len);
|
87
|
+
}
|
112
88
|
}
|
113
89
|
|
114
90
|
/* ===== public class methods ===== */
|
@@ -120,31 +96,26 @@ int rxml_writer_write_callback(void *context, const char *buffer, int len)
|
|
120
96
|
*/
|
121
97
|
static VALUE rxml_writer_io(VALUE klass, VALUE io)
|
122
98
|
{
|
123
|
-
#if 0
|
124
|
-
typedef int (*xmlOutputCloseCallback)(void * context);
|
125
|
-
typedef int (*xmlOutputWriteCallback)(void * context, const char * buffer, int len);
|
126
|
-
|
127
|
-
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
|
128
|
-
|
129
|
-
xmlOutputBufferPtr xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, void * ioctx, xmlCharEncodingHandlerPtr encoder)
|
130
|
-
|
131
|
-
xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name);
|
132
|
-
#endif
|
133
99
|
xmlOutputBufferPtr out;
|
134
|
-
rxml_writer_object
|
100
|
+
rxml_writer_object* rwo;
|
135
101
|
|
136
102
|
rwo = ALLOC(rxml_writer_object);
|
137
103
|
rwo->output = io;
|
138
104
|
rwo->buffer = NULL;
|
139
105
|
rwo->closed = 0;
|
140
|
-
|
141
|
-
rwo->encoding
|
142
|
-
|
106
|
+
rwo->encoding = rb_enc_get(io);
|
107
|
+
if (!rwo->encoding)
|
108
|
+
rwo->encoding = rb_utf8_encoding();
|
109
|
+
|
143
110
|
rwo->output_type = RXMLW_OUTPUT_IO;
|
144
|
-
|
111
|
+
|
112
|
+
xmlCharEncodingHandlerPtr encodingHdlr = xmlFindCharEncodingHandler(rwo->encoding->name);
|
113
|
+
if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void*)rwo, encodingHdlr)))
|
114
|
+
{
|
145
115
|
rxml_raise(&xmlLastError);
|
146
116
|
}
|
147
|
-
if (NULL == (rwo->writer = xmlNewTextWriter(out)))
|
117
|
+
if (NULL == (rwo->writer = xmlNewTextWriter(out)))
|
118
|
+
{
|
148
119
|
rxml_raise(&xmlLastError);
|
149
120
|
}
|
150
121
|
|
@@ -160,17 +131,16 @@ xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name);
|
|
160
131
|
*/
|
161
132
|
static VALUE rxml_writer_file(VALUE klass, VALUE filename)
|
162
133
|
{
|
163
|
-
rxml_writer_object
|
134
|
+
rxml_writer_object* rwo;
|
164
135
|
|
165
136
|
rwo = ALLOC(rxml_writer_object);
|
166
137
|
rwo->output = Qnil;
|
167
138
|
rwo->buffer = NULL;
|
168
139
|
rwo->closed = 0;
|
169
|
-
|
170
|
-
rwo->encoding = NULL;
|
171
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
140
|
+
rwo->encoding = rb_utf8_encoding();
|
172
141
|
rwo->output_type = RXMLW_OUTPUT_NONE;
|
173
|
-
if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
|
142
|
+
if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
|
143
|
+
{
|
174
144
|
rxml_raise(&xmlLastError);
|
175
145
|
}
|
176
146
|
|
@@ -184,19 +154,19 @@ static VALUE rxml_writer_file(VALUE klass, VALUE filename)
|
|
184
154
|
*/
|
185
155
|
static VALUE rxml_writer_string(VALUE klass)
|
186
156
|
{
|
187
|
-
rxml_writer_object
|
157
|
+
rxml_writer_object* rwo;
|
188
158
|
|
189
159
|
rwo = ALLOC(rxml_writer_object);
|
190
160
|
rwo->output = Qnil;
|
191
161
|
rwo->closed = 0;
|
192
|
-
|
193
|
-
rwo->encoding = NULL;
|
194
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
162
|
+
rwo->encoding = rb_utf8_encoding();
|
195
163
|
rwo->output_type = RXMLW_OUTPUT_STRING;
|
196
|
-
if (NULL == (rwo->buffer = xmlBufferCreate()))
|
164
|
+
if (NULL == (rwo->buffer = xmlBufferCreate()))
|
165
|
+
{
|
197
166
|
rxml_raise(&xmlLastError);
|
198
167
|
}
|
199
|
-
if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
|
168
|
+
if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
|
169
|
+
{
|
200
170
|
xmlBufferFree(rwo->buffer);
|
201
171
|
rxml_raise(&xmlLastError);
|
202
172
|
}
|
@@ -212,17 +182,16 @@ static VALUE rxml_writer_string(VALUE klass)
|
|
212
182
|
static VALUE rxml_writer_doc(VALUE klass)
|
213
183
|
{
|
214
184
|
xmlDocPtr doc;
|
215
|
-
rxml_writer_object
|
185
|
+
rxml_writer_object* rwo;
|
216
186
|
|
217
187
|
rwo = ALLOC(rxml_writer_object);
|
218
188
|
rwo->buffer = NULL;
|
219
189
|
rwo->output = Qnil;
|
220
190
|
rwo->closed = 0;
|
221
|
-
|
222
|
-
rwo->encoding = NULL;
|
223
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
191
|
+
rwo->encoding = rb_utf8_encoding();
|
224
192
|
rwo->output_type = RXMLW_OUTPUT_DOC;
|
225
|
-
if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
|
193
|
+
if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
|
194
|
+
{
|
226
195
|
rxml_raise(&xmlLastError);
|
227
196
|
}
|
228
197
|
rwo->output = rxml_document_wrap(doc);
|
@@ -240,33 +209,34 @@ static VALUE rxml_writer_doc(VALUE klass)
|
|
240
209
|
* If +empty?+ is +true+, and for a in memory XML::Writer, this internel
|
241
210
|
* buffer is empty.
|
242
211
|
*/
|
243
|
-
static VALUE rxml_writer_flush(int argc, VALUE
|
212
|
+
static VALUE rxml_writer_flush(int argc, VALUE* argv, VALUE self)
|
244
213
|
{
|
245
214
|
int ret;
|
246
215
|
VALUE empty;
|
247
|
-
rxml_writer_object
|
216
|
+
rxml_writer_object* rwo;
|
248
217
|
|
249
218
|
rb_scan_args(argc, argv, "01", &empty);
|
250
219
|
|
251
220
|
rwo = rxml_textwriter_get(self);
|
252
|
-
if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
|
221
|
+
if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
|
222
|
+
{
|
253
223
|
rxml_raise(&xmlLastError);
|
254
224
|
}
|
255
225
|
|
256
|
-
if (NULL != rwo->buffer)
|
226
|
+
if (NULL != rwo->buffer)
|
227
|
+
{
|
257
228
|
VALUE content;
|
258
229
|
|
259
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
260
230
|
content = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
|
261
|
-
|
262
|
-
|
263
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
264
|
-
if (NIL_P(empty) || RTEST(empty)) { /* nil = default value = true */
|
231
|
+
if (NIL_P(empty) || RTEST(empty))
|
232
|
+
{ /* nil = default value = true */
|
265
233
|
xmlBufferEmpty(rwo->buffer);
|
266
234
|
}
|
267
235
|
|
268
236
|
return content;
|
269
|
-
}
|
237
|
+
}
|
238
|
+
else
|
239
|
+
{
|
270
240
|
return INT2NUM(ret);
|
271
241
|
}
|
272
242
|
}
|
@@ -281,26 +251,28 @@ static VALUE rxml_writer_flush(int argc, VALUE *argv, VALUE self)
|
|
281
251
|
static VALUE rxml_writer_result(VALUE self)
|
282
252
|
{
|
283
253
|
VALUE ret = Qnil;
|
284
|
-
rxml_writer_object
|
254
|
+
rxml_writer_object* rwo = rxml_textwriter_get(self);
|
285
255
|
int bytesWritten = xmlTextWriterFlush(rwo->writer);
|
286
256
|
|
287
|
-
if (bytesWritten == -1)
|
257
|
+
if (bytesWritten == -1)
|
258
|
+
{
|
288
259
|
rxml_raise(&xmlLastError);
|
289
260
|
}
|
290
261
|
|
291
|
-
switch (rwo->output_type)
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
262
|
+
switch (rwo->output_type)
|
263
|
+
{
|
264
|
+
case RXMLW_OUTPUT_DOC:
|
265
|
+
ret = rwo->output;
|
266
|
+
break;
|
267
|
+
case RXMLW_OUTPUT_STRING:
|
268
|
+
ret = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
|
269
|
+
break;
|
270
|
+
case RXMLW_OUTPUT_IO:
|
271
|
+
case RXMLW_OUTPUT_NONE:
|
272
|
+
break;
|
273
|
+
default:
|
274
|
+
rb_bug("unexpected output");
|
275
|
+
break;
|
304
276
|
}
|
305
277
|
|
306
278
|
return ret;
|
@@ -311,7 +283,7 @@ static VALUE rxml_writer_result(VALUE self)
|
|
311
283
|
static VALUE numeric_rxml_writer_void(VALUE obj, int (*fn)(xmlTextWriterPtr))
|
312
284
|
{
|
313
285
|
int ret;
|
314
|
-
rxml_writer_object
|
286
|
+
rxml_writer_object* rwo;
|
315
287
|
|
316
288
|
rwo = rxml_textwriter_get(obj);
|
317
289
|
ret = fn(rwo->writer);
|
@@ -335,88 +307,102 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_
|
|
335
307
|
{
|
336
308
|
va_list ap;
|
337
309
|
size_t argc;
|
338
|
-
|
339
|
-
rxml_writer_object
|
340
|
-
const xmlChar
|
310
|
+
int ret = -1;
|
311
|
+
rxml_writer_object* rwo;
|
312
|
+
const xmlChar* argv[XMLWRITER_MAX_STRING_ARGS];
|
341
313
|
VALUE utf8[XMLWRITER_MAX_STRING_ARGS], orig[XMLWRITER_MAX_STRING_ARGS];
|
342
314
|
|
343
|
-
if (strings_count > XMLWRITER_MAX_STRING_ARGS)
|
315
|
+
if (strings_count > XMLWRITER_MAX_STRING_ARGS)
|
316
|
+
{
|
344
317
|
rb_bug("more arguments than expected");
|
345
318
|
}
|
346
319
|
va_start(ap, fn);
|
347
320
|
rwo = rxml_textwriter_get(obj);
|
348
|
-
for (argc = 0; argc < strings_count; argc++)
|
321
|
+
for (argc = 0; argc < strings_count; argc++)
|
322
|
+
{
|
349
323
|
VALUE arg;
|
350
324
|
|
351
325
|
arg = va_arg(ap, VALUE);
|
352
326
|
orig[argc] = arg;
|
353
|
-
if (NIL_P(arg))
|
327
|
+
if (NIL_P(arg))
|
328
|
+
{
|
354
329
|
utf8[argc] = Qnil;
|
355
330
|
argv[argc] = NULL;
|
356
|
-
}
|
357
|
-
|
331
|
+
}
|
332
|
+
else
|
333
|
+
{
|
334
|
+
utf8[argc] = rb_str_conv_enc(orig[argc], rb_enc_get(orig[argc]), rwo->encoding);
|
358
335
|
argv[argc] = BAD_CAST StringValueCStr(utf8[argc]);
|
359
336
|
}
|
360
337
|
}
|
361
338
|
va_end(ap);
|
362
339
|
|
363
|
-
if (Qundef == pe)
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
340
|
+
if (Qundef == pe)
|
341
|
+
{
|
342
|
+
switch (strings_count)
|
343
|
+
{
|
344
|
+
case 0:
|
345
|
+
ret = fn(rwo->writer);
|
346
|
+
break;
|
347
|
+
case 1:
|
348
|
+
ret = fn(rwo->writer, argv[0]);
|
349
|
+
break;
|
350
|
+
case 2:
|
351
|
+
ret = fn(rwo->writer, argv[0], argv[1]);
|
352
|
+
break;
|
353
|
+
case 3:
|
354
|
+
ret = fn(rwo->writer, argv[0], argv[1], argv[2]);
|
355
|
+
break;
|
356
|
+
case 4:
|
357
|
+
ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3]);
|
358
|
+
break;
|
359
|
+
case 5:
|
360
|
+
ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3], argv[4]);
|
361
|
+
break;
|
362
|
+
default:
|
363
|
+
break;
|
385
364
|
}
|
386
|
-
}
|
365
|
+
}
|
366
|
+
else
|
367
|
+
{
|
387
368
|
int xpe;
|
388
369
|
|
389
370
|
xpe = RTEST(pe);
|
390
|
-
switch (strings_count)
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
371
|
+
switch (strings_count)
|
372
|
+
{ /* strings_count doesn't include pe */
|
373
|
+
case 0:
|
374
|
+
ret = fn(rwo->writer, xpe);
|
375
|
+
break;
|
376
|
+
case 1:
|
377
|
+
ret = fn(rwo->writer, xpe, argv[0]);
|
378
|
+
break;
|
379
|
+
case 2:
|
380
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1]);
|
381
|
+
break;
|
382
|
+
case 3:
|
383
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2]);
|
384
|
+
break;
|
385
|
+
case 4:
|
386
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3]);
|
387
|
+
break;
|
388
|
+
case 5:
|
389
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3], argv[4]);
|
390
|
+
break;
|
391
|
+
default:
|
392
|
+
break;
|
411
393
|
}
|
412
394
|
}
|
413
|
-
|
414
|
-
while (--strings_count > 0)
|
415
|
-
|
416
|
-
|
395
|
+
|
396
|
+
while (--strings_count > 0)
|
397
|
+
{
|
398
|
+
if (!NIL_P(orig[strings_count]))
|
399
|
+
{
|
400
|
+
if (orig[strings_count] != utf8[strings_count])
|
401
|
+
{
|
402
|
+
rb_str_free(utf8[strings_count]);
|
403
|
+
}
|
417
404
|
}
|
418
405
|
}
|
419
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
420
406
|
|
421
407
|
return (-1 == ret ? Qfalse : Qtrue);
|
422
408
|
}
|
@@ -434,7 +420,7 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_
|
|
434
420
|
static VALUE rxml_writer_set_indent(VALUE self, VALUE indentation)
|
435
421
|
{
|
436
422
|
int ret;
|
437
|
-
rxml_writer_object
|
423
|
+
rxml_writer_object* rwo;
|
438
424
|
|
439
425
|
rwo = rxml_textwriter_get(self);
|
440
426
|
ret = xmlTextWriterSetIndent(rwo->writer, RTEST(indentation));
|
@@ -484,7 +470,7 @@ static VALUE rxml_writer_write_cdata(VALUE self, VALUE content)
|
|
484
470
|
}
|
485
471
|
|
486
472
|
static VALUE rxml_writer_start_element(VALUE, VALUE);
|
487
|
-
static VALUE rxml_writer_start_element_ns(int, VALUE
|
473
|
+
static VALUE rxml_writer_start_element_ns(int, VALUE*, VALUE);
|
488
474
|
static VALUE rxml_writer_end_element(VALUE);
|
489
475
|
|
490
476
|
/* call-seq:
|
@@ -494,17 +480,21 @@ static VALUE rxml_writer_end_element(VALUE);
|
|
494
480
|
* This is equivalent to start_element(name) + write_string(content) +
|
495
481
|
* end_element.
|
496
482
|
*/
|
497
|
-
static VALUE rxml_writer_write_element(int argc, VALUE
|
483
|
+
static VALUE rxml_writer_write_element(int argc, VALUE* argv, VALUE self)
|
498
484
|
{
|
499
485
|
VALUE name, content;
|
500
486
|
|
501
487
|
rb_scan_args(argc, argv, "11", &name, &content);
|
502
|
-
if (Qnil == content)
|
503
|
-
|
488
|
+
if (Qnil == content)
|
489
|
+
{
|
490
|
+
if (Qfalse == rxml_writer_start_element(self, name))
|
491
|
+
{
|
504
492
|
return Qfalse;
|
505
493
|
}
|
506
494
|
return rxml_writer_end_element(self);
|
507
|
-
}
|
495
|
+
}
|
496
|
+
else
|
497
|
+
{
|
508
498
|
return numeric_rxml_writer_va_strings(self, Qundef, 2, xmlTextWriterWriteElement, name, content);
|
509
499
|
}
|
510
500
|
}
|
@@ -526,19 +516,23 @@ static VALUE rxml_writer_write_element(int argc, VALUE *argv, VALUE self)
|
|
526
516
|
* earlier.
|
527
517
|
* - +content+ can be omitted for an empty tag
|
528
518
|
*/
|
529
|
-
static VALUE rxml_writer_write_element_ns(int argc, VALUE
|
519
|
+
static VALUE rxml_writer_write_element_ns(int argc, VALUE* argv, VALUE self)
|
530
520
|
{
|
531
521
|
VALUE prefix, name, namespaceURI, content;
|
532
522
|
|
533
523
|
rb_scan_args(argc, argv, "22", &prefix, &name, &namespaceURI, &content);
|
534
|
-
if (Qnil == content)
|
524
|
+
if (Qnil == content)
|
525
|
+
{
|
535
526
|
VALUE argv[3] = { prefix, name, namespaceURI };
|
536
527
|
|
537
|
-
if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self))
|
528
|
+
if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self))
|
529
|
+
{
|
538
530
|
return Qfalse;
|
539
531
|
}
|
540
532
|
return rxml_writer_end_element(self);
|
541
|
-
}
|
533
|
+
}
|
534
|
+
else
|
535
|
+
{
|
542
536
|
return numeric_rxml_writer_va_strings(self, Qundef, 4, xmlTextWriterWriteElementNS, prefix, name, namespaceURI, content);
|
543
537
|
}
|
544
538
|
}
|
@@ -568,7 +562,7 @@ static VALUE rxml_writer_write_attribute(VALUE self, VALUE name, VALUE content)
|
|
568
562
|
* earlier.
|
569
563
|
* - +content+ can be omitted too for an empty attribute
|
570
564
|
*/
|
571
|
-
static VALUE rxml_writer_write_attribute_ns(int argc, VALUE
|
565
|
+
static VALUE rxml_writer_write_attribute_ns(int argc, VALUE* argv, VALUE self)
|
572
566
|
{
|
573
567
|
VALUE prefix, name, namespaceURI, content;
|
574
568
|
|
@@ -634,7 +628,7 @@ static VALUE rxml_writer_start_attribute(VALUE self, VALUE name)
|
|
634
628
|
* +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
|
635
629
|
* prefix somewhere earlier.
|
636
630
|
*/
|
637
|
-
static VALUE rxml_writer_start_attribute_ns(int argc, VALUE
|
631
|
+
static VALUE rxml_writer_start_attribute_ns(int argc, VALUE* argv, VALUE self)
|
638
632
|
{
|
639
633
|
VALUE prefix, name, namespaceURI;
|
640
634
|
|
@@ -697,7 +691,7 @@ static VALUE rxml_writer_start_element(VALUE self, VALUE name)
|
|
697
691
|
* +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
|
698
692
|
* prefix somewhere earlier.
|
699
693
|
*/
|
700
|
-
static VALUE rxml_writer_start_element_ns(int argc, VALUE
|
694
|
+
static VALUE rxml_writer_start_element_ns(int argc, VALUE* argv, VALUE self)
|
701
695
|
{
|
702
696
|
VALUE prefix, name, namespaceURI;
|
703
697
|
|
@@ -762,16 +756,17 @@ static VALUE rxml_writer_end_cdata(VALUE self)
|
|
762
756
|
* - standalone: nil (default) or a boolean to indicate if the document is
|
763
757
|
* standalone or not
|
764
758
|
*/
|
765
|
-
static VALUE rxml_writer_start_document(int argc, VALUE
|
759
|
+
static VALUE rxml_writer_start_document(int argc, VALUE* argv, VALUE self)
|
766
760
|
{
|
767
761
|
int ret;
|
768
762
|
VALUE options = Qnil;
|
769
|
-
rxml_writer_object
|
770
|
-
const xmlChar
|
771
|
-
const char
|
763
|
+
rxml_writer_object* rwo;
|
764
|
+
const xmlChar* xencoding = NULL;
|
765
|
+
const char* xstandalone = NULL;
|
772
766
|
|
773
767
|
rb_scan_args(argc, argv, "01", &options);
|
774
|
-
if (!NIL_P(options))
|
768
|
+
if (!NIL_P(options))
|
769
|
+
{
|
775
770
|
VALUE encoding, standalone;
|
776
771
|
|
777
772
|
encoding = standalone = Qnil;
|
@@ -779,16 +774,17 @@ static VALUE rxml_writer_start_document(int argc, VALUE *argv, VALUE self)
|
|
779
774
|
encoding = rb_hash_aref(options, sEncoding);
|
780
775
|
xencoding = NIL_P(encoding) ? NULL : (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding));
|
781
776
|
standalone = rb_hash_aref(options, sStandalone);
|
782
|
-
if (NIL_P(standalone))
|
777
|
+
if (NIL_P(standalone))
|
778
|
+
{
|
783
779
|
xstandalone = NULL;
|
784
|
-
}
|
780
|
+
}
|
781
|
+
else
|
782
|
+
{
|
785
783
|
xstandalone = RTEST(standalone) ? "yes" : "no";
|
786
784
|
}
|
787
785
|
}
|
788
786
|
rwo = rxml_textwriter_get(self);
|
789
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
790
787
|
rwo->encoding = rxml_figure_encoding(xencoding);
|
791
|
-
#endif /* !HAVE_RUBY_ENCODING_H */
|
792
788
|
ret = xmlTextWriterStartDocument(rwo->writer, NULL, (const char*)xencoding, xstandalone);
|
793
789
|
|
794
790
|
return (-1 == ret ? Qfalse : Qtrue);
|
@@ -829,7 +825,7 @@ static VALUE rxml_writer_end_pi(VALUE self)
|
|
829
825
|
*
|
830
826
|
* Starts a DTD. Returns +false+ on failure.
|
831
827
|
*/
|
832
|
-
static VALUE rxml_writer_start_dtd(int argc, VALUE
|
828
|
+
static VALUE rxml_writer_start_dtd(int argc, VALUE* argv, VALUE self)
|
833
829
|
{
|
834
830
|
VALUE name, pubid, sysid;
|
835
831
|
|
@@ -853,12 +849,13 @@ static VALUE rxml_writer_start_dtd_element(VALUE self, VALUE name)
|
|
853
849
|
*
|
854
850
|
* Starts a DTD entity (<!ENTITY ... >). Returns +false+ on failure.
|
855
851
|
*/
|
856
|
-
static VALUE rxml_writer_start_dtd_entity(int argc, VALUE
|
852
|
+
static VALUE rxml_writer_start_dtd_entity(int argc, VALUE* argv, VALUE self)
|
857
853
|
{
|
858
854
|
VALUE name, pe;
|
859
855
|
|
860
856
|
rb_scan_args(argc, argv, "11", &name, &pe);
|
861
|
-
if (NIL_P(pe))
|
857
|
+
if (NIL_P(pe))
|
858
|
+
{
|
862
859
|
pe = Qfalse;
|
863
860
|
}
|
864
861
|
|
@@ -934,7 +931,7 @@ static VALUE rxml_writer_end_dtd_element(VALUE self)
|
|
934
931
|
* writer.write_dtd 'person', nil, nil, '<!ELEMENT person (firstname,lastname)><!ELEMENT firstname (#PCDATA)><!ELEMENT lastname (#PCDATA)>'
|
935
932
|
* #=> <!DOCTYPE person [<!ELEMENT person (firstname,lastname)><!ELEMENT firstname (#PCDATA)><!ELEMENT lastname (#PCDATA)>]>
|
936
933
|
*/
|
937
|
-
static VALUE rxml_writer_write_dtd(int argc, VALUE
|
934
|
+
static VALUE rxml_writer_write_dtd(int argc, VALUE* argv, VALUE self)
|
938
935
|
{
|
939
936
|
VALUE name, pubid, sysid, subset;
|
940
937
|
|
@@ -1043,12 +1040,12 @@ static VALUE rxml_writer_write_dtd_notation(VALUE self, VALUE name, VALUE pubid,
|
|
1043
1040
|
static VALUE rxml_writer_set_quote_char(VALUE self, VALUE quotechar)
|
1044
1041
|
{
|
1045
1042
|
int ret;
|
1046
|
-
const char
|
1047
|
-
rxml_writer_object
|
1043
|
+
const char* xquotechar;
|
1044
|
+
rxml_writer_object* rwo;
|
1048
1045
|
|
1049
1046
|
rwo = rxml_textwriter_get(self);
|
1050
1047
|
xquotechar = StringValueCStr(quotechar);
|
1051
|
-
ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar)
|
1048
|
+
ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar)xquotechar[0]);
|
1052
1049
|
|
1053
1050
|
return (-1 == ret ? Qfalse : Qtrue);
|
1054
1051
|
}
|