ox 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ox might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +394 -0
- data/ext/ox/encode.h +26 -0
- data/ext/ox/ox.c +4 -4
- data/ext/ox/sax.c +1 -1
- data/lib/ox/element.rb +40 -2
- data/lib/ox/sax.rb +2 -2
- data/lib/ox/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a200a69cf6325bb5b0609452e4075b30ad3c432b
|
4
|
+
data.tar.gz: 96f8028076776533ae56dd098b970fbbd9937a6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc2eb452d9d428d943c46ab4a412374f1ca97f127684c654008880ca7bc9415df11551c199a030953b23f4e957a3b1a81750207f4aeb5814da10d836b1f399d2
|
7
|
+
data.tar.gz: bb36e32b2dc96a17b1c56f96ade6eab40ad349e0e14ffff0726f5e36992ac4df3c1eeaf4df2b52eb513a13c4bac42bed34e12657b206e707f9121aeb48e17354
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,394 @@
|
|
1
|
+
|
2
|
+
## 2.6.0 - August 9, 2017
|
3
|
+
|
4
|
+
- The Element#each() method was added to allow iteration over Element nodes conditionally.
|
5
|
+
|
6
|
+
- Element#locate() now supports a [@attr=value] specification.
|
7
|
+
|
8
|
+
- An underscore character used in the easy API is now treated as a wild card for valid XML characters that are not valid for Ruby method names.
|
9
|
+
|
10
|
+
## 2.5.0 - May 4, 2017
|
11
|
+
|
12
|
+
- Set the default for skip to be to skip white space.
|
13
|
+
|
14
|
+
- Added a :nest_ok option to SAX hints that will ignore the nested check on a
|
15
|
+
tag to accomadate non-compliant HTML.
|
16
|
+
|
17
|
+
## 2.4.13 - April 21, 2017
|
18
|
+
|
19
|
+
- Corrected Builder special character handling.
|
20
|
+
|
21
|
+
## 2.4.12 - April 11, 2017
|
22
|
+
|
23
|
+
- Fixed position in builder when encoding special characters.
|
24
|
+
|
25
|
+
## 2.4.11 - March 19, 2017
|
26
|
+
|
27
|
+
- Fixed SAX parser bug regarding upper case hints not matching.
|
28
|
+
|
29
|
+
## 2.4.10 - February 13, 2017
|
30
|
+
|
31
|
+
- Dump is now smarter about which characters to replace with &xxx; alternatives.
|
32
|
+
|
33
|
+
## 2.4.9 - January 25, 2017
|
34
|
+
|
35
|
+
- Added a SAX hint that allows comments to be treated like other elements.
|
36
|
+
|
37
|
+
## 2.4.8 - January 15, 2017
|
38
|
+
|
39
|
+
- Tolerant mode now allows case-insensitve matches on elements during
|
40
|
+
parsing. Smart mode in the SAX parser is also case insensitive.
|
41
|
+
|
42
|
+
## 2.4.7 - December 25, 2016
|
43
|
+
|
44
|
+
- After encountering a <> the SAX parser will continue parsing after reporting an error.
|
45
|
+
|
46
|
+
## 2.4.6 - November 28, 2016
|
47
|
+
|
48
|
+
- Added margin option to dump.
|
49
|
+
|
50
|
+
## 2.4.5 - September 11, 2016
|
51
|
+
|
52
|
+
- Thanks to GUI for fixing an infinite loop in Ox::Builder.
|
53
|
+
|
54
|
+
## 2.4.4 - August 9, 2016
|
55
|
+
|
56
|
+
- Builder element attributes with special characters are now encoded correctly.
|
57
|
+
|
58
|
+
- A newline at end of an XML string is now controlled by the indent value. A
|
59
|
+
value of -1 indicates no terminating newline character and an indentation of
|
60
|
+
zero.
|
61
|
+
|
62
|
+
## 2.4.3 - June 26, 2016
|
63
|
+
|
64
|
+
- Fixed compiler warnings and errors.
|
65
|
+
|
66
|
+
- Updated for Ruby 2.4.0.
|
67
|
+
|
68
|
+
## 2.4.2 - June 23, 2016
|
69
|
+
|
70
|
+
- Added methods to Ox::Builder to provide output position information.
|
71
|
+
|
72
|
+
## 2.4.1 - April 30, 2016
|
73
|
+
|
74
|
+
- Made SAX smarter a little smarter or rather let it handle unquoted string
|
75
|
+
with a / at the end.
|
76
|
+
|
77
|
+
- Fixed bug with reporting errors of element names that are too long.
|
78
|
+
|
79
|
+
- Added overlay feature to give control over which elements generate callbacks
|
80
|
+
with the SAX parser.
|
81
|
+
|
82
|
+
- Element.locate now includes self if the path is relative and starts with a wildcard.
|
83
|
+
|
84
|
+
## 2.4.0 - April 14, 2016
|
85
|
+
|
86
|
+
- Added Ox::Builder that constructs an XML string or writes XML to a stream
|
87
|
+
using builder methods.
|
88
|
+
|
89
|
+
## 2.3.0 - February 21, 2016
|
90
|
+
|
91
|
+
- Added Ox::Element.replace_text() method.
|
92
|
+
|
93
|
+
- Ox::Element nodes variable is now always initialized to an empty Array.
|
94
|
+
|
95
|
+
- Ox::Element attributes variable is now always initialized to an empty Hash.
|
96
|
+
|
97
|
+
- A invalid_replace option has been added. It will replace invalid XML
|
98
|
+
character with a provided string. Strict effort now raises an exception if an
|
99
|
+
invalid character is encountered on dump or load.
|
100
|
+
|
101
|
+
- Ox.load and Ox.parse now allow for a callback block to handle multiple top
|
102
|
+
level entities in the input.
|
103
|
+
|
104
|
+
- The Ox SAX parser now supports strings as input directly without and IO wrapper.
|
105
|
+
|
106
|
+
## 2.2.4 - February 4, 2016
|
107
|
+
|
108
|
+
- Changed the code to allow compilation on older compilers. No change in
|
109
|
+
functionality otherwise.
|
110
|
+
|
111
|
+
## 2.2.3 - December 31, 2015
|
112
|
+
|
113
|
+
- The convert_special option now applies to attributes as well as elements in
|
114
|
+
the SAX parser.
|
115
|
+
|
116
|
+
- The convert_special option now applies to the regualr parser as well as the
|
117
|
+
SAX parser.
|
118
|
+
|
119
|
+
- Updated to work correctly with Ruby 2.3.0.
|
120
|
+
|
121
|
+
## 2.2.2 - October 19, 2015
|
122
|
+
|
123
|
+
- Fixed problem with detecting invalid special character sequences.
|
124
|
+
|
125
|
+
- Fixed bug that caused a crash when an <> was encountered with the SAX parser.
|
126
|
+
|
127
|
+
## 2.2.1 - July 30, 2015
|
128
|
+
|
129
|
+
- Added support to handle script elements in html.
|
130
|
+
|
131
|
+
- Added support for position from start for the sax parser.
|
132
|
+
|
133
|
+
## 2.2.0 - April 20, 2015
|
134
|
+
|
135
|
+
- Added the SAX convert_special option to the default options.
|
136
|
+
|
137
|
+
- Added the SAX smart option to the default options.
|
138
|
+
|
139
|
+
- Other SAX options are now taken from the defaults if not specified.
|
140
|
+
|
141
|
+
## 2.1.8 - February 10, 2015
|
142
|
+
|
143
|
+
- Fixed a bug that caused all input to be read before parsing with the sax
|
144
|
+
parser and an IO.pipe.
|
145
|
+
|
146
|
+
## 2.1.7 - January 31, 2015
|
147
|
+
|
148
|
+
- Empty elements such as <foo></foo> are now called back with empty text.
|
149
|
+
|
150
|
+
- Fixed GC problem that occurs with the new GC in Ruby 2.2 that garbage
|
151
|
+
collects Symbols.
|
152
|
+
|
153
|
+
## 2.1.6 - December 31, 2014
|
154
|
+
|
155
|
+
- Update licenses. No other changes.
|
156
|
+
|
157
|
+
## 2.1.5 - December 30, 2014
|
158
|
+
|
159
|
+
- Fixed symbol intern problem with Ruby 2.2.0. Symbols are not dynamic unless
|
160
|
+
rb_intern(). There does not seem to be a way to force symbols created with
|
161
|
+
encoding to be pinned.
|
162
|
+
|
163
|
+
## 2.1.4 - December 5, 2014
|
164
|
+
|
165
|
+
- Fixed bug where the parser always started at the first position in a stringio
|
166
|
+
instead of the current position.
|
167
|
+
|
168
|
+
## 2.1.3 - July 25, 2014
|
169
|
+
|
170
|
+
- Added check for @attributes being nil. Reported by and proposed fix by Elana.
|
171
|
+
|
172
|
+
## 2.1.2 - July 17, 2014
|
173
|
+
|
174
|
+
- Added skip option to parsing. This allows white space to be collapsed in two
|
175
|
+
different ways.
|
176
|
+
|
177
|
+
- Added respond_to? method for easy access method checking.
|
178
|
+
|
179
|
+
## 2.1.1 - February 12, 2014
|
180
|
+
|
181
|
+
- Worked around a module reset and clear that occurs on some Rubies.
|
182
|
+
|
183
|
+
## 2.1.0 - February 2, 2014
|
184
|
+
|
185
|
+
- Thanks to jfontan Ox now includes support for XMLRPC.
|
186
|
+
|
187
|
+
## 2.0.12 - December 1, 2013 - May 21, 2013
|
188
|
+
|
189
|
+
- Fixed problem compiling with latest version of Rubinius.
|
190
|
+
|
191
|
+
## 2.0.11 - October 17, 2013
|
192
|
+
|
193
|
+
- Added support for BigDecimals in :object mode.
|
194
|
+
|
195
|
+
## 2.0.10
|
196
|
+
|
197
|
+
- Small fix to not create an empty element from a closed element when using locate().
|
198
|
+
|
199
|
+
- Fixed to keep objects from being garbages collected in Ruby 2.x.
|
200
|
+
|
201
|
+
## 2.0.9 - September 2, 2013
|
202
|
+
|
203
|
+
- Fixed bug that did not allow ISO-8859-1 characters and caused a crash.
|
204
|
+
|
205
|
+
## 2.0.8 - August 6, 2013
|
206
|
+
|
207
|
+
- Allow single quoted strings in all modes.
|
208
|
+
|
209
|
+
## 2.0.7 - August 4, 2013
|
210
|
+
|
211
|
+
- Fixed DOCTYPE parsing to handle nested '>' characters.
|
212
|
+
|
213
|
+
## 2.0.6 - July 23, 2013
|
214
|
+
|
215
|
+
- Fixed bug in special character decoding that chopped of text.
|
216
|
+
|
217
|
+
- Limit depth on dump to 1000 to avoid core dump on circular references if the user does not specify circular.
|
218
|
+
|
219
|
+
- Handles dumping non-string values for attributes correctly by converting the value to a string.
|
220
|
+
|
221
|
+
## 2.0.5 - July 5, 2013
|
222
|
+
|
223
|
+
- Better support for special character encoding with 1.8.7. - February 8, 2013
|
224
|
+
|
225
|
+
## 2.0.4 - June 24, 2013
|
226
|
+
|
227
|
+
- Fixed SAX parser handling of &#nnnn; encoded characters.
|
228
|
+
|
229
|
+
## 2.0.3 - June 12, 2013
|
230
|
+
|
231
|
+
- Fixed excessive memory allocation issue for very large file parsing (half a gig).
|
232
|
+
|
233
|
+
## 2.0.2 - June 7, 2013
|
234
|
+
|
235
|
+
- Fixed buffer sliding window off by 1 error in the SAX parser.
|
236
|
+
|
237
|
+
## 2.0.1
|
238
|
+
|
239
|
+
- Added an attrs_done callback to the sax parser that will be called when all
|
240
|
+
attributes for an element have been read.
|
241
|
+
|
242
|
+
- Fixed bug in SAX parser where raising an exception in the handler routines
|
243
|
+
would not cleanup. The test put together by griffinmyers was a huge help.
|
244
|
+
|
245
|
+
- Reduced stack use in a several places to improve fiber support.
|
246
|
+
|
247
|
+
- Changed exception handling to assure proper cleanup with new stack minimizing.
|
248
|
+
|
249
|
+
## 2.0.0 - April 16, 2013
|
250
|
+
|
251
|
+
- The SAX parser went through a significant re-write. The options have changed. It is now 15% faster on large files and
|
252
|
+
much better at recovering from errors. So much so that the tolerant option was removed and is now the default and
|
253
|
+
only behavior. A smart option was added however. The smart option recognizes a file as an HTML file and will apply a
|
254
|
+
simple set of validation rules that allow the HTML to be parsed more reasonably. Errors will cause callbacks but the
|
255
|
+
parsing continues with the best guess as to how to recover. Rubymaniac has helped with testing and prompted the
|
256
|
+
rewrite to support parsing HTML pages.
|
257
|
+
|
258
|
+
- HTML is now supported with the SAX parser. The parser knows some tags like \<br\> or \<img\> do not have to be
|
259
|
+
closed. Other hints as to how to parse and when to raise errors are also included. The parser does it's best to
|
260
|
+
continue parsing even after errors.
|
261
|
+
|
262
|
+
- Added symbolize option to the sax parser. This option, if set to false will use strings instead of symbols for
|
263
|
+
element and attribute names.
|
264
|
+
|
265
|
+
- A contrib directory was added for people to submit useful bits of code that can be used with Ox. The first
|
266
|
+
contributor is Notezen with a nice way of building XML.
|
267
|
+
|
268
|
+
## 1.9.4 - March 24, 2013
|
269
|
+
|
270
|
+
- SAX tolerant mode handle multiple elements in a document better.
|
271
|
+
|
272
|
+
## 1.9.3 - March 22, 2013
|
273
|
+
|
274
|
+
- mcarpenter fixed a compile problem with Cygwin.
|
275
|
+
|
276
|
+
- Now more tolerant when the :effort is set to :tolerant. Ox will let all sorts
|
277
|
+
of errors typical in HTML documents pass. The result may not be perfect but
|
278
|
+
at least parsed results are returned.
|
279
|
+
|
280
|
+
- Attribute values need not be quoted or they can be quoted with single
|
281
|
+
quotes or there can be no =value are all.
|
282
|
+
|
283
|
+
- Elements not terminated will be terminated by the next element
|
284
|
+
termination. This effect goes up until a match is found on the element
|
285
|
+
name.
|
286
|
+
|
287
|
+
- SAX parser also given a :tolerant option with the same tolerance as the string parser.
|
288
|
+
|
289
|
+
## 1.9.2 - March 9, 2013
|
290
|
+
|
291
|
+
- Fixed bug in the sax element name check that cause a memory write error.
|
292
|
+
|
293
|
+
## 1.9.1 - February 27, 2013
|
294
|
+
|
295
|
+
- Fixed the line numbers to be the start of the elements in the sax parser.
|
296
|
+
|
297
|
+
## 1.9.0 - February 25, 2013
|
298
|
+
|
299
|
+
- Added a new feature to Ox::Element.locate() that allows filtering by node Class.
|
300
|
+
|
301
|
+
- Added feature to the Sax parser. If @line is defined in the handler it is set to the line number of the xml file
|
302
|
+
before making callbacks. The same goes for @column but it is updated with the column.
|
303
|
+
|
304
|
+
## 1.8.9 - February 21, 2013
|
305
|
+
|
306
|
+
- Fixed bug in element start and end name checking.
|
307
|
+
|
308
|
+
## 1.8.8 - February 17, 2013
|
309
|
+
|
310
|
+
- Fixed bug in check for open and close element names matching.
|
311
|
+
|
312
|
+
## 1.8.7
|
313
|
+
|
314
|
+
- Added a correct check for element open and close names.
|
315
|
+
|
316
|
+
- Changed raised Exceptions to customer classes that inherit from StandardError.
|
317
|
+
|
318
|
+
- Fixed a few minor bugs.
|
319
|
+
|
320
|
+
## 1.8.6 - February 7, 2013
|
321
|
+
|
322
|
+
- Removed broken check for matching start and end element names in SAX mode. The names are still included in the
|
323
|
+
handler callbacks so the user can perform the check is desired.
|
324
|
+
|
325
|
+
## 1.8.5 - February 3, 2013
|
326
|
+
|
327
|
+
- added encoding support for JRuby where possible when in 1.9 mode.
|
328
|
+
|
329
|
+
## 1.8.4 - January 25, 2013
|
330
|
+
|
331
|
+
- Applied patch by mcarpenter to fix solaris issues with build and remaining undefined @nodes.
|
332
|
+
|
333
|
+
## 1.8.3 - January 24, 2013
|
334
|
+
|
335
|
+
- Sax parser now honors encoding specification in the xml prolog correctly.
|
336
|
+
|
337
|
+
## 1.8.2 - January 18, 2013
|
338
|
+
|
339
|
+
- Ox::Element.locate no longer raises and exception if there are no child nodes.
|
340
|
+
|
341
|
+
- Dumping an XML document no longer puts a carriage return after processing instructions.
|
342
|
+
|
343
|
+
## 1.8.1 - December 17, 2012
|
344
|
+
|
345
|
+
- Fixed bug that caused a crash when an invalid xml with two elements and no <?xml?> was parsed. (issue #28)
|
346
|
+
|
347
|
+
- Modified the SAX parser to not strip white space from the start of string content.
|
348
|
+
|
349
|
+
## 1.8.0 - December 11, 2012
|
350
|
+
|
351
|
+
- Added more complete support for processing instructions in both the generic parser and in the sax parser. This change includes and additional sax handler callback for the end of the instruction processing.
|
352
|
+
|
353
|
+
## 1.7.1 - December 6, 2012
|
354
|
+
|
355
|
+
- Pulled in sharpyfox's changes to make Ox with with Windows. (issue #24)
|
356
|
+
|
357
|
+
- Fixed bug that ignored white space only text elements. (issue #26)
|
358
|
+
|
359
|
+
## 1.7.0 - November 27, 2012
|
360
|
+
|
361
|
+
- Added support for BOM in the SAX parser.
|
362
|
+
|
363
|
+
## 1.6.9 - November 25, 2012
|
364
|
+
|
365
|
+
- Added support for BOM. They are honored for and handled correctly for UTF-8. Others cause encoding issues with Ruby or raise an error as others are not ASCII compatible..
|
366
|
+
|
367
|
+
## 1.6.8 - November 18, 2012
|
368
|
+
|
369
|
+
- Changed extconf.rb to use RUBY_PLATFORM.
|
370
|
+
|
371
|
+
## 1.6.7 - November 15, 2012
|
372
|
+
|
373
|
+
- Now uses the encoding of the imput XML as the default encoding for the parsed output if the default options encoding is not set and the encoding is not set in the XML file prolog.
|
374
|
+
|
375
|
+
## 1.6.5 - October 25, 2012
|
376
|
+
|
377
|
+
- Special character handling now supports UCS-2 and UCS-4 Unicode characters as well as UTF-8 characters.
|
378
|
+
|
379
|
+
## 1.6.4 - October 24, 2012
|
380
|
+
|
381
|
+
- Special character handling has been improved. Both hex and base 10 numeric values are allowed up to a 64 bit number
|
382
|
+
for really long UTF-8 characters.
|
383
|
+
|
384
|
+
## 1.6.3 - October 22, 2012
|
385
|
+
|
386
|
+
- Fixed compatibility issues with Linux (Ubuntu) mostly related to pointer sizes.
|
387
|
+
|
388
|
+
## 1.6.2 - October 7, 2012
|
389
|
+
|
390
|
+
- Added check for Solaris and Linux builds to not use the timezone member of time struct (struct tm).
|
391
|
+
|
392
|
+
## 1.6.1 - October 7, 2012
|
393
|
+
|
394
|
+
- Added check for Solaris builds to not use the timezone member of time struct (struct tm).
|
data/ext/ox/encode.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
/* encode.h
|
2
|
+
* Copyright (c) 2011, Peter Ohler
|
3
|
+
* All rights reserved.
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef __OX_ENCODE_H__
|
7
|
+
#define __OX_ENCODE_H__
|
8
|
+
|
9
|
+
#include "ruby.h"
|
10
|
+
#if HAS_ENCODING_SUPPORT
|
11
|
+
#include "ruby/encoding.h"
|
12
|
+
#endif
|
13
|
+
|
14
|
+
static inline VALUE
|
15
|
+
ox_encode(VALUE rstr) {
|
16
|
+
#if HAS_ENCODING_SUPPORT
|
17
|
+
rb_enc_associate(rstr, ox_utf8_encoding);
|
18
|
+
#else
|
19
|
+
if (Qnil != ox_utf8_encoding) {
|
20
|
+
rstr = rb_funcall(ox_utf8_encoding, ox_iconv_id, 1, rstr);
|
21
|
+
}
|
22
|
+
#endif
|
23
|
+
return rstr;
|
24
|
+
}
|
25
|
+
|
26
|
+
#endif /* __OX_ENCODE_H__ */
|
data/ext/ox/ox.c
CHANGED
@@ -972,7 +972,7 @@ load_file(int argc, VALUE *argv, VALUE self) {
|
|
972
972
|
* - *:convert_special* [true|false] flag indicating special characters like < are converted
|
973
973
|
* - *:symbolize* [true|false] flag indicating the parser symbolize element and attribute names
|
974
974
|
* - *:smart* [true|false] flag indicating the parser uses hints if available (use with html)
|
975
|
-
* - *:skip* [:skip_return|:skip_white] flag indicating the parser skips
|
975
|
+
* - *:skip* [:skip_none|:skip_return|:skip_white] flag indicating the parser skips \\r or collpase white space into a single space. Default (skip space)
|
976
976
|
* - *:strip_namespace* [nil|String|true|false] "" or false result in no namespace stripping. A string of "*" or true will strip all namespaces. Any other non-empty string indicates that matching namespaces will be stripped.
|
977
977
|
*/
|
978
978
|
static VALUE
|
@@ -1045,7 +1045,7 @@ sax_parse(int argc, VALUE *argv, VALUE self) {
|
|
1045
1045
|
* - +options+ [Hash] options parse options
|
1046
1046
|
* - *:convert_special* [true|false] flag indicating special characters like < are converted
|
1047
1047
|
* - *:symbolize* [true|false] flag indicating the parser symbolize element and attribute names
|
1048
|
-
* - *:skip* [:skip_return|:skip_white] flag indicating the parser skips
|
1048
|
+
* - *:skip* [:skip_none|:skip_return|:skip_white] flag indicating the parser skips \\r or collapse white space into a single space. Default (skip space)
|
1049
1049
|
* - *:overlay* [Hash] a Hash of keys that match html element names and values that are one of
|
1050
1050
|
* - _:active_ - make the normal callback for the element
|
1051
1051
|
* - _:nest_ok_ - active but ignore nest check
|
@@ -1129,7 +1129,7 @@ parse_dump_options(VALUE ropts, Options copts) {
|
|
1129
1129
|
|
1130
1130
|
if (Qnil != (v = rb_hash_lookup(ropts, ox_indent_sym))) {
|
1131
1131
|
#ifdef RUBY_INTEGER_UNIFICATION
|
1132
|
-
if (rb_cInteger != rb_obj_class(v)) {
|
1132
|
+
if (rb_cInteger != rb_obj_class(v) && T_FIXNUM != rb_type(v)) {
|
1133
1133
|
#else
|
1134
1134
|
if (rb_cFixnum != rb_obj_class(v)) {
|
1135
1135
|
#endif
|
@@ -1139,7 +1139,7 @@ parse_dump_options(VALUE ropts, Options copts) {
|
|
1139
1139
|
}
|
1140
1140
|
if (Qnil != (v = rb_hash_lookup(ropts, trace_sym))) {
|
1141
1141
|
#ifdef RUBY_INTEGER_UNIFICATION
|
1142
|
-
if (rb_cInteger != rb_obj_class(v)) {
|
1142
|
+
if (rb_cInteger != rb_obj_class(v) && T_FIXNUM != rb_type(v)) {
|
1143
1143
|
#else
|
1144
1144
|
if (rb_cFixnum != rb_obj_class(v)) {
|
1145
1145
|
#endif
|
data/ext/ox/sax.c
CHANGED
@@ -1100,7 +1100,7 @@ read_element_end(SaxDrive dr) {
|
|
1100
1100
|
rb_ivar_set(dr->handler, ox_at_column_id, LONG2NUM(col));
|
1101
1101
|
}
|
1102
1102
|
for (nv = stack_pop(&dr->stack); match < nv; nv = stack_pop(&dr->stack)) {
|
1103
|
-
if (dr->has.end_element && 0 >= dr->blocked && (NULL == nv->hint || ActiveOverlay == nv->hint->overlay || NestOverlay ==
|
1103
|
+
if (dr->has.end_element && 0 >= dr->blocked && (NULL == nv->hint || ActiveOverlay == nv->hint->overlay || NestOverlay == nv->hint->overlay)) {
|
1104
1104
|
rb_funcall(dr->handler, ox_end_element_id, 1, nv->val);
|
1105
1105
|
}
|
1106
1106
|
if (NULL != nv->hint && BlockOverlay == nv->hint->overlay && 0 < dr->blocked) {
|
data/lib/ox/element.rb
CHANGED
@@ -91,6 +91,32 @@ module Ox
|
|
91
91
|
@nodes << txt
|
92
92
|
end
|
93
93
|
|
94
|
+
# Return true if all the key-value pairs in the cond Hash match the
|
95
|
+
# @attributes key-values.
|
96
|
+
def attr_match(cond)
|
97
|
+
cond.each_pair { |k,v| return false unless v == @attributes[k.to_sym] || v == @attributes[k.to_s] }
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
# Iterate over each child of the instance yielding according to the cond
|
102
|
+
# argument value. If the cond argument is nil then all child nodes are
|
103
|
+
# yielded to. If cond is a string then only the child Elements with a
|
104
|
+
# matching name will be yielded to. If the cond is a Hash then the
|
105
|
+
# keys-value pairs in the cond must match the child attribute values with
|
106
|
+
# the same keys. Any other cond type will yield to nothing.
|
107
|
+
def each(cond=nil)
|
108
|
+
if cond.nil?
|
109
|
+
nodes.each { |n| yield(n) }
|
110
|
+
else
|
111
|
+
cond = cond.to_s if cond.is_a?(Symbol)
|
112
|
+
if cond.is_a?(String)
|
113
|
+
nodes.each { |n| yield(n) if n.is_a?(Element) && cond == n.name }
|
114
|
+
elsif cond.is_a?(Hash)
|
115
|
+
nodes.each { |n| yield(n) if n.is_a?(Element) && n.attr_match(cond) }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
94
120
|
# Returns an array of Nodes or Strings that correspond to the locations
|
95
121
|
# specified by the path parameter. The path parameter describes the path
|
96
122
|
# to the return values which can be either nodes in the XML or
|
@@ -122,6 +148,7 @@ module Ox
|
|
122
148
|
# * <code>element.locate("Family/Pete/*")</code> returns all children of the Pete Element.
|
123
149
|
# * <code>element.locate("Family/?[1]")</code> returns the first element in the Family Element.
|
124
150
|
# * <code>element.locate("Family/?[<3]")</code> returns the first 3 elements in the Family Element.
|
151
|
+
# * <code>element.locate("Family/?[@age=32]")</code> returns the elements with an age attribute equal to 32 in the Family Element.
|
125
152
|
# * <code>element.locate("Family/?/@age")</code> returns the arg attribute for each child in the Family Element.
|
126
153
|
# * <code>element.locate("Family/*/@type")</code> returns the type attribute value for decendents of the Family.
|
127
154
|
# * <code>element.locate("Family/^Comment")</code> returns any comments that are a child of Family.
|
@@ -153,7 +180,7 @@ module Ox
|
|
153
180
|
ids = id.to_s
|
154
181
|
i = args[0].to_i # will be 0 if no arg or parsing fails
|
155
182
|
nodes.each do |n|
|
156
|
-
if (n.is_a?(Element) || n.is_a?(Instruct)) && (n.value == id || n.value == ids)
|
183
|
+
if (n.is_a?(Element) || n.is_a?(Instruct)) && (n.value == id || n.value == ids || name_matchs?(n.value, ids))
|
157
184
|
return n if 0 == i
|
158
185
|
has_some = true
|
159
186
|
i -= 1
|
@@ -176,7 +203,7 @@ module Ox
|
|
176
203
|
id_sym = id.to_sym
|
177
204
|
nodes.each do |n|
|
178
205
|
next if n.is_a?(String)
|
179
|
-
return true if n.value == id_str || n.value == id_sym
|
206
|
+
return true if n.value == id_str || n.value == id_sym || name_matchs?(n.value, id_str)
|
180
207
|
end
|
181
208
|
if instance_variable_defined?(:@attributes) && !@attributes.nil?
|
182
209
|
return true if @attributes.has_key?(id_str)
|
@@ -245,6 +272,9 @@ module Ox
|
|
245
272
|
match = 0 < index ? match[0..index - 1] : []
|
246
273
|
when '>'
|
247
274
|
match = index <= match.size ? match[index + 1..-1] : []
|
275
|
+
when '@'
|
276
|
+
k,v = step[3..-2].split('=')
|
277
|
+
match = match.select { |n| n.is_a?(Element) && (v == n.attributes[k.to_sym] || v == n.attributes[k]) }
|
248
278
|
else
|
249
279
|
raise InvalidPath.new(path)
|
250
280
|
end
|
@@ -260,5 +290,13 @@ module Ox
|
|
260
290
|
end
|
261
291
|
end
|
262
292
|
|
293
|
+
private
|
294
|
+
|
295
|
+
def name_matchs?(pat, id)
|
296
|
+
return false unless pat.length == id.length
|
297
|
+
pat.length.times { |i| return false unless '_' == id[i] || pat[i] == id[i] }
|
298
|
+
true
|
299
|
+
end
|
300
|
+
|
263
301
|
end # Element
|
264
302
|
end # Ox
|
data/lib/ox/sax.rb
CHANGED
@@ -11,7 +11,7 @@ module Ox
|
|
11
11
|
#
|
12
12
|
# class MySax < ::Ox::Sax
|
13
13
|
# def initialize()
|
14
|
-
# @
|
14
|
+
# @element_names = []
|
15
15
|
# end
|
16
16
|
#
|
17
17
|
# def start_element(name)
|
@@ -31,7 +31,7 @@ module Ox
|
|
31
31
|
# arguments will be Ox::Sax::Value objects. Since both the text() and the
|
32
32
|
# value() methods are called for the same element in the XML document the the
|
33
33
|
# text() method is ignored if the value() method is defined or public. The
|
34
|
-
# same is true for attr() and attr_value(). When all
|
34
|
+
# same is true for attr() and attr_value(). When all attributes have been read
|
35
35
|
# the attr_done() callback will be invoked.
|
36
36
|
#
|
37
37
|
# def instruct(target); end
|
data/lib/ox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "A fast XML parser and object serializer that uses only standard C lib.\n
|
14
14
|
\ \nOptimized XML (Ox), as the name implies was written to provide speed
|
@@ -20,7 +20,9 @@ extensions:
|
|
20
20
|
- ext/ox/extconf.rb
|
21
21
|
extra_rdoc_files:
|
22
22
|
- README.md
|
23
|
+
- CHANGELOG.md
|
23
24
|
files:
|
25
|
+
- CHANGELOG.md
|
24
26
|
- LICENSE
|
25
27
|
- README.md
|
26
28
|
- ext/ox/attr.h
|
@@ -33,6 +35,7 @@ files:
|
|
33
35
|
- ext/ox/cache8.c
|
34
36
|
- ext/ox/cache8.h
|
35
37
|
- ext/ox/dump.c
|
38
|
+
- ext/ox/encode.h
|
36
39
|
- ext/ox/err.c
|
37
40
|
- ext/ox/err.h
|
38
41
|
- ext/ox/extconf.rb
|