libxml-ruby 3.2.0 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY +23 -1
- data/README.rdoc +52 -36
- data/Rakefile +24 -16
- data/ext/libxml/ruby_xml.c +4 -0
- 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_namespace.c +1 -0
- data/ext/libxml/ruby_xml_node.c +8 -4
- data/ext/libxml/ruby_xml_schema.c +151 -79
- data/ext/libxml/ruby_xml_schema.h +2 -5
- data/ext/libxml/ruby_xml_schema_attribute.c +23 -71
- data/ext/libxml/ruby_xml_schema_element.c +28 -54
- data/ext/libxml/ruby_xml_schema_facet.c +15 -21
- data/ext/libxml/ruby_xml_schema_type.c +19 -37
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +189 -192
- data/libxml-ruby.gemspec +1 -1
- data/test/model/shiporder.rnc +2 -2
- data/test/model/shiporder.rng +2 -2
- data/test/model/shiporder.xsd +7 -3
- data/test/model/shiporder_bad.xsd +40 -0
- data/test/model/shiporder_import.xsd +45 -0
- data/test/test_document.rb +111 -110
- data/test/test_dtd.rb +2 -1
- data/test/test_helper.rb +2 -0
- data/test/test_parser.rb +1 -1
- data/test/test_parser_context.rb +3 -9
- data/test/test_reader.rb +2 -1
- data/test/test_sax_parser.rb +13 -6
- data/test/test_schema.rb +92 -29
- data/test/test_writer.rb +48 -25
- data/test/test_xml.rb +2 -1
- metadata +11 -10
- data/ext/libxml/extconf.h +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5173bcced46009decd7e7a710aaf20b4005cf8baa5e8ee55148cb28733fd3c97
|
4
|
+
data.tar.gz: 3649de749c1064ec31c3d563a1328abfb43e401372beb6af4b0b5ad891af1ae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f5e71808404d9553073ae483c15a55b4d72e7a0e5b40939c7f2c72c8867386e7c7489769f6da2ce7da13cbbbd3329f0851d949f6dc48d7c5b40d9ec5784b630
|
7
|
+
data.tar.gz: 731d9152dca3cf219af862eb67171b9e5cce8df6c8bde4262eae3c53f1a5528e211188a50b472be67e3a294cf4b4f0d2a239317b5c08a3b2886b5e9c5fece14a
|
data/HISTORY
CHANGED
@@ -1,10 +1,32 @@
|
|
1
1
|
= Release History
|
2
2
|
|
3
|
+
== 3.2.3 / 2022-05-22
|
4
|
+
|
5
|
+
* Change some getter methods to instance variables with attr_accessors for easier debuggability (David Hansen)
|
6
|
+
* Add a number of tests related to schemas (David Hansen)
|
7
|
+
* Add schema.imported_elements so we can find imported elements (David Hansen)
|
8
|
+
* Fix segfault under windows when dereferencing a pre-existing error where the node has already been freed (David Hansen)
|
9
|
+
* Update to change name from imported_elements to imported_ns_elements and return a hash of hashes for namespaced elements (David Hansen)
|
10
|
+
* Only call xmlGetFeaturesList if LIBXML_LEGACY_ENABLED is defined. Most distros still ship libxml2 with legacy features enabled, but this will change (Nick Wellnhofer)
|
11
|
+
* Update GitHub Actions to use ruby/setup-ruby (Greg)
|
12
|
+
* Fix memory leak in rxml_node_path, node.path (vovanmozg)
|
13
|
+
|
14
|
+
== 3.2.2 / 2022-01-15
|
15
|
+
* Switch to Github actions for CI/CD (Greg)
|
16
|
+
* Test fixes (Greg, Sergio Durigan Junior)
|
17
|
+
* Fix typo on test/test_sax_parser.rb (Sergio Durigan Junior)
|
18
|
+
* Update homepage in gemspec (Pirate Praveen Arimbrathodiyil)
|
19
|
+
|
20
|
+
== 3.2.1 / 2020-11-05
|
21
|
+
|
22
|
+
* Fix incorrect handling of encodings when using XMLWriter.io (Charlie Savage)
|
23
|
+
* Clean up README (Richard Michael)
|
24
|
+
|
3
25
|
== 3.2.0 / 2020-05-09 Charlie Savage
|
4
26
|
|
5
27
|
* Fix crash when creating an empty DTD
|
6
28
|
* Modernize tests to use Bundler to load gem
|
7
|
-
* Add libxml-ruby.rb file so gem loads in
|
29
|
+
* Add libxml-ruby.rb file so gem loads in expected way.
|
8
30
|
* Add support for xmlSaveNoEmptyTags.
|
9
31
|
* Clean up extconf.rb file
|
10
32
|
|
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
|
-
|
data/Rakefile
CHANGED
@@ -16,21 +16,29 @@ spec = Gem::Specification.load("#{GEM_NAME}.gemspec")
|
|
16
16
|
task :default => [:test]
|
17
17
|
|
18
18
|
# Setup compile tasks
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
ext.config_options <<
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
19
|
+
Rake::ExtensionTask.new do |ext|
|
20
|
+
ext.gem_spec = spec
|
21
|
+
ext.name = SO_NAME
|
22
|
+
ext.ext_dir = "ext/libxml"
|
23
|
+
ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}"
|
24
|
+
if RUBY_PLATFORM.match(/mswin|mingw/)
|
25
|
+
ext.config_options <<
|
26
|
+
if (dir = ENV['WINDOWS_XML2_INCLUDE'])
|
27
|
+
"--with-xml2-include=#{dir}"
|
28
|
+
else
|
29
|
+
case RUBY_PLATFORM
|
30
|
+
when 'i386-mingw32'
|
31
|
+
'--with-xml2-include=C:/msys64/mingw32/include/libxml2'
|
32
|
+
when 'x64-mingw32'
|
33
|
+
'--with-xml2-include=C:/msys64/mingw64/include/libxml2'
|
34
|
+
when 'x64-mingw-ucrt'
|
35
|
+
'--with-xml2-include=C:/msys64/ucrt64/include/libxml2'
|
36
|
+
else
|
37
|
+
raise "Unknown Windows Ruby, please set ENV['WINDOWS_XML2_INCLUDE']"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
ext.config_options << '--with-xml2-include=/usr/include/libxml2'
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
@@ -41,7 +49,7 @@ Gem::PackageTask.new(spec) do |pkg|
|
|
41
49
|
end
|
42
50
|
|
43
51
|
# Setup Windows Gem
|
44
|
-
if RUBY_PLATFORM.match(/
|
52
|
+
if RUBY_PLATFORM.match(/mswin|mingw/)
|
45
53
|
binaries = (FileList['lib/**/*.so',
|
46
54
|
'lib/**/*dll'])
|
47
55
|
|
data/ext/libxml/ruby_xml.c
CHANGED
@@ -764,6 +764,9 @@ static VALUE rxml_default_save_no_empty_tags_set(VALUE klass, VALUE value)
|
|
764
764
|
*/
|
765
765
|
static VALUE rxml_features(VALUE klass)
|
766
766
|
{
|
767
|
+
#ifndef LIBXML_LEGACY_ENABLED
|
768
|
+
return Qnil;
|
769
|
+
#else
|
767
770
|
VALUE arr, str;
|
768
771
|
int i, len = MAX_LIBXML_FEATURES_LEN;
|
769
772
|
char **list = NULL;
|
@@ -788,6 +791,7 @@ static VALUE rxml_features(VALUE klass)
|
|
788
791
|
|
789
792
|
ruby_xfree(list);
|
790
793
|
return (arr);
|
794
|
+
#endif /* LIBXML_LEGACY_ENABLED */
|
791
795
|
}
|
792
796
|
|
793
797
|
/*
|
@@ -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
@@ -52,6 +52,7 @@ static VALUE rxml_namespace_initialize(VALUE self, VALUE node, VALUE prefix,
|
|
52
52
|
|
53
53
|
Check_Type(node, T_DATA);
|
54
54
|
Data_Get_Struct(node, xmlNode, xnode);
|
55
|
+
xmlResetLastError();
|
55
56
|
|
56
57
|
/* Prefix can be null - that means its the default namespace */
|
57
58
|
xmlPrefix = NIL_P(prefix) ? NULL : (xmlChar *)StringValuePtr(prefix);
|
data/ext/libxml/ruby_xml_node.c
CHANGED
@@ -983,14 +983,18 @@ static VALUE rxml_node_path(VALUE self)
|
|
983
983
|
{
|
984
984
|
xmlNodePtr xnode;
|
985
985
|
xmlChar *path;
|
986
|
+
VALUE result = Qnil;
|
986
987
|
|
987
988
|
xnode = rxml_get_xnode(self);
|
988
989
|
path = xmlGetNodePath(xnode);
|
989
990
|
|
990
|
-
if (path
|
991
|
-
|
992
|
-
|
993
|
-
|
991
|
+
if (path)
|
992
|
+
{
|
993
|
+
result = rxml_new_cstr( path, NULL);
|
994
|
+
xmlFree(path);
|
995
|
+
}
|
996
|
+
|
997
|
+
return result;
|
994
998
|
}
|
995
999
|
|
996
1000
|
/*
|