libxml-ruby 3.0.0 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY +37 -0
  3. data/MANIFEST +34 -34
  4. data/README.rdoc +65 -36
  5. data/Rakefile +21 -3
  6. data/ext/libxml/extconf.rb +30 -26
  7. data/ext/libxml/ruby_libxml.h +0 -8
  8. data/ext/libxml/ruby_xml.c +40 -0
  9. data/ext/libxml/ruby_xml_document.c +1 -5
  10. data/ext/libxml/ruby_xml_dtd.c +6 -8
  11. data/ext/libxml/ruby_xml_encoding.c +1 -13
  12. data/ext/libxml/ruby_xml_encoding.h +0 -3
  13. data/ext/libxml/ruby_xml_error.c +1 -1
  14. data/ext/libxml/ruby_xml_error.h +1 -1
  15. data/ext/libxml/ruby_xml_io.c +14 -18
  16. data/ext/libxml/ruby_xml_io.h +1 -1
  17. data/ext/libxml/ruby_xml_node.c +16 -17
  18. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  19. data/ext/libxml/ruby_xml_reader.c +7 -2
  20. data/ext/libxml/ruby_xml_schema.c +44 -66
  21. data/ext/libxml/ruby_xml_schema_element.c +15 -14
  22. data/ext/libxml/ruby_xml_schema_type.c +66 -93
  23. data/ext/libxml/ruby_xml_version.h +4 -4
  24. data/ext/libxml/ruby_xml_writer.c +189 -192
  25. data/lib/libxml/schema/element.rb +0 -8
  26. data/lib/libxml/schema/type.rb +0 -8
  27. data/lib/libxml/schema.rb +0 -19
  28. data/lib/libxml-ruby.rb +30 -0
  29. data/lib/libxml.rb +3 -28
  30. data/libxml-ruby.gemspec +5 -4
  31. data/setup.rb +0 -1
  32. data/test/model/cwm_1_0.xml +11336 -0
  33. data/test/{tc_attr.rb → test_attr.rb} +18 -18
  34. data/test/{tc_attr_decl.rb → test_attr_decl.rb} +8 -8
  35. data/test/{tc_attributes.rb → test_attributes.rb} +10 -10
  36. data/test/{tc_canonicalize.rb → test_canonicalize.rb} +35 -39
  37. data/test/test_deprecated_require.rb +12 -0
  38. data/test/{tc_document.rb → test_document.rb} +31 -24
  39. data/test/test_document_write.rb +146 -0
  40. data/test/{tc_dtd.rb → test_dtd.rb} +26 -25
  41. data/test/{tc_encoding.rb → test_encoding.rb} +20 -17
  42. data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +3 -3
  43. data/test/test_error.rb +178 -0
  44. data/test/test_helper.rb +4 -11
  45. data/test/{tc_html_parser.rb → test_html_parser.rb} +31 -30
  46. data/test/test_html_parser_context.rb +23 -0
  47. data/test/test_namespace.rb +60 -0
  48. data/test/{tc_namespaces.rb → test_namespaces.rb} +29 -38
  49. data/test/{tc_node.rb → test_node.rb} +37 -31
  50. data/test/{tc_node_cdata.rb → test_node_cdata.rb} +10 -10
  51. data/test/{tc_node_comment.rb → test_node_comment.rb} +6 -6
  52. data/test/{tc_node_copy.rb → test_node_copy.rb} +3 -4
  53. data/test/{tc_node_edit.rb → test_node_edit.rb} +20 -21
  54. data/test/{tc_node_pi.rb → test_node_pi.rb} +8 -10
  55. data/test/{tc_node_text.rb → test_node_text.rb} +8 -9
  56. data/test/{tc_node_write.rb → test_node_write.rb} +16 -26
  57. data/test/test_node_xlink.rb +28 -0
  58. data/test/{tc_parser.rb → test_parser.rb} +72 -75
  59. data/test/{tc_parser_context.rb → test_parser_context.rb} +38 -44
  60. data/test/{tc_properties.rb → test_properties.rb} +5 -5
  61. data/test/test_reader.rb +364 -0
  62. data/test/{tc_relaxng.rb → test_relaxng.rb} +11 -11
  63. data/test/{tc_sax_parser.rb → test_sax_parser.rb} +38 -31
  64. data/test/{tc_schema.rb → test_schema.rb} +40 -33
  65. data/test/test_suite.rb +39 -40
  66. data/test/{tc_traversal.rb → test_traversal.rb} +4 -4
  67. data/test/{tc_writer.rb → test_writer.rb} +95 -74
  68. data/test/{tc_xinclude.rb → test_xinclude.rb} +3 -3
  69. data/test/test_xml.rb +263 -0
  70. data/test/{tc_xpath.rb → test_xpath.rb} +25 -25
  71. data/test/{tc_xpath_context.rb → test_xpath_context.rb} +5 -5
  72. data/test/{tc_xpath_expression.rb → test_xpath_expression.rb} +7 -7
  73. data/test/{tc_xpointer.rb → test_xpointer.rb} +15 -15
  74. metadata +91 -102
  75. data/test/tc_deprecated_require.rb +0 -12
  76. data/test/tc_document_write.rb +0 -195
  77. data/test/tc_error.rb +0 -178
  78. data/test/tc_html_parser_context.rb +0 -23
  79. data/test/tc_namespace.rb +0 -61
  80. data/test/tc_node_xlink.rb +0 -28
  81. data/test/tc_reader.rb +0 -358
  82. data/test/tc_xml.rb +0 -225
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 865194cd65ca9ad9a3ccc047d89b5a68186ef97f
4
- data.tar.gz: 7d29d8cb6cd5d40cba78f171ac92d61f3b48d1d1
2
+ SHA256:
3
+ metadata.gz: 40cfe66ffd84495bc2bd079978d06abd01be932513d0c04160453fe04c33db6c
4
+ data.tar.gz: 1c45a468970af35413989b9af9f516efb1fc7aae17b401fa83626a762141d04e
5
5
  SHA512:
6
- metadata.gz: 0b68eca1f0ff9241250a1d9ac28f9bd34e744493e50d1728f0da43568b2a478ca75ced18899e13483076fd6da88716c62a8485acda4bb84e1f42e7b018d91433
7
- data.tar.gz: dcc1043a0033995c6c0be3fc2cae266f9be82d436dd92ad7db76e616e5442353f7515a3bdb0e1ae84701eb3cb912950abadf339613215256ac0a339d2391b536
6
+ metadata.gz: 6352fc0f0414020fbd48118313e6557e18f6dbccbd1a67270ef04cf693c3abd3a054ff68548e4235266acb41182b0907df079ba99e0b461afc6f320e1b3b923f
7
+ data.tar.gz: e19986fa3ee2298dd6ed3d00f300e5ce25b956562cf6609b27fb976b9acc5df6e6f3ddcf22926de76cd9d9eb97d6d95d05d8c281dc4df0a53ec27b81a16552dd
data/HISTORY CHANGED
@@ -1,5 +1,42 @@
1
1
  = Release History
2
2
 
3
+ == 3.2.2 / 2022-01-15
4
+ * Switch to Github actions for CI/CD (Greg)
5
+ * Test fixes (Greg, Sergio Durigan Junior)
6
+ * Fix typo on test/test_sax_parser.rb (Sergio Durigan Junior)
7
+ * Update homepage in gemspec (Pirate Praveen Arimbrathodiyil)
8
+
9
+ == 3.2.1 / 2020-11-05
10
+
11
+ * Fix incorrect handling of encodings when using XMLWriter.io (Charlie Savage)
12
+ * Clean up README (Richard Michael)
13
+
14
+ == 3.2.0 / 2020-05-09 Charlie Savage
15
+
16
+ * Fix crash when creating an empty DTD
17
+ * Modernize tests to use Bundler to load gem
18
+ * Add libxml-ruby.rb file so gem loads in expected way.
19
+ * Add support for xmlSaveNoEmptyTags.
20
+ * Clean up extconf.rb file
21
+
22
+ == 3.1.0 / 2018-02-03 Charlie Savage
23
+
24
+ * Fix segmentation fault when adding one node to another node (Charlie Savage)
25
+ * Fix deprecated "assert_equal(nil, expected)" calls. #148 and #151. (utilum)
26
+ * Remove assigned but unused variables. #150 (utilum)
27
+ * Add Gemfile. #146. (Dorian Marié)
28
+ * Remove duplicate hash key in setup.rb. #147. (Dorian Marié)
29
+ * Fix gemspec by requiring Date. #149 (utilum)
30
+ * Restore default internal encoding after tests are completed. #123 (Charlie Savage)
31
+ * Remove duplicate method definitions. #145. (Charlie Savage)
32
+ * Remove SchemaElement#minOccurs and SchemaElement#maxOccurs since they actually did not work (Charlie Savage)
33
+ * Rename test files to follow Ruby conventions (Charlie Savage)
34
+ * Fix handling of node returned by Reader#expand. #142. (Charlie Savage)
35
+ * Add Travis Build support (Charlie Savage)
36
+ * Fix Fixnum deprecation (Charlie Savage)
37
+ * Cleanup schema code (Charlie Savage)
38
+ * Update Visual Studio project to 2017 (Charlie Savage)
39
+
3
40
  == 3.0.0 / 2017-02-07 Charlie Savage
4
41
 
5
42
  * Revamp how libxml-ruby manages memory. Instead of trying to return the same ruby object for each xmlnode,
data/MANIFEST CHANGED
@@ -122,40 +122,40 @@ test/model/shiporder.xml
122
122
  test/model/shiporder.xsd
123
123
  test/model/soap.xml
124
124
  test/model/xinclude.xml
125
- test/tc_attr.rb
126
- test/tc_attr_decl.rb
127
- test/tc_attributes.rb
128
- test/tc_deprecated_require.rb
129
- test/tc_document.rb
130
- test/tc_document_write.rb
131
- test/tc_dtd.rb
132
- test/tc_error.rb
133
- test/tc_html_parser.rb
134
- test/tc_namespace.rb
135
- test/tc_namespaces.rb
136
- test/tc_node.rb
137
- test/tc_node_cdata.rb
138
- test/tc_node_comment.rb
139
- test/tc_node_copy.rb
140
- test/tc_node_edit.rb
141
- test/tc_node_pi.rb
142
- test/tc_node_text.rb
143
- test/tc_node_write.rb
144
- test/tc_node_xlink.rb
145
- test/tc_parser.rb
146
- test/tc_parser_context.rb
147
- test/tc_properties.rb
148
- test/tc_reader.rb
149
- test/tc_relaxng.rb
150
- test/tc_sax_parser.rb
151
- test/tc_schema.rb
152
- test/tc_traversal.rb
153
- test/tc_xinclude.rb
154
- test/tc_xml.rb
155
- test/tc_xpath.rb
156
- test/tc_xpath_context.rb
157
- test/tc_xpath_expression.rb
158
- test/tc_xpointer.rb
125
+ test/test_attr.rb
126
+ test/test_attr_decl.rb
127
+ test/test_attributes.rb
128
+ test/test_deprecated_require.rb
129
+ test/test_document.rb
130
+ test/test_document_write.rb
131
+ test/test_dtd.rb
132
+ test/test_error.rb
133
+ test/test_html_parser.rb
134
+ test/test_namespace.rb
135
+ test/test_namespaces.rb
136
+ test/test_node.rb
137
+ test/test_node_cdata.rb
138
+ test/test_node_comment.rb
139
+ test/test_node_copy.rb
140
+ test/test_node_edit.rb
141
+ test/test_node_pi.rb
142
+ test/test_node_text.rb
143
+ test/test_node_write.rb
144
+ test/test_node_xlink.rb
145
+ test/test_parser.rb
146
+ test/test_parser_context.rb
147
+ test/test_properties.rb
148
+ test/test_reader.rb
149
+ test/test_relaxng.rb
150
+ test/test_sax_parser.rb
151
+ test/test_schema.rb
152
+ test/test_traversal.rb
153
+ test/test_xinclude.rb
154
+ test/test_xml.rb
155
+ test/test_xpath.rb
156
+ test/test_xpath_context.rb
157
+ test/test_xpath_expression.rb
158
+ test/test_xpointer.rb
159
159
  test/test_suite.rb
160
160
  Rakefile
161
161
  HISTORY.rdoc
data/README.rdoc CHANGED
@@ -11,8 +11,8 @@ We think libxml-ruby is the best XML library for Ruby because:
11
11
  * Conformance - It passes all 1800+ tests from the OASIS XML Tests Suite
12
12
 
13
13
  == Requirements
14
- libxml-ruby requires Ruby 1.8.4 or higher. It depends on libxml2 to
15
- function propoerly. libxml2, in turn, depends on:
14
+ libxml-ruby requires Ruby 1.8.7 or higher. It depends on libxml2 to
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 (http://rubyinstaller.org/add-ons/devkit/) or
25
- msys2 (https://msys2.github.io/).
24
+ Devkit[http://rubyinstaller.org/add-ons/devkit/] or
25
+ msys2[https://msys2.github.io/].
26
26
 
27
- == INSTALLATION
28
- The easiest way to install libxml-ruby is via Ruby Gems. To install:
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
- THe gem inncludes prebuilt extensions for Ruby 2.3. These
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\libs directory. To use them, put them
37
- someplace on your path.
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 Github at https://github.com/xml4r/libxml-ruby.
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 a XML document. Although not as popular,
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
- then install the libxslt gem which is available at
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 documentation at
81
- http://xml4r.github.com/libxml-ruby/rdoc/index.html. Some tutorials are also
82
- available at https://github.com/xml4r/libxml-ruby/wiki.
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'. This will mixin
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
 
@@ -118,11 +133,24 @@ libxml-ruby fully supports native, background Ruby threads. This of course
118
133
  only applies to Ruby 1.9.x and higher since earlier versions of Ruby do not
119
134
  support native threads.
120
135
 
136
+ == Tests
137
+
138
+ To run tests you first need to build the shared libary:
139
+
140
+ rake compile
141
+
142
+ Once you have build the shared libary, you can then run tests using rake:
143
+
144
+ rake test
145
+
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]
147
+
121
148
  == Performance
149
+
122
150
  In addition to being feature rich and conformation, the main reason
123
- people use libxml-ruby is for performance. Here are the results
151
+ people use libxml-ruby is for performance. Here are the results
124
152
  of a couple simple benchmarks recently blogged about on the
125
- Web (you can find them in the benchmark directory of the
153
+ Web (you can find them in the benchmark directory of the
126
154
  libxml distribution).
127
155
 
128
156
  From http://depixelate.com/2008/4/23/ruby-xml-parsing-benchmarks
@@ -144,44 +172,45 @@ From https://svn.concord.org/svn/projects/trunk/common/ruby/xml_benchmarks/
144
172
  Documentation is available via rdoc, and is installed automatically with the
145
173
  gem.
146
174
 
147
- libxml-ruby's online documentation is generated using Hanna, which is a
148
- development gem dependency.
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.
149
178
 
150
179
  Note that older versions of Rdoc, which ship with Ruby 1.8.x, will report
151
180
  a number of errors. To avoid them, install Rdoc 2.1 or higher. Once you have
152
181
  installed the gem, you'll have to disable the version of Rdoc that Ruby 1.8.x
153
- includes. An easy way to do that is rename the directory ruby/lib/ruby/1.8/rdoc to
154
- ruby/lib/ruby/1.8/rdoc_old.
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>.
155
185
 
156
186
  == Support
157
-
158
- If you have any questions about using libxml-ruby, please report them to
159
- 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].
160
189
 
161
190
  == Memory Management
162
191
  libxml-ruby automatically manages memory associated with the
163
192
  underlying libxml2 library. The bindings create a one-to-one mapping between
164
- ruby objects and libxml documents and libxml parent nodes (ie, nodes that do not
165
- have a parent and do not belong to a document). In these cases,
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,
166
195
  the bindings manage the memory. They do this by installing a free
167
196
  function and storing a back pointer to the Ruby object from the xmlnode
168
197
  using the _private member on libxml structures. When the Ruby object
169
198
  goes out of scope, the underlying libxml structure is freed. Libxml
170
- itself then frees all child node (recursively).
199
+ itself then frees all child nodes (recursively).
171
200
 
172
201
  For all other nodes (the vast majority), the bindings create temporary
173
202
  Ruby objects that get freed once they go out of scope. Thus there can be
174
- more than one ruby object pointing to the same xml node. To mostly hide
175
- this from programmers on the ruby side, the #eql? and #== methods are
176
- overriden to check if two ruby objects wrap the same xmlnode. If they do,
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,
177
206
  then the methods return true. During the mark phase, each of these temporary
178
207
  objects marks its owning document, thereby keeping the Ruby document object
179
208
  alive and thus the xmldoc tree.
180
209
 
181
210
  In the sweep phase of the garbage collector, or when a program ends,
182
- there is no order to how Ruby objects are freed. In fact, the ruby document
183
- object is almost always freed before any ruby objects that wrap child nodes.
184
- However, this is ok because those ruby objects do not have a free function
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
185
214
  and are no longer in scope (since if they were the document would not be freed).
186
215
 
187
216
  == License
data/Rakefile CHANGED
@@ -21,8 +21,25 @@ Rake::ExtensionTask.new do |ext|
21
21
  ext.name = SO_NAME
22
22
  ext.ext_dir = "ext/libxml"
23
23
  ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}"
24
- ext.config_options << "--with-xml2-include=C:/msys64/mingw64/include/libxml2"
25
- ext.config_options << "--with-zlib-dir=C:/msys64/mingw64"
24
+ if RUBY_PLATFORM.match(/mswin32|mswin64|mingw32|ucrt/)
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'
42
+ end
26
43
  end
27
44
 
28
45
  # Setup generic gem
@@ -32,7 +49,7 @@ Gem::PackageTask.new(spec) do |pkg|
32
49
  end
33
50
 
34
51
  # Setup Windows Gem
35
- if RUBY_PLATFORM.match(/win32|mingw32/)
52
+ if RUBY_PLATFORM.match(/mswin32|mswin64|mingw32/)
36
53
  binaries = (FileList['lib/**/*.so',
37
54
  'lib/**/*dll'])
38
55
 
@@ -77,5 +94,6 @@ end
77
94
  # Test Task
78
95
  Rake::TestTask.new do |t|
79
96
  t.libs << "test"
97
+ t.test_files = FileList['test/test*.rb'] - ['test/test_suite.rb']
80
98
  t.verbose = true
81
99
  end
@@ -25,33 +25,37 @@ else
25
25
  dir_config('xml2')
26
26
  end
27
27
 
28
- unless find_header('libxml/xmlversion.h',
29
- '/opt/include/libxml2',
30
- '/opt/local/include/libxml2',
31
- '/usr/local/include/libxml2',
32
- '/usr/include/libxml2') &&
33
- find_library('xml2', 'xmlParseDoc',
34
- '/opt/lib',
35
- '/opt/local/lib',
36
- '/usr/local/lib',
37
- '/usr/lib')
38
- crash(<<EOL)
39
- need libxml2.
40
-
41
- Install the library or try one of the following options to extconf.rb:
42
-
43
- --with-xml2-config=/path/to/xml2-config
44
- --with-xml2-dir=/path/to/libxml2
45
- --with-xml2-lib=/path/to/libxml2/lib
46
- --with-xml2-include=/path/to/libxml2/include
47
- EOL
28
+ found_header = find_header('libxml/xmlversion.h',
29
+ '/opt/include/libxml2',
30
+ '/opt/local/include/libxml2',
31
+ '/usr/local/include/libxml2',
32
+ '/usr/include/libxml2',
33
+ '/usr/local/include')
34
+
35
+ found_lib = find_library('xml2', 'xmlParseDoc',
36
+ '/opt/lib',
37
+ '/opt/local/lib',
38
+ '/usr/local/lib',
39
+ '/usr/lib')
40
+
41
+ found_lib ||= find_library('libxml2', 'xmlParseDoc',
42
+ '/opt/lib',
43
+ '/opt/local/lib',
44
+ '/usr/local/lib',
45
+ '/usr/lib')
46
+
47
+ if !found_header || !found_lib
48
+ crash(<<~EOL)
49
+ Cannot find libxml2.
50
+
51
+ Install the library or try one of the following options to extconf.rb:
52
+
53
+ --with-xml2-config=/path/to/xml2-config
54
+ --with-xml2-dir=/path/to/libxml2
55
+ --with-xml2-lib=/path/to/libxml2/lib
56
+ --with-xml2-include=/path/to/libxml2/include
57
+ EOL
48
58
  end
49
59
 
50
- have_func('rb_io_bufwrite', 'ruby/io.h')
51
-
52
- # For FreeBSD add /usr/local/include
53
- $INCFLAGS << " -I/usr/local/include"
54
- $CFLAGS << ' ' << $INCFLAGS
55
-
56
60
  create_header()
57
61
  create_makefile('libxml_ruby')
@@ -16,15 +16,7 @@
16
16
  #include <libxml/xmlreader.h>
17
17
  #include <libxml/c14n.h>
18
18
 
19
- /* Needed prior to Ruby 1.9.1 */
20
- #ifndef RHASH_TBL
21
- #define RHASH_TBL(s) (RHASH(s)->tbl)
22
- #endif
23
-
24
- // Encoding support added in Ruby 1.9.*
25
- #ifdef HAVE_RUBY_ENCODING_H
26
19
  #include <ruby/encoding.h>
27
- #endif
28
20
 
29
21
  #ifdef LIBXML_DEBUG_ENABLED
30
22
  #include <libxml/xpathInternals.h>
@@ -717,6 +717,44 @@ static VALUE rxml_default_compression_set(VALUE klass, VALUE num)
717
717
  #endif
718
718
  }
719
719
 
720
+ /*
721
+ * call-seq:
722
+ * XML.default_save_no_empty_tags -> (true|false)
723
+ *
724
+ * Determine whether serializer outputs empty tags by default.
725
+ */
726
+ static VALUE rxml_default_save_no_empty_tags_get(VALUE klass)
727
+ {
728
+ if (xmlSaveNoEmptyTags)
729
+ return (Qtrue);
730
+ else
731
+ return (Qfalse);
732
+ }
733
+
734
+ /*
735
+ * call-seq:
736
+ * XML.default_save_no_empty_tags = true|false
737
+ *
738
+ * Controls whether serializer outputs empty tags by default.
739
+ */
740
+ static VALUE rxml_default_save_no_empty_tags_set(VALUE klass, VALUE value)
741
+ {
742
+ if (value == Qfalse)
743
+ {
744
+ xmlSaveNoEmptyTags = 0;
745
+ return (Qfalse);
746
+ }
747
+ else if (value == Qtrue)
748
+ {
749
+ xmlSaveNoEmptyTags = 1;
750
+ return (Qtrue);
751
+ }
752
+ else
753
+ {
754
+ rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
755
+ }
756
+ }
757
+
720
758
  /*
721
759
  * call-seq:
722
760
  * XML.features -> ["feature", ..., "feature"]
@@ -885,6 +923,8 @@ void rxml_init_xml(void)
885
923
  rb_define_module_function(mXML, "default_validity_checking=", rxml_default_validity_checking_set, 1);
886
924
  rb_define_module_function(mXML, "default_warnings", rxml_default_warnings_get, 0);
887
925
  rb_define_module_function(mXML, "default_warnings=", rxml_default_warnings_set, 1);
926
+ rb_define_module_function(mXML, "default_save_no_empty_tags", rxml_default_save_no_empty_tags_get, 0);
927
+ rb_define_module_function(mXML, "default_save_no_empty_tags=", rxml_default_save_no_empty_tags_set, 1);
888
928
  rb_define_module_function(mXML, "features", rxml_features, 0);
889
929
  rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0);
890
930
  rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1);
@@ -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:
@@ -738,7 +736,7 @@ static VALUE rxml_document_root_set(VALUE self, VALUE node)
738
736
  Data_Get_Struct(node, xmlNode, xnode);
739
737
 
740
738
  if (xnode->doc != NULL && xnode->doc != xdoc)
741
- rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import");
739
+ rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import");
742
740
 
743
741
  xmlDocSetRootElement(xdoc, xnode);
744
742
 
@@ -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);
@@ -38,13 +38,11 @@ void rxml_dtd_free(xmlDtdPtr xdtd)
38
38
 
39
39
  void rxml_dtd_mark(xmlDtdPtr xdtd)
40
40
  {
41
- VALUE doc = Qnil;
42
-
43
- if (xdtd == NULL)
44
- return;
45
-
46
- doc = (VALUE)xdtd->doc->_private;
47
- rb_gc_mark(doc);
41
+ if (xdtd && xdtd->doc)
42
+ {
43
+ VALUE doc = (VALUE)xdtd->doc->_private;
44
+ rb_gc_mark(doc);
45
+ }
48
46
  }
49
47
 
50
48
  static VALUE rxml_dtd_alloc(VALUE klass)
@@ -173,7 +171,7 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
173
171
  }
174
172
  if (doc != Qnil) {
175
173
  if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
176
- rb_raise(rb_eTypeError, "Must pass an XML::Document object");
174
+ rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
177
175
  Data_Get_Struct(doc, xmlDoc, xdoc);
178
176
  }
179
177
 
@@ -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
- #ifdef HAVE_RUBY_ENCODING_H
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
@@ -158,7 +158,7 @@ static VALUE rxml_error_reset_handler(VALUE self)
158
158
  return self;
159
159
  }
160
160
 
161
- void rxml_raise(xmlErrorPtr xerror)
161
+ NORETURN(void rxml_raise(xmlErrorPtr xerror))
162
162
  {
163
163
  /* Wrap error up as Ruby object and send it off to ruby */
164
164
  VALUE error = rxml_error_wrap(xerror);
@@ -7,6 +7,6 @@ extern VALUE eXMLError;
7
7
 
8
8
  void rxml_init_error();
9
9
  VALUE rxml_error_wrap(xmlErrorPtr xerror);
10
- void rxml_raise(xmlErrorPtr xerror);
10
+ NORETURN(void rxml_raise(xmlErrorPtr xerror));
11
11
 
12
12
  #endif