astro-sax-machine 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ module SAXMachine
3
3
 
4
4
  class CollectionConfig
5
5
  attr_reader :name
6
+ attr_reader :default_xmlns
6
7
 
7
8
  def initialize(name, options)
8
9
  @name = name.to_s
@@ -13,9 +14,14 @@ module SAXMachine
13
14
  when String then [options[:xmlns]]
14
15
  else nil
15
16
  end
17
+ @default_xmlns = options[:default_xmlns]
16
18
  end
17
19
 
18
20
  def handler(nsstack)
21
+ if nsstack.nil? || nsstack[''] == ''
22
+ nsstack = NSStack.new(nsstack, nsstack)
23
+ nsstack[''] = @default_xmlns
24
+ end
19
25
  SAXHandler.new(@class.new, nsstack)
20
26
  end
21
27
 
@@ -331,6 +331,30 @@ describe "SAXMachine" do
331
331
  document = @klass.parse("<root xmlns:a='urn:test'><a>foo</a><a>foo</a><a:a>bar</a:a></root>")
332
332
  document.a.should == 'bar'
333
333
  end
334
+
335
+ context "when passing a default namespace" do
336
+ before :each do
337
+ @xmlns = 'urn:test'
338
+ class Inner
339
+ include SAXMachine
340
+ element :a, :xmlns => @xmlns
341
+ end
342
+ @outer = Class.new do
343
+ include SAXMachine
344
+ elements :root, :default_xmlns => @xmlns, :class => Inner
345
+ end
346
+ end
347
+
348
+ it "should replace the empty namespace with a default" do
349
+ document = @outer.parse("<root><a>Hello</a></root>")
350
+ document.root[0].a.should == 'Hello'
351
+ end
352
+
353
+ it "should not replace another namespace" do
354
+ document = @outer.parse("<root xmlns='urn:test2'><a>Hello</a></root>")
355
+ document.root[0].a.should == 'Hello'
356
+ end
357
+ end
334
358
  end
335
359
 
336
360
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astro-sax-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix