[Instantrails-users] REXML question

Bill Walton bill.walton at charter.net
Sat Apr 29 10:20:00 EDT 2006


Hi Curt, Gavin;

Thanks for your replies.  I've tried both suggestions and, unfortunately, it still gives me errors.  I'd really appreciate it if you'd take a look at the irb input / output below and tell me if you can tell what I'm doing wrong.  Thanks!

--------------- irb session ---------------

C:\InstantRails-1.3\rails_apps\sandbox>irb
irb(main):001:0> require "rexml/document"
=> true
irb(main):002:0> file=File.new("public/mydoc.xml")
=> #<File:public/mydoc.xml>
irb(main):003:0> doc=REXML::Document.new file
=> <UNDEFINED> ... </>

[BW]  I assume the <UNDEFINED> error message above is referring to Document.  One thing I don't understand though is why the 'require' on the first line of input is successful since rexml/document.rb is over in another branch of the directory tree.  For now, I'm just assuming irb knows where to find what it needs.  It returns true, so I figure it found it.  But if irb found document.rb, then why is the 'doc=' line failing?

[BW]  So I figured I'd give Gavin's approach a shot.

irb(main):004:0> include REXML
=> Object
irb(main):005:0> doc = Document.new file
NoMethodError: undefined method `[]' for nil:NilClass
        from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/source.rb:131:in `initialize'
        from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:126:in `stream='
        from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:100:in `initialize'
        from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in `initialize'
        from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/document.rb:178:in `build'
        from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/document.rb:45:in `initialize'
        from (irb):5

[BW]  Hmmm....  That didn't see to make things better ;-(    So I tried it without passing in the file argument.

irb(main):006:0> doc=Document.new
=> <UNDEFINED/>

[BW]  So it definitely looks to me like it's the Document.new that's throwing the error.  Any ideas?  I sure would appreciate it if you'd try entering these commands on your systems and letting me know if you get any different results.  Maybe there's something wrong with my config.  I've included the content of "mydoc.xml" below.  I put it in the 'public' directory.

Thanks,
Bill

------------------  mydoc.xml  ---------------------

<inventory title="OmniCorp Store #45x10^3">
  <section name="health">
    <item upc="123456789" stock="12">
      <name>Invisibility Cream</name>
      <price>14.50</price>
      <description>Makes you invisible</description>
    </item>
    <item upc="445322344" stock="18">
      <name>Levitation Salve</name>
      <price>23.99</price>
      <description>Levitate yourself for up to 3 hours per application</description>
    </item>
  </section>
  <section name="food">
    <item upc="485672034" stock="653">
      <name>Blork and Freen Instameal</name>
      <price>4.95</price>
      <description>A tasty meal in a tablet; just add water</description>
    </item>
    <item upc="132957764" stock="44">
      <name>Grob winglets</name>
      <price>3.56</price>
      <description>Tender winglets of Grob. Just add water</description>
    </item>
  </section>
</inventory>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/instantrails-users/attachments/20060429/98863db0/attachment.htm 


More information about the Instantrails-users mailing list