sporkmonger-sax-machine 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG
CHANGED
@@ -7,11 +7,14 @@ module SAXMachine
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def parse(xml_text)
|
10
|
-
|
10
|
+
@parser ||= (begin
|
11
11
|
sax_handler = SAXHandler.new(self)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
parser = Nokogiri::XML::SAX::PushParser.new(sax_handler)
|
13
|
+
if parser.respond_to?(:options)
|
14
|
+
parser.options |= Nokogiri::XML::ParseOptions::RECOVER
|
15
|
+
end
|
16
|
+
parser
|
17
|
+
end)
|
15
18
|
@parser << xml_text
|
16
19
|
self
|
17
20
|
end
|
@@ -24,7 +27,6 @@ module SAXMachine
|
|
24
27
|
end
|
25
28
|
|
26
29
|
module ClassMethods
|
27
|
-
|
28
30
|
def parse(xml_text)
|
29
31
|
# It might be cleaner to aditionally call parse_finish here, but
|
30
32
|
# then Nokogiri/libxml2 barfs on incomplete documents. Desired
|
@@ -44,11 +46,9 @@ module SAXMachine
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def columns
|
47
|
-
|
48
|
-
|
49
|
-
r += ecs
|
49
|
+
sax_config.top_level_elements.inject([]) do |accu, (name, ecs)|
|
50
|
+
accu += ecs; accu
|
50
51
|
end
|
51
|
-
r
|
52
52
|
end
|
53
53
|
|
54
54
|
def column(sym)
|
@@ -56,7 +56,7 @@ module SAXMachine
|
|
56
56
|
reset_current_collection
|
57
57
|
elsif parsing_collection?
|
58
58
|
@collection_handler.end_element(name)
|
59
|
-
elsif
|
59
|
+
elsif characters_captured? && !@element_config.has_value?
|
60
60
|
@object.send(@element_config.setter, @value)
|
61
61
|
end
|
62
62
|
|
@@ -64,12 +64,12 @@ module SAXMachine
|
|
64
64
|
@nsstack = @nsstack.pop
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
67
|
+
def characters_captured?
|
68
68
|
!@value.nil? && !@value.empty?
|
69
69
|
end
|
70
70
|
|
71
71
|
def parsing_collection?
|
72
|
-
|
72
|
+
!(@collection_handler ||= nil).nil?
|
73
73
|
end
|
74
74
|
|
75
75
|
def parse_element_attributes(element_configs)
|
@@ -103,7 +103,7 @@ module SAXMachine
|
|
103
103
|
##
|
104
104
|
# Decodes XML special characters.
|
105
105
|
def self.decode_xml(str)
|
106
|
-
return str.map
|
106
|
+
return str.map(&method(:decode_xml)) if str.kind_of?(Array)
|
107
107
|
|
108
108
|
# entities = {
|
109
109
|
# '#38' => '&',
|
data/lib/sax-machine/version.rb
CHANGED
@@ -229,6 +229,31 @@ describe "SAXMachine" do
|
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
+
it "should not save a value when the attribute is missing" do
|
233
|
+
document = @klass.parse("<link />")
|
234
|
+
document.link.should == nil
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should not save a value when the attribute is missing" do
|
238
|
+
document = @klass.parse("<link bar='foo' />")
|
239
|
+
document.link.should == nil
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should not save a value when the attribute is missing" do
|
243
|
+
document = @klass.parse("<link></link>")
|
244
|
+
document.link.should == nil
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should not save a value when the attribute is missing" do
|
248
|
+
document = @klass.parse("<link>\n</link>")
|
249
|
+
document.link.should == nil
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should not save a value when the attribute is missing" do
|
253
|
+
document = @klass.parse("<link>not foo</link>")
|
254
|
+
document.link.should == nil
|
255
|
+
end
|
256
|
+
|
232
257
|
it "should save the attribute value" do
|
233
258
|
document = @klass.parse("<link foo='test'>hello</link>")
|
234
259
|
document.link.should == 'test'
|
@@ -283,6 +308,27 @@ describe "SAXMachine" do
|
|
283
308
|
document.link_foo.should == 'test1'
|
284
309
|
document.link_bar.should == 'test2'
|
285
310
|
end
|
311
|
+
|
312
|
+
it "should parse the element and attribute values" do
|
313
|
+
document = @klass.parse("<link foo='test1'>hello</link>")
|
314
|
+
document.link.should == 'hello'
|
315
|
+
document.link_foo.should == 'test1'
|
316
|
+
document.link_bar.should == nil
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should parse the element and attribute values" do
|
320
|
+
document = @klass.parse("<link bar='test2'>hello</link>")
|
321
|
+
document.link.should == 'hello'
|
322
|
+
document.link_foo.should == nil
|
323
|
+
document.link_bar.should == 'test2'
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should parse the element and attribute values" do
|
327
|
+
document = @klass.parse("<link>hello</link>")
|
328
|
+
document.link.should == 'hello'
|
329
|
+
document.link_foo.should == nil
|
330
|
+
document.link_bar.should == nil
|
331
|
+
end
|
286
332
|
end
|
287
333
|
|
288
334
|
describe "when specifying namespaces" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sporkmonger-sax-machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Dix
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-11 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|