julien51-sax-machine 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,7 @@ module SAXMachine
|
|
18
18
|
if @default_xmlns && @xmlns && !@xmlns.include?('')
|
19
19
|
@xmlns << ''
|
20
20
|
end
|
21
|
+
@record_events = options[:events]
|
21
22
|
end
|
22
23
|
|
23
24
|
def handler(nsstack)
|
@@ -25,7 +26,11 @@ module SAXMachine
|
|
25
26
|
nsstack = NSStack.new(nsstack, nsstack)
|
26
27
|
nsstack[''] = @default_xmlns
|
27
28
|
end
|
28
|
-
|
29
|
+
unless @record_events
|
30
|
+
SAXHandler.new(@class.new, nsstack)
|
31
|
+
else
|
32
|
+
SAXEventRecorder.new(nsstack)
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
def accessor
|
@@ -33,8 +33,9 @@ module SAXMachine
|
|
33
33
|
|
34
34
|
elsif @collection_config = sax_config.collection_config(@name, @nsstack)
|
35
35
|
@collection_handler = @collection_config.handler(@nsstack)
|
36
|
-
@
|
37
|
-
|
36
|
+
if @object.class != @collection_handler.object.class
|
37
|
+
@collection_handler.start_element(@name, @attrs)
|
38
|
+
end
|
38
39
|
elsif (element_configs = sax_config.element_configs_for_attribute(@name, @attrs)).any?
|
39
40
|
parse_element_attributes(element_configs)
|
40
41
|
set_element_config_for_element_value
|
data/lib/sax-machine.rb
CHANGED
@@ -344,7 +344,7 @@ describe "SAXMachine" do
|
|
344
344
|
end
|
345
345
|
|
346
346
|
context "when passing a default namespace" do
|
347
|
-
before :
|
347
|
+
before :all do
|
348
348
|
@xmlns = 'urn:test'
|
349
349
|
class Inner
|
350
350
|
include SAXMachine
|
@@ -373,7 +373,7 @@ describe "SAXMachine" do
|
|
373
373
|
|
374
374
|
describe "elements" do
|
375
375
|
describe "when parsing multiple elements" do
|
376
|
-
before :
|
376
|
+
before :all do
|
377
377
|
@klass = Class.new do
|
378
378
|
include SAXMachine
|
379
379
|
elements :entry, :as => :entries
|
@@ -447,6 +447,50 @@ describe "SAXMachine" do
|
|
447
447
|
document.entries.first.url.should == "http://pauldix.net"
|
448
448
|
end
|
449
449
|
end
|
450
|
+
|
451
|
+
describe "when desiring sax events" do
|
452
|
+
XHTML_XMLNS = "http://www.w3.org/1999/xhtml"
|
453
|
+
|
454
|
+
before :all do
|
455
|
+
@klass = Class.new do
|
456
|
+
include SAXMachine
|
457
|
+
elements :body, :events => true
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
it "should parse a simple child" do
|
462
|
+
document = @klass.parse("<body><p/></body>")
|
463
|
+
document.body[0].should == [[:start_element, "", "p", []],
|
464
|
+
[:end_element, "", "p"]]
|
465
|
+
end
|
466
|
+
it "should parse a simple child with text" do
|
467
|
+
document = @klass.parse("<body><p>Hello</p></body>")
|
468
|
+
document.body[0].should == [[:start_element, "", "p", []],
|
469
|
+
[:chars, "Hello"],
|
470
|
+
[:end_element, "", "p"]]
|
471
|
+
end
|
472
|
+
it "should parse nested children" do
|
473
|
+
document = @klass.parse("<body><p><span/></p></body>")
|
474
|
+
document.body[0].should == [[:start_element, "", "p", []],
|
475
|
+
[:start_element, "", "span", []],
|
476
|
+
[:end_element, "", "span"],
|
477
|
+
[:end_element, "", "p"]]
|
478
|
+
end
|
479
|
+
it "should parse multiple children" do
|
480
|
+
document = @klass.parse("<body><p>Hello</p><p>World</p></body>")
|
481
|
+
document.body[0].should == [[:start_element, "", "p", []],
|
482
|
+
[:chars, "Hello"],
|
483
|
+
[:end_element, "", "p"],
|
484
|
+
[:start_element, "", "p", []],
|
485
|
+
[:chars, "World"],
|
486
|
+
[:end_element, "", "p"]]
|
487
|
+
end
|
488
|
+
it "should pass namespaces" do
|
489
|
+
document = @klass.parse("<body xmlns='#{XHTML_XMLNS}'><p/></body>")
|
490
|
+
document.body[0].should == [[:start_element, XHTML_XMLNS, "p", []],
|
491
|
+
[:end_element, XHTML_XMLNS, "p"]]
|
492
|
+
end
|
493
|
+
end
|
450
494
|
end
|
451
495
|
|
452
496
|
describe "full example" do
|