astro-sax-machine 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,9 @@ module SAXMachine
15
15
  else nil
16
16
  end
17
17
  @default_xmlns = options[:default_xmlns]
18
+ if @default_xmlns && !@xmlns.include?('')
19
+ @xmlns << ''
20
+ end
18
21
  end
19
22
 
20
23
  def handler(nsstack)
@@ -332,6 +332,17 @@ describe "SAXMachine" do
332
332
  document.a.should == 'bar'
333
333
  end
334
334
 
335
+ it "should parse multiple namespaces" do
336
+ klass = Class.new do
337
+ include SAXMachine
338
+ element :a, :xmlns => 'urn:test'
339
+ element :b, :xmlns => 'urn:test2'
340
+ end
341
+ document = klass.parse("<root xmlns='urn:test' xmlns:b='urn:test2'><b:b>bar</b:b><a>foo</a></root>")
342
+ document.a.should == 'foo'
343
+ document.b.should == 'bar'
344
+ end
345
+
335
346
  context "when passing a default namespace" do
336
347
  before :each do
337
348
  @xmlns = 'urn:test'
@@ -478,4 +489,91 @@ describe "SAXMachine" do
478
489
  f.entries[0].orig_link.should == 'http://www.pauldix.net/2008/09/marshal-data-to.html'
479
490
  end
480
491
  end
492
+
493
+ describe "another full example" do
494
+
495
+ RSS_XMLNS = 'http://purl.org/rss/1.0/'
496
+ ATOM_XMLNS = 'http://www.w3.org/2005/Atom'
497
+ class Entry
498
+ include SAXMachine
499
+ element :title, :xmlns => RSS_XMLNS
500
+ element :title, :xmlns => ATOM_XMLNS
501
+ element :link, :xmlns => RSS_XMLNS
502
+ element :link, :xmlns => ATOM_XMLNS, :value => 'href'
503
+ end
504
+ class Channel
505
+ include SAXMachine
506
+ element :title, :xmlns => RSS_XMLNS
507
+ element :title, :xmlns => ATOM_XMLNS
508
+ element :link, :xmlns => RSS_XMLNS
509
+ element :link, :xmlns => ATOM_XMLNS, :value => 'href'
510
+ elements :entry, :as => :entries, :class => Entry
511
+ elements :item, :as => :entries, :class => Entry
512
+ end
513
+ class Root
514
+ include SAXMachine
515
+ elements :rss, :as => :channels, :default_xmlns => RSS_XMLNS, :class => Channel
516
+ elements :feed, :as => :channels, :default_xmlns => ATOM_XMLNS, :class => Channel
517
+ end
518
+
519
+ context "when parsing a complex example" do
520
+ before :all do
521
+ @document = Root.parse(<<-eoxml).channels[0]
522
+ <?xml version="1.0" encoding="UTF-8"?>
523
+ <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
524
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
525
+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
526
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
527
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
528
+ xmlns:cc="http://web.resource.org/cc/">
529
+ <channel>
530
+ <title>Delicious/tag/pubsubhubbub</title>
531
+ <atom:link rel="self" type="application/rss+xml" href="http://feeds.delicious.com/v2/rss/tag/pubsubhubbub?count=15"/>
532
+ <link>http://delicious.com/tag/pubsubhubbub</link>
533
+ <description>recent bookmarks tagged pubsubhubbub</description>
534
+ </channel>
535
+ </rss>
536
+ eoxml
537
+ end
538
+ it "should parse the title" do
539
+ @document.title.should == 'Delicious/tag/pubsubhubbub'
540
+ end
541
+ it "should parse the link" do
542
+ @document.link.should == 'http://feeds.delicious.com/v2/rss/tag/pubsubhubbub?count=15'
543
+ end
544
+ end
545
+ context "when parsing a Twitter example" do
546
+ before :all do
547
+ @document = Root.parse(<<-eoxml).channels[0]
548
+ <?xml version="1.0" encoding="UTF-8"?>
549
+ <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
550
+ <channel>
551
+ <atom:link type="application/rss+xml" rel="self" href="http://twitter.com/statuses/user_timeline/5381582.rss"/>
552
+ <title>Twitter / julien51</title>
553
+ <link>http://twitter.com/julien51</link>
554
+ <description>Twitter updates from julien / julien51.</description>
555
+ <language>en-us</language>
556
+ <ttl>40</ttl>
557
+ <item>
558
+ <title>julien51: @github : I get an error when trying to build one of my gems (julien51-sax-machine), it seems related to another gem's gemspec.</title>
559
+ <description>julien51: @github : I get an error when trying to build one of my gems (julien51-sax-machine), it seems related to another gem's gemspec.</description>
560
+ <pubDate>Thu, 30 Jul 2009 01:00:30 +0000</pubDate>
561
+ <guid>http://twitter.com/julien51/statuses/2920716033</guid>
562
+ <link>http://twitter.com/julien51/statuses/2920716033</link>
563
+ </item>
564
+ </channel>
565
+ </rss>
566
+ eoxml
567
+ end
568
+ it "should parse the title" do
569
+ @document.title.should == 'Twitter / julien51'
570
+ end
571
+ it "should parse the link" do
572
+ @document.link.should == 'http://twitter.com/statuses/user_timeline/5381582.rss'
573
+ end
574
+ it "should find an entry" do
575
+ @document.entries.length.should == 1
576
+ end
577
+ end
578
+ end
481
579
  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.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix